Пример #1
0
        public void CheckImportData()
        {
            #region 首先检查要导入的Excel数据中ERP代码是否在ERP系统中存在
            string       txtfilename = System.Windows.Forms.Application.StartupPath + "\\错误信息.txt";
            StreamWriter sw          = new StreamWriter(txtfilename, false, Encoding.GetEncoding("gb2312"));
            int          flag        = 0;
            try
            {
                for (int i = 0; i < dgv2.Rows.Count - 1; i++)
                {
                    string partno = dgv2.Rows[i].Cells[4].Value.ToString();
                    if (!string.IsNullOrEmpty(partno))
                    {
                        InventoryPart invpartnew = InventoryPart.FindInvInfor(partno, mSite);
                        if (invpartnew == null)
                        {
                            System.Diagnostics.Trace.WriteLine("第" + (i + 1) + "行材料编码 " + partno + " 在ERP中所选择域无此材料编码,请联系ERP操作员,在ERP中添加。");
                            sw.WriteLine("第" + (i + 1) + "行材料编码 " + partno + " 在ERP中所选择域无此材料编码,请联系ERP操作员,在ERP中添加。", "温馨提示");
                            flag = 1;
                        }
                    }
                    else
                    {
                        System.Diagnostics.Trace.WriteLine("第" + (i + 1) + "行材料编码 " + partno + " 在没有填写,在ERP中添加活查询后填写。");
                        sw.WriteLine("第" + (i + 1) + "行材料编码 " + partno + " 在没有填写,在ERP中添加活查询后填写。", "温馨提示");
                        flag = 1;
                    }
                    if (!string.IsNullOrEmpty(dgv2.Rows[i].Cells[6].Value.ToString()))
                    {
                        string rqty = dgv2.Rows[i].Cells[6].Value.ToString();
                        if (BaseClass.validateNum(rqty) == false)
                        {
                            System.Diagnostics.Trace.WriteLine("请确认第" + (i + 1) + "行" + partno + " 预估数量输入数字!!!");
                            sw.WriteLine("请确认第" + (i + 1) + "行" + partno + " 预估数量输入数字!!!", "温馨提示");
                            flag = 1;
                        }
                    }
                    if (!string.IsNullOrEmpty(dgv2.Rows[i].Cells[7].Value.ToString()))
                    {
                        string rqty = dgv2.Rows[i].Cells[7].Value.ToString();
                        if (BaseClass.validateNum(rqty) == false)
                        {
                            System.Diagnostics.Trace.WriteLine("请确认第" + (i + 1) + "行 " + partno + " 第一批生产需求数量输入数字!!!");
                            sw.WriteLine("请确认第" + (i + 1) + "行 " + partno + " 第一批生产需求数量输入数字!!!", "温馨提示");
                            flag = 1;
                        }
                    }
                    else
                    {
                        System.Diagnostics.Trace.WriteLine("请确认第" + (i + 1) + "行 " + partno + " 第一批生产需求数量没有输入数字!!!");
                        sw.WriteLine("请确认第" + (i + 1) + "行 " + partno + " 第一批生产需求数量没有输入数字!!!", "温馨提示");
                        flag = 1;
                    }
                    if (!string.IsNullOrEmpty(dgv2.Rows[i].Cells[9].Value.ToString()))
                    {
                        string rqty = dgv2.Rows[i].Cells[9].Value.ToString();
                        if (BaseClass.validateNum(rqty) == false)
                        {
                            System.Diagnostics.Trace.WriteLine("请确认第" + (i + 1) + "行 " + partno + " 第一批生产需求数量输入数字!!!");
                            sw.WriteLine("请确认第" + (i + 1) + "行 " + partno + " 第一批生产需求数量输入数字!!!", "温馨提示");
                            flag = 1;
                        }
                    }
                    else
                    {
                        System.Diagnostics.Trace.WriteLine("请确认第" + (i + 1) + "行 " + partno + " 第二批生产需求数量没有输入数字!!!");
                        sw.WriteLine("请确认第" + (i + 1) + "行 " + partno + " 第二批生产需求数量没有输入数字!!!", "温馨提示");
                        flag = 1;
                    }
                }
                if (flag == 1)
                {
                    sw.Close();
                    MessageBox.Show("要导入的预估文件数据有误,请检查!");
                    System.Diagnostics.Process.Start("explorer.exe", txtfilename);
                    return;
                }
                #endregion
                DialogResult dgresult = MessageBox.Show("确定要将预估结果进行导入吗?", "操作确认", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                if (dgresult == DialogResult.No)
                {
                    return;
                }
                #region 首先将上次的预估结果保存为历史记录(按照预估人,专业,区域进行覆盖)

                PartParameter.DeleteEstimate(mSite, ProjectId, DisciplineId);
                #endregion
                ImportDataHanlder ImportData = new ImportDataHanlder(ImportParaData);
                ImportData.BeginInvoke(null, null);
            }
            catch (Exception et) { MessageBox.Show(et.Message); }
            finally { MessageBox.Show("预估数据导入成功!!!", "操作提示"); }
        }