private void bt_inputwobominfo_Click(object sender, EventArgs e) { try { this.rtb_msglog.Clear(); OpenFileDialog ofd = new OpenFileDialog(); ofd.Title = "选择工单料表"; ofd.Filter = "(*.xls Excel 2003)|*.xls|(*.*)|*.*"; // ofd.InitialDirectory = "c:\\"; DialogResult dlr = ofd.ShowDialog(); if (dlr == DialogResult.Yes || dlr == DialogResult.OK) { //获取excel中有几个表 List <string> lsname = ClsReadExcel.GetTableNames(ofd.FileName);// BLL.ClsReadExcel.GetTableNames(ofd.FileName); if (lsname.Count > 1) { throw new Exception("料表格式错误,请确保Excel文件中只有一张表.."); } if (lsname[0].Split('-').Length != 3) { throw new Exception("料表名称规则不符,正确格式 => \"工单号-成品料号-BOM版本\""); } DataTable _dt = ClsReadExcel.getTable(ofd.FileName, lsname[0]); if (_dt.Rows.Count < 1) { throw new Exception("料表中没有数据,请检查.."); } if (_dt.Columns.Count != this.mBomHadInfo.Length) { throw new Exception("料表格式错误,请检查料表的第一行标题信息是否不符合规则"); } for (int x = 0; x < _dt.Columns.Count; x++) { bool flag = false; foreach (string item in this.mBomHadInfo) { if (_dt.Columns[x].Caption == item) { flag = true; break; } } if (!flag) { throw new Exception("料表标题不符合规则,请查看文件"); } DataTable mdt = _dt.DefaultView.ToTable(true, new string[] { "生产工单号" }); int xx = 0; for (int i = 0; i < mdt.Rows.Count; i++) { if (!string.IsNullOrEmpty(mdt.Rows[i][0].ToString())) { xx++; } } if (xx != 1) { throw new Exception("导入的工单料表中存在多个工单号名称,请检查.."); } DataTable mdtt = _dt.DefaultView.ToTable(true, new string[] { "成品料号" }); int xxx = 0; for (int i = 0; i < mdtt.Rows.Count; i++) { if (!string.IsNullOrEmpty(mdtt.Rows[i][0].ToString())) { xxx++; } } if (xxx != 1) { throw new Exception("导入的工单料表中存在多个成品料号,请检查.."); } } //查询导入的料表对应的工单号是否在系统中已经建立 int ic = 0; this.mFrm.ShowPrgMsg(string.Format("累计[{0}]颗物料需要导入系统", _dt.Rows.Count), MainParent.MsgType.Warning); foreach (DataRow dr in _dt.Rows) { if (!dr.IsNull("生产工单号") && !dr.IsNull("成品料号") && !dr.IsNull("组件料号")) { Dictionary <string, object> dic = new Dictionary <string, object>(); dic.Add("KPDESC", dr[eBomHadInfo.组件物料描述.ToString()].ToString()); dic.Add("KPNUMBER", dr[eBomHadInfo.组件料号.ToString()].ToString()); dic.Add("PARTNUMBER", dr[eBomHadInfo.成品料号.ToString()].ToString()); dic.Add("PROCESS", dr[eBomHadInfo.制程段.ToString()].ToString()); dic.Add("QTY", string.IsNullOrEmpty(dr[eBomHadInfo.数量.ToString()].ToString()) ? 0 : int.Parse(dr[eBomHadInfo.数量.ToString()].ToString())); dic.Add("USERID", this.mFrm.gUserInfo.userId); dic.Add("WOID", dr[eBomHadInfo.生产工单号.ToString()].ToString()); dic.Add("BOMVER", lsname[0].Split('-')[2].Replace("$'", "")); string _StrErr = refWebtWoBomInfo.Instance.InsertWoBomInfo(FrmBLL.ReleaseData.DictionaryToJson(dic)); if (_StrErr == "OK") { this.ShowMsg(LogMsgType.Outgoing, string.Format("第[{0}]颗:[{1}]导入成功", ic + 1, dr[eBomHadInfo.组件料号.ToString()].ToString())); } else { this.ShowMsg(LogMsgType.Error, string.Format("第[{0}]颗:[{1}]导入失败:" + _StrErr, ic + 1, dr[eBomHadInfo.组件料号.ToString()].ToString())); } ic++; } } this.cb_woname.Text = _dt.Rows[0][eBomHadInfo.生产工单号.ToString()].ToString(); this.bt_entrywo_Click(null, null); FrmBLL.publicfuntion.InserSystemLog(this.mFrm.gUserInfo.userId, "导入备料表", "新增", "导入备料表: " + "生产工单:" + _dt.Rows[0][eBomHadInfo.生产工单号.ToString()].ToString() + ";成品料号: " + _dt.Rows[0][eBomHadInfo.成品料号.ToString()].ToString()); this.mFrm.ShowPrgMsg("料件导入完成..", MainParent.MsgType.Incoming); MessageBoxEx.Show(string.Format("料件导入完成\n累计成功导入[{0}]颗物料,请核对", ic)); } } catch (Exception ex) { this.mFrm.ShowPrgMsg(ex.Message, MainParent.MsgType.Error); } }
private string BomInfoToDB(string Excelfilename) { try { //获取excel中有几个表 List <string> lsname = ClsReadExcel.GetTableNames(Excelfilename);// BLL.ClsReadExcel.GetTableNames(ofd.FileName); if (lsname.Count > 1) { throw new Exception("料表格式错误,请确保Excel文件中只有一张表.."); } if (lsname[0].Split('-').Length != 3) { throw new Exception("料表名称规则不符,正确格式 => \"工单号-成品料号-BOM版本\""); } DataTable _dt = ClsReadExcel.getTable(Excelfilename, lsname[0]); if (_dt.Rows.Count < 1) { throw new Exception("料表中没有数据,请检查.."); } if (_dt.Columns.Count != this.mBomHadInfo.Length) { throw new Exception("料表格式错误,请检查料表的第一行标题信息是否不符合规则"); } for (int x = 0; x < _dt.Columns.Count; x++) { bool flag = false; foreach (string item in this.mBomHadInfo) { if (_dt.Columns[x].Caption == item) { flag = true; break; } } if (!flag) { throw new Exception("料表标题不符合规则,请查看文件"); } DataTable mdt = _dt.DefaultView.ToTable(true, new string[] { "生产工单号" }); int xx = 0; for (int i = 0; i < mdt.Rows.Count; i++) { if (!string.IsNullOrEmpty(mdt.Rows[i][0].ToString())) { xx++; } } if (xx != 1) { throw new Exception("导入的工单料表中存在多个工单号名称,请检查.."); } DataTable mdtt = _dt.DefaultView.ToTable(true, new string[] { "成品料号" }); int xxx = 0; for (int i = 0; i < mdtt.Rows.Count; i++) { if (!string.IsNullOrEmpty(mdtt.Rows[i][0].ToString())) { xxx++; } } if (xxx != 1) { throw new Exception("导入的工单料表中存在多个成品料号,请检查.."); } } //查询导入的料表对应的工单号是否在系统中已经建立 int ic = 0; foreach (DataRow dr in _dt.Rows) { if (!dr.IsNull("生产工单号") && !dr.IsNull("成品料号") && !dr.IsNull("组件料号")) { RefWebService_BLL.refWebtWoBomInfo.Instance.InsertWoBomInfo(new WebServices.tWoBomInfo.T_WO_BOM_INFO() { kpdesc = dr[eBomHadInfo.组件物料描述.ToString()].ToString(), kpnumber = dr[eBomHadInfo.组件料号.ToString()].ToString(), partnumber = dr[eBomHadInfo.成品料号.ToString()].ToString(), process = dr[eBomHadInfo.制程段.ToString()].ToString(), qty = string.IsNullOrEmpty(dr[eBomHadInfo.数量.ToString()].ToString()) ? 0 : int.Parse(dr[eBomHadInfo.数量.ToString()].ToString()), userId = this.mFrm.gUserInfo.userId, woId = dr[eBomHadInfo.生产工单号.ToString()].ToString(), wbiId = Guid.NewGuid(), bomver = lsname[0].Split('-')[2].Replace("$'", "") }); //this.ShowMsg(LogMsgType.Outgoing, string.Format("第[{0}]颗:[{1}]导入成功", ic + 1, dr[eBomHadInfo.组件料号.ToString()].ToString())); ic++; } } FrmBLL.publicfuntion.InserSystemLog(this.mFrm.gUserInfo.userId, "导入备料表", "新增", "导入备料表: " + "生产工单:" + _dt.Rows[0][eBomHadInfo.生产工单号.ToString()].ToString() + ";成品料号: " + _dt.Rows[0][eBomHadInfo.成品料号.ToString()].ToString()); return(string.Empty); //this.mFrm.ShowPrgMsg("料件导入完成..", MainParent.MsgType.Incoming); // MessageBoxEx.Show(string.Format("料件导入完成\n累计成功导入[{0}]颗物料,请核对", ic)); } catch (Exception ex) { return(ex.Message); //this.mFrm.ShowPrgMsg(ex.Message, MainParent.MsgType.Error); } }