private void mbt_OpenExcel_Click(object sender, EventArgs e) { try { dicnames = new Dictionary <string, string>(); 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) { this.mExcleFile = ofd.FileName; //在打开Excel文档时就去判断文档内容是否符合规则要求 List <string> lsnames = ClsReadExcel.GetTableNames(ClsReadExcel.FileExists(this.mExcleFile)); DataTable mdatatable = new DataTable(); string side = string.Empty; foreach (string item in lsnames) { side = "T";// item.Split('-')[1].Substring(0, 1); if (item.Split(' ').Length < 2) { throw new Exception("料站表的命名规则不符,请重新修正.."); } if (string.IsNullOrEmpty(side)) { throw new Exception("文档命名不符合规则(\"产品名称-PCB版面+F\")"); } //if ("T" != side && "B" != side) //throw new Exception("文档命名不符合规则(\"产品名称-PCB版面+F\")"); //添加Feeder类型 string sql = string.Format("select 产品料号,产品描述,机器编号,BOM版本,料站总数,count(*) as 料站数 from [{0}] group by 产品料号,产品描述,机器编号,BOM版本,料站总数 having 机器编号 is not null", item); //string sql = string.Format("select 产品料号,产品描述,机器编号,BOM版本,料站总数,count(*) as 料站数 from [{0}] group by 产品料号,产品描述,机器编号,BOM版本,料站总数 having 机器编号 is not null", // item); mdatatable = ClsReadExcel.getTableForSql(ClsReadExcel.FileExists(this.mExcleFile), sql); this.dicnames.Add(item.Replace('\'', ' ').Replace('$', ' ').Trim(), item); if (mdatatable.Rows.Count > 2) { if (this.ShowMsg("一条生产线的参数设置过多\n默认只支持左边、右边,请重新设置..")) { throw new Exception("一条生产线的参数设置过多,默认只支持左边、右边,请检查料表设置.."); } } } //this.dgv_had.DataSource = mdatatable; // this.dgv_had.Columns["料站数"].Visible = false; this.ip_linenamelist.Items.Clear(); foreach (string item in this.dicnames.Keys) { this.ip_linenamelist.Items.Add(new DevComponents.DotNetBar.CheckBoxItem(item, item)); this.ip_linenamelist.Refresh(); } //将料站表上传FTP try { FrmBLL.Ftp_MyFtp ftp = new FrmBLL.Ftp_MyFtp(); ftp.PutImage(ofd.FileName); } catch (Exception ex) { this.mainfrm.ShowPrgMsg(ex.Message, MainParent.MsgType.Warning); } } } catch (Exception ex) { this.mainfrm.ShowPrgMsg(ex.Message, MainParent.MsgType.Error); } }
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); } }