Esempio n. 1
0
        private void ImportArea()
        {
            //if (ExcelLibrary.ExcelLibrary_Func.ReadExcelToListByNPOI(ref lstMain))
            //    dgvList.DataSource = lstMain;

            try
            {
                //int iSize = 5000;
                string tableName = "T_P_IMPORTAREA";
                Cursor = Cursors.WaitCursor;
                Application.DoEvents();
                //lblMassage.Text = "文件读取中...";
                //lblMassage.Refresh();

                Dictionary <string, string> dicDefault = new Dictionary <string, string>();
                dicDefault.Add("WAREHOUSESTATUS", "1");
                dicDefault.Add("HOUSESTATUS", "1");
                dicDefault.Add("AREASTATUS", "1");
                dicDefault.Add("IMPORTSTATUS", "0");
                dicDefault.Add("IMPORTDATE", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                dicDefault.Add("IMPORTUSER", Common_Var.CurrentUser.UserNo);
                dicDefault.Add("AREATYPENAME", "正式货位");
                Dictionary <string, string> dicFields = new Dictionary <string, string>();
                dicFields.Add("仓库编号", "WAREHOUSENO");
                dicFields.Add("仓库名称", "WAREHOUSENAME");
                dicFields.Add("库区编号", "HOUSENO");
                dicFields.Add("库区名称", "HOUSENAME");
                dicFields.Add("货位编号", "AREANO");
                dicFields.Add("货位名称", "AREANAME");
                dicFields.Add("货位类型", "AREATYPENAME");
                string strError = string.Empty;
                //List<T_SupplierStockInfo> lstImport = new List<T_SupplierStockInfo>();
                //lblMassage.Text = "数据载入中...";
                //lblMassage.Refresh();

                List <string> lstSql = new List <string>();
                if (ExcelLibrary_Func.ReadExcelToSqlListByNPOI(ref lstSql, tableName, dicFields, dicDefault))
                {
                    this.Refresh();
                    Application.DoEvents();

                    if (lstSql == null || lstSql.Count <= 0)
                    {
                        MessageBox.Show("导入出错,读取的文件内容为空!", "错误");
                        return;
                    }

                    string strFields = lstSql[0].Substring(0, lstSql[0].IndexOf(')') + 1);
                    if (Common_Func.IsIncludeChinese(strFields))
                    {
                        MessageBox.Show("导入出错,读取的文件格式不匹配,找不到对应的列!", "错误");
                        return;
                    }
                    string sql = lstSql.Find(delegate(string temp) { return(temp.IndexOf(",,") >= 0); });
                    if (!string.IsNullOrEmpty(sql))
                    {
                        MessageBox.Show("导入出错,读取的文件格式不匹配,不允许导入空值!", "错误");
                        return;
                    }

                    //lblMassage.Text = "数据上传中...";
                    //lblMassage.Refresh();
                    this.Refresh();
                    Application.DoEvents();
                    if (!Common_Func.CheckImportTable(ImportType.Area, ref strError))
                    {
                        MessageBox.Show("导入出错," + strError, "错误");
                        return;
                    }
                    lstSql.Insert(0, string.Format("DELETE {0} \n", tableName));

                    if (lstSql.Count / Common_Var.OnceImportSize >= 2)
                    {
                        MessageBox.Show("导入数据过于庞大,请拆分后导入", "提示");

                        //ExcelLibrary_Func.WriteSqlListToText(lstSql);
                        return;
                    }

                    if (!Common_Func.UpLoadSql(lstSql, ref strError))
                    {
                        MessageBox.Show("导入出错," + strError, "错误");
                        return;
                    }

                    //lblMassage.Text = "数据处理中...";
                    //lblMassage.Refresh();
                    this.Refresh();
                    Application.DoEvents();
                    bool bResult = false;
                    //bResult = Common_Func.DealImport(ImportType.Area, ref strError);
                    //lblMassage.Text = "导入完成";
                    //lblMassage.Refresh();

                    if (!bResult)
                    {
                        MessageBox.Show("导入出错," + strError, "提示");
                        return;
                    }
                    else
                    {
                        MessageBox.Show("导入成功", "提示");
                        return;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("导入失败," + ex.Message, "提示");
            }
            finally
            {
                Cursor = Cursors.Default;
                //lblMassage.Text = "";
                //lblMassage.Refresh();
            }
        }