Пример #1
0
        private void btnResolve_InProduct_Click(object sender, EventArgs e)
        {
            try
            {
                string yearMonth = "";

                择年月 frm = new  择年月();

                if (frm.ShowDialog() == DialogResult.OK)
                {
                    yearMonth = frm._Str_YearMonth;
                }
                else
                {
                    return;
                }

                //DataTable tempTable = _Service_InProcutReport.GetAllInProductInfo(零件供应商耗用报表.Name, yearMonth);

                //if (tempTable != null && tempTable.Rows.Count > 0)
                //{
                //    if (MessageDialog.ShowEnquiryMessage("年月:【"+ yearMonth +"】,已存在记录,重复导入"))
                //    {

                //    }
                //}

                DataTable dtTemp = ExcelHelperP.RenderFromExcel(openFileDialog1);

                if (dtTemp == null)
                {
                    return;
                }

                if (!dtTemp.Columns.Contains("图号型号"))
                {
                    throw new Exception("文件无【图号型号】列名");
                }

                if (!dtTemp.Columns.Contains("物品名称"))
                {
                    throw new Exception("文件无【物品名称】列名");
                }

                if (!dtTemp.Columns.Contains("规格"))
                {
                    throw new Exception("文件无【规格】列名");
                }

                if (!dtTemp.Columns.Contains("耗用数"))
                {
                    throw new Exception("文件无【耗用数】列名");
                }

                if (!dtTemp.Columns.Contains("供应商"))
                {
                    throw new Exception("文件无【供应商】列名");
                }

                List <Bus_WorkShop_InProduct_Resolve> lstInfo = new List <Bus_WorkShop_InProduct_Resolve>();

                for (int i = 0; i < dtTemp.Rows.Count; i++)
                {
                    int goodsID = UniversalFunction.GetGoodsID(dtTemp.Rows[i]["图号型号"].ToString(),
                                                               dtTemp.Rows[i]["物品名称"].ToString(), dtTemp.Rows[i]["规格"].ToString());

                    if (goodsID == 0)
                    {
                        throw new Exception(string.Format("第【{0}】行,图号型号:{1},物品名称:{2},规格:{3},无法找到匹配的物品ID", i.ToString(),
                                                          dtTemp.Rows[i]["图号型号"].ToString(), dtTemp.Rows[i]["物品名称"].ToString(), dtTemp.Rows[i]["规格"].ToString()));
                    }

                    Bus_WorkShop_InProduct_Resolve tempInfo = new Bus_WorkShop_InProduct_Resolve();
                    tempInfo.F_Id      = Guid.NewGuid().ToString();
                    tempInfo.GoodsID   = goodsID;
                    tempInfo.Provider  = dtTemp.Rows[i]["供应商"].ToString();
                    tempInfo.YearMonth = yearMonth;

                    decimal goodsCount = 0;
                    Decimal.TryParse(dtTemp.Rows[i]["耗用数"] == null ? "" : dtTemp.Rows[i]["耗用数"].ToString(), out goodsCount);
                    tempInfo.GoodsCount = goodsCount;

                    lstInfo.Add(tempInfo);
                }

                _Service_InProcutReport.InputResolveInfo(lstInfo);
                MessageDialog.ShowPromptMessage("导入成功");
            }
            catch (Exception ex)
            {
                MessageDialog.ShowPromptMessage(ex.Message);
                return;
            }
        }
Пример #2
0
        private void btnSupplementary_InProduct_Click(object sender, EventArgs e)
        {
            try
            {
                string yearMonth = "";

                择年月 frm = new  择年月();

                if (frm.ShowDialog() == DialogResult.OK)
                {
                    yearMonth = frm._Str_YearMonth;
                }
                else
                {
                    return;
                }

                DataTable dtTemp = ExcelHelperP.RenderFromExcel(openFileDialog1);

                if (dtTemp == null)
                {
                    return;
                }

                if (!dtTemp.Columns.Contains("图号型号"))
                {
                    throw new Exception("文件无【图号型号】列名");
                }

                if (!dtTemp.Columns.Contains("物品名称"))
                {
                    throw new Exception("文件无【物品名称】列名");
                }

                if (!dtTemp.Columns.Contains("规格"))
                {
                    throw new Exception("文件无【规格】列名");
                }

                if (!dtTemp.Columns.Contains("实盘数"))
                {
                    throw new Exception("文件无【实盘数】列名");
                }

                List <Bus_WorkShop_InProduct> lstInfo = new List <Bus_WorkShop_InProduct>();

                for (int i = 0; i < dtTemp.Rows.Count; i++)
                {
                    int goodsID = UniversalFunction.GetGoodsID(dtTemp.Rows[i]["图号型号"].ToString(),
                                                               dtTemp.Rows[i]["物品名称"].ToString(), dtTemp.Rows[i]["规格"].ToString());

                    if (goodsID == 0)
                    {
                        throw new Exception(string.Format("第【{0}】行,图号型号:{1},物品名称:{2},规格:{3},无法找到匹配的物品ID", i.ToString(),
                                                          dtTemp.Rows[i]["图号型号"].ToString(), dtTemp.Rows[i]["物品名称"].ToString(), dtTemp.Rows[i]["规格"].ToString()));
                    }

                    Bus_WorkShop_InProduct tempInfo = new Bus_WorkShop_InProduct();
                    tempInfo.F_Id      = Guid.NewGuid().ToString();
                    tempInfo.GoodsID   = goodsID;
                    tempInfo.YearMonth = yearMonth;

                    decimal goodsCount = 0;
                    Decimal.TryParse(dtTemp.Rows[i]["实盘数"] == null ? "" : dtTemp.Rows[i]["实盘数"].ToString(), out goodsCount);
                    tempInfo.NowBalanceCount = goodsCount;

                    lstInfo.Add(tempInfo);
                }

                _Service_InProcutReport.InputNowBalanceCount(lstInfo);
                MessageDialog.ShowPromptMessage("导入成功");
            }
            catch (Exception ex)
            {
                MessageDialog.ShowPromptMessage(ex.Message);
                return;
            }
        }