uploadfy导入Excel内容到数据库中3

private int ImportSheetData(string userno, string sheet, string bigT, DataTable dt, List<BigTColModel> lstColModel, ref string msg)
        {
            BigTColModel COL;
            /**********   查找列表头对应的列序号   *******/
            DataRow drTitle2 = dt.Rows[0];//二级表头
            string colName, colName2;
            bool bColOver = false;
            for (int i = 1; i < dt.Columns.Count; i++)//第0列为序号
            {
                if (bColOver)
                {
                    break;//最后一列
                }
                colName = CommonMethod.toString(dt.Columns[i]);
                colName2 = CommonMethod.toString( drTitle2[i] );
                if (colName == string.Empty && colName2 == string.Empty)
                {
                    continue;
                }
                for (int k = 0; k < lstColModel.Count; k++)
                {
                    COL = lstColModel[k];
                    if (colName != COL.sheet_name && colName2 != COL.sheet_name)
                    {
                        continue;
                    }

                    lstColModel[k].col_pos = i;//记录对应的列索引
                    if (k == lstColModel.Count - 1)
                    {
                        bColOver = true;//最后一列,因为lstColModel是按列大小排序的
                    }
                }
            }

            /**********   导入数据   *******/
            DataRow dr;
            int indexNum=0;
            for (int i = 1; i < dt.Rows.Count; i++)//从第一列开始
            {
                dr = dt.Rows[i];
                if (CommonMethod.toInt(dr[0], ref indexNum) <= 0)
                {
                    break;//序号为空,空行,跳出
                }

                //采集一行的数据
                for (int k = 0; k < lstColModel.Count; k++)
                {
                    COL = lstColModel[k];
                    if (string.IsNullOrEmpty(COL.col_index) || COL.col_pos <= 0) //没有对应数据库表对应列,没有对应Excel对应列
                    {
                        continue;//
                    }
                    lstColModel[k].col_data = CommonMethod.toString(dr[COL.col_pos]); //赋值
                }

                if (btModuel.InsertRowData(userno, sheet, bigT, lstColModel) < 0)
                {
                    msg = btModuel.m_sMsg;
                    return -1;
                }
            }
            return 1;
        }

你可能感兴趣的:(upload)