示例#1
0
        private void Button_Click_Me(object sender, RoutedEventArgs e)
        {
            for (int i = 1; i <= 8; i++)
            {
                resultlist.Add(new ResultGrid()
                {
                    id = i
                });
            }

            foreach (var value in resultlist)
            {
                value.clear();
            }

            grid2.ItemsSource = null;

            var dateresult = cSVFile.OpenCSVFile();

            if (dateresult == null)
            {
                MessageBox.Show("未能成功打开CSV文件");
                return;
            }
            if (dateresult.Columns.Count != 21)
            {
                MessageBox.Show("CSV文件列数不正确,无法导入");
                return;
            }
            for (int i = 0; i < dateresult.Rows.Count; i++)
            {
                int[] length = new int[15];
                length[i] = 0;

                string GWNo    = dateresult.Rows[i][0].ToString().Replace(" ", "");
                string MT      = dateresult.Rows[i][1].ToString().Replace(" ", "");
                string OD      = dateresult.Rows[i][2].ToString().Replace(" ", "");
                string WT      = dateresult.Rows[i][3].ToString().Replace(" ", "");
                string YLLth   = dateresult.Rows[i][4].ToString().Replace(" ", "");
                string length1 = dateresult.Rows[i][5].ToString().Replace(" ", "");
                //string length2 = dateresult.Rows[i][6].ToString().Replace(" ", "");
                //string length3 = dateresult.Rows[i][7].ToString().Replace(" ", "");
                //string length4 = dateresult.Rows[i][8].ToString().Replace(" ", "");
                //string length5 = dateresult.Rows[i][9].ToString().Replace(" ", "");
                //string length6 = dateresult.Rows[i][10].ToString().Replace(" ", "");
                //string length7 = dateresult.Rows[i][11].ToString().Replace(" ", "");
                //string length8 = dateresult.Rows[i][12].ToString().Replace(" ", "");
                //string length9 = dateresult.Rows[i][13].ToString().Replace(" ", "");
                //string length10 = dateresult.Rows[i][14].ToString().Replace(" ", "");
                //string length11 = dateresult.Rows[i][15].ToString().Replace(" ", "");
                //string length12 = dateresult.Rows[i][16].ToString().Replace(" ", "");
                //string length13 = dateresult.Rows[i][17].ToString().Replace(" ", "");
                //string length14 = dateresult.Rows[i][18].ToString().Replace(" ", "");
                //string length15 = dateresult.Rows[i][19].ToString().Replace(" ", "");
                string IsBusy = dateresult.Rows[i][20].ToString().Replace(" ", "");

                if (string.IsNullOrWhiteSpace(GWNo))
                {
                    continue;
                }
                if (string.IsNullOrWhiteSpace(MT))
                {
                    continue;
                }
                if (string.IsNullOrWhiteSpace(OD))
                {
                    continue;
                }
                if (string.IsNullOrWhiteSpace(WT))
                {
                    continue;
                }
                if (string.IsNullOrWhiteSpace(YLLth))
                {
                    continue;
                }
                for (int j = 0; j < 15; j++)
                {
                    if (!int.TryParse(length1, out length[j]))
                    {
                        continue;
                    }
                }

                resultlist[i].GWNo     = GWNo;
                resultlist[i].MT       = MT;
                resultlist[i].OD       = OD;
                resultlist[i].WT       = WT;
                resultlist[i].YLLth    = YLLth;
                resultlist[i].length1  = length[0];
                resultlist[i].length2  = length[1];
                resultlist[i].length3  = length[2];
                resultlist[i].length4  = length[3];
                resultlist[i].length5  = length[4];
                resultlist[i].length6  = length[5];
                resultlist[i].length7  = length[6];
                resultlist[i].length8  = length[7];
                resultlist[i].length9  = length[8];
                resultlist[i].length10 = length[9];
                resultlist[i].length11 = length[10];
                resultlist[i].length12 = length[11];
                resultlist[i].length13 = length[12];
                resultlist[i].length14 = length[13];
                resultlist[i].length15 = length[14];
                resultlist[i].Busy     = IsBusy;
            }
            grid2.ItemsSource = resultlist;
            int realcount = resultlist.Count(a => !string.IsNullOrWhiteSpace(a.GWNo));

            if (realcount != dateresult.Rows.Count)
            {
                MessageBox.Show("未能全部导入文件内容,部分数据为空或格式不正确,实际导入" + realcount + "条数据");
            }
        }
示例#2
0
        /// <summary>
        /// 导入Excel原材料
        /// </summary>
        private BllResult importExcelMaterial()
        {
            try
            {
                foreach (var value in inputlist)
                {
                    value.clear();
                }

                inputgrid1.ItemsSource = null;

                var dateresult = cSVFile.OpenCSVFile();
                if (dateresult == null)
                {
                    return(BllResultFactory.Error("未能成功打开CSV文件"));
                }
                if (dateresult.Columns.Count != 7)
                {
                    return(BllResultFactory.Error("CSV文件列数不正确,无法导入"));
                }
                for (int i = 0; i < dateresult.Rows.Count; i++)
                {
                    int fl = 0;

                    string WaiJing   = dateresult.Rows[i][0].ToString().Replace(" ", "");
                    string BiHou     = dateresult.Rows[i][1].ToString().Replace(" ", "");
                    string CaiZhi    = dateresult.Rows[i][2].ToString().Replace(" ", "");
                    string Dengji    = dateresult.Rows[i][3].ToString().Replace(" ", "");
                    string length    = dateresult.Rows[i][4].ToString().Replace(" ", "");
                    string LuPiHao   = dateresult.Rows[i][5].ToString().Replace(" ", "");
                    string WuLiaoHao = dateresult.Rows[i][6].ToString().Replace(" ", "");

                    if (string.IsNullOrWhiteSpace(WaiJing))
                    {
                        continue;
                    }
                    if (string.IsNullOrWhiteSpace(BiHou))
                    {
                        continue;
                    }
                    if (string.IsNullOrWhiteSpace(CaiZhi))
                    {
                        continue;
                    }
                    if (string.IsNullOrWhiteSpace(Dengji))
                    {
                        continue;
                    }
                    if (string.IsNullOrWhiteSpace(LuPiHao))
                    {
                        continue;
                    }
                    if (string.IsNullOrWhiteSpace(WuLiaoHao))
                    {
                        continue;
                    }
                    if (!int.TryParse(length, out fl))
                    {
                        continue;
                    }

                    inputlist[i].WaiJing   = WaiJing;
                    inputlist[i].BiHou     = BiHou;
                    inputlist[i].CaiZhi    = CaiZhi;
                    inputlist[i].Dengji    = Dengji;
                    inputlist[i].length    = fl;
                    inputlist[i].LuPiHao   = LuPiHao;
                    inputlist[i].WuLiaoHao = WuLiaoHao;
                }

                int realcount = inputlist.Count(a => !string.IsNullOrWhiteSpace(a.WaiJing));
                if (realcount != dateresult.Rows.Count)
                {
                    return(BllResultFactory.Error("未能全部导入文件内容,部分数据为空或格式不正确,实际导入" + realcount + "条数据"));
                }
                else
                {
                    return(BllResultFactory.Sucess("导入Excel原材料成功!"));
                }
            }
            catch (Exception ex)
            {
                return(BllResultFactory.Error($"导入Excel原材料发生异常:{ex.Message}"));
            }
        }