Beispiel #1
0
        private void ip_linenamelist_ItemClick(object sender, EventArgs e)
        {
            try
            {
                List <string> lsValue = new List <string>();
                if (this.ip_linenamelist.SelectedItems.Count > 0)
                {
                    for (int i = 0; i < this.ip_linenamelist.Items.Count; i++)
                    {
                        if ((this.ip_linenamelist.Items[i] as DevComponents.DotNetBar.CheckBoxItem).Checked)
                        {
                            lsValue.Add(this.dicnames[(this.ip_linenamelist.Items[i] as DevComponents.DotNetBar.CheckBoxItem).Text]);
                        }
                    }
                }

                this.dgv_had.DataSource = ClsReadExcel.getTableHad(ClsReadExcel.FileExists(this.mExcleFile), lsValue.ToArray());

                this.dgv_dta.DataSource = ClsReadExcel.getTableDta(ClsReadExcel.FileExists(this.mExcleFile), lsValue.ToArray());
                if (this.dgv_had.Rows.Count > 0)
                {
                    this.dgv_had.Columns["料站数"].Visible = false;
                }
            }
            catch (Exception ex)
            {
                this.mainfrm.ShowPrgMsg(ex.Message, MainParent.MsgType.Warning);
            }
        }
Beispiel #2
0
        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);
            }
        }
Beispiel #3
0
        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);
            }
        }
Beispiel #4
0
        private void ExportDb(DataTable dgvDtTemp, DataGridView dgvhad)
        {
            try
            {
                this.mainfrm.ShowPrgMsg("正在导入数据", MainParent.MsgType.Outgoing);
                #region 20150811导入料站表时,删除整条线体料表
                DataTable dtMachineLine = FrmBLL.ReleaseData.arrByteToDataTable(refWebtMachineInfo.Instance.GetAllMachineInfo());
                string    _Machine      = null;
                string    _PartNumber   = string.Empty;
                string    _PcbaSide     = string.Empty;
                for (int i = 0; i < dgvhad.Rows.Count; i++)
                {
                    _PartNumber = dgvhad["产品料号", i].Value.ToString();
                    _PcbaSide   = dgvhad["PCB面", i].Value.ToString();
                    if (i == dgvhad.Rows.Count - 1)
                    {
                        _Machine += "'" + dgvhad["机器编号", i].Value.ToString() + "'";
                    }
                    else
                    {
                        _Machine += "'" + dgvhad["机器编号", i].Value.ToString() + "',";
                    }
                }
                DataTable dtLine            = ClsReadExcel.getNewTable(dtMachineLine, string.Format("MACHINEID IN ({0})", _Machine));
                DataView  dataView          = dtLine.DefaultView;
                DataTable dataTableDistinct = dataView.ToTable(true, "LINEID");
                string    _SmtLine          = null;
                for (int x = 0; x < dataTableDistinct.Rows.Count; x++)
                {
                    if (x == dataTableDistinct.Rows.Count - 1)
                    {
                        _SmtLine += "'" + dataTableDistinct.Rows[x]["LINEID"].ToString() + "'";
                    }
                    else
                    {
                        _SmtLine += "'" + dataTableDistinct.Rows[x]["LINEID"].ToString() + "',";
                    }
                }
                DataTable _SmtMachine = ClsReadExcel.getNewTable(dtMachineLine, string.Format("LINEID IN ({0})", _SmtLine));

                List <string> LsMachine = new List <string>();
                for (int y = 0; y < _SmtMachine.Rows.Count; y++)
                {
                    LsMachine.Add(_SmtMachine.Rows[y]["MACHINEID"].ToString());
                }

                string _StrErr = refWebSmtKpMaster.Instance.DeleteSmtKpMaster(LsMachine.ToArray(), _PartNumber, _PcbaSide);
                if (_StrErr != "OK")
                {
                    throw new Exception("删除料站表头信息失败:" + _StrErr);
                }
                #endregion

                for (int i = 0; i < dgvhad.Rows.Count; i++)
                {
                    DataTable dtTemp = ClsReadExcel.getNewTable(dgvDtTemp,
                                                                string.Format("产品料号='{0}' and 产品描述='{1}' and 机器编号='{2}' and BOM版本='{3}'",
                                                                              dgvhad["产品料号", i].Value.ToString(), dgvhad["产品描述", i].Value.ToString(),
                                                                              dgvhad["机器编号", i].Value.ToString(), dgvhad["BOM版本", i].Value.ToString()));

                    List <IDictionary <string, object> > lskpdetalt = new List <IDictionary <string, object> >();
                    Dictionary <string, object>          kpdetalt   = null;
                    foreach (DataRow dr in dtTemp.Rows)
                    {
                        kpdetalt = new Dictionary <string, object>();
                        kpdetalt.Add("KPDESC", dr["品名与规格"].ToString());
                        kpdetalt.Add("KPDISTINCT", int.Parse(!string.IsNullOrEmpty(dr["优先级"].ToString()) ? dr["优先级"].ToString() : "0") > 1 ? "0" : "1");
                        kpdetalt.Add("KPNUMBER", dr["组件料号"].ToString());
                        kpdetalt.Add("LOCTION", dr["组件位置"].ToString());
                        kpdetalt.Add("PRIORITYCLASS", int.Parse(!string.IsNullOrEmpty(dr["优先级"].ToString()) ? dr["优先级"].ToString() : "0"));
                        kpdetalt.Add("STATIONNO", dr["料站"].ToString());

                        if (!string.IsNullOrEmpty(dr["替代组"].ToString()))
                        {
                            kpdetalt.Add("REPLACEGROUP", dr["替代组"].ToString());
                        }

                        if (!string.IsNullOrEmpty(dr["组件位置"].ToString().Trim()))
                        {
                            kpdetalt.Add("RESERVE1", GetKpUnit(dr["组件位置"].ToString().Trim()));
                        }

                        if (!string.IsNullOrEmpty(dr["FEEDER类型"].ToString()))
                        {
                            kpdetalt.Add("RESERVE", dr["FEEDER类型"].ToString());
                        }

                        lskpdetalt.Add(kpdetalt);
                        //lskpdetalt.Add(new WebServices.ExcelToDb.SMT_KP_DETALT()
                        //{
                        //    KPDesc = dr["品名与规格"].ToString(),
                        //    KPDistinct = int.Parse(!string.IsNullOrEmpty(dr["优先级"].ToString()) ? dr["优先级"].ToString() : "0") > 1 ? false : true,
                        //    KPNumber = dr["组件料号"].ToString(),
                        //    Loction = dr["组件位置"].ToString(),
                        //    loctionLen = dr["组件位置"].ToString().Length,---未增加此行 20150203 michael
                        //    //Masterid = _masterId,
                        //    Priorityclass = int.Parse(!string.IsNullOrEmpty(dr["优先级"].ToString()) ? dr["优先级"].ToString() : "0"),
                        //    Stationno = dr["料站"].ToString(),
                        //    Replacegroup = dr["替代组"].ToString(),
                        //    reserve1 = GetKpUnit(dr["组件位置"].ToString().Trim()),
                        //    reserve = dr["FEEDER类型"].ToString()  //添加Feeder类型
                        //});
                    }

                    Dictionary <string, object> SmtKpMater = new Dictionary <string, object>();
                    SmtKpMater.Add("BOMVER", dgvhad["BOM版本", i].Value.ToString());
                    SmtKpMater.Add("LINEID", dgvhad["机器编号", i].Value.ToString());
                    SmtKpMater.Add("RESERVE1", dgvhad["SMT程式", i].Value.ToString());
                    SmtKpMater.Add("MODELNAME", dgvhad["产品描述", i].Value.ToString());
                    SmtKpMater.Add("PARTNUMBER", dgvhad["产品料号", i].Value.ToString());
                    SmtKpMater.Add("PCBSIDE", dgvhad["PCB面", i].Value.ToString());
                    SmtKpMater.Add("USERID", this.mainfrm.gUserInfo.userId);
                    //refWebExcelToDb.Instance.InsertMaterTable(new WebServices.ExcelToDb.SMT_KP_MASTER()
                    //{
                    //    bomver = dgvhad["BOM版本", i].Value.ToString(),
                    //    Lineid = dgvhad["机器编号", i].Value.ToString(),
                    //    reserve1 = dgvhad["SMT程式",i].Value.ToString(),
                    //    // masterId = _masterId,
                    //    modelname = dgvhad["产品描述", i].Value.ToString(),
                    //    partnumber = dgvhad["产品料号", i].Value.ToString(),
                    //    pcbside = dgvhad["PCB面", i].Value.ToString(),
                    //    Userid = this.mainfrm.gUserInfo.userId
                    //},  lskpdetalt);

                    refWebExcelToDb.Instance.InsertMaterTable(ReleaseData.DictionaryToJson(SmtKpMater), ReleaseData.ListDictionaryToJson(lskpdetalt));
                }


                FrmBLL.publicfuntion.InserSystemLog(mainfrm.gUserInfo.userId, "导入料站表", "新增", "导入料站表: " + "产品料号:" + dgv_had["产品料号", 0].Value.ToString() + ";机器编号: " + dgv_had["机器编号", 0].Value.ToString());

                this.mainfrm.ShowPrgMsg("数据导入成功..");
                MessageBoxEx.Show("数据导入成功", "提示");
            }
            catch (Exception ex)
            {
                if (ex.Message.IndexOf("FOREIGN KEY") != -1)
                {
                    this.mainfrm.ShowPrgMsg("料站表中的[机器编号]不存在于系统,请先添加机器信息.", MainParent.MsgType.Error);
                }
                else
                {
                    this.mainfrm.ShowPrgMsg(ex.Message, MainParent.MsgType.Error);
                }
                MessageBoxEx.Show("数据导入失败,错误信息如下:\n" + ex.Message, "提示");
            }
        }
Beispiel #5
0
 private void button1_Click(object sender, EventArgs e)
 {
     //打印预览
     ClsReadExcel.ExcelPreview("d:\\QC-120607132719_20120625.xml");
 }
Beispiel #6
0
        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);
            }
        }