Exemple #1
0
        private void bt_savecraft_Click(object sender, EventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(this.txt_craftid.Text))
                {
                    throw new Exception("工艺编号不能为空");
                }
                if (string.IsNullOrEmpty(this.txt_craftname.Text))
                {
                    throw new Exception("工艺描述不能为空");
                }
                if (string.IsNullOrEmpty(this.cbx_beworkseg.Text))
                {
                    throw new Exception("请选择所属制程段");
                }
                if (cbx_beworkseg.Text.Length > 15)
                {
                    throw new Exception("制程段不能大于15位");
                }
                if (txt_craftname.Text.Length > 18)
                {
                    throw new Exception("工艺名称不能大于18位");
                }
                if (string.IsNullOrEmpty(txt_testflag.Text))
                {
                    throw new Exception("工艺标记为空");
                }

                ////if (string.IsNullOrEmpty(this.dgv_addcraftitem["CraftItem",0].Value.ToString()))
                if (this.dgv_addcraftitem.Rows.Count - 1 < 1)
                {
                    if (MessageBoxEx.Show(string.Format("工艺\"{0}\"不存在工艺项目\n 是否确定?", this.txt_craftid.Text), "提示",
                                          MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk) != DialogResult.Yes)
                    {
                        return;
                    }
                }
                else
                {
                    if (MessageBoxEx.Show(string.Format("工艺\"{0}\"存在[{1}]个工艺项目\n 是否确定?",
                                                        this.txt_craftid.Text, this.dgv_addcraftitem.Rows.Count - 1), "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk) != DialogResult.Yes)
                    {
                        return;
                    }
                }

                //if (FrmBLL.publicfuntion.getNewTable(dgv_showcraftitem.DataSource as DataTable, string.Format("{0}='{1}'", (dgv_showcraftitem.DataSource as DataTable).Columns[1].ColumnName, tb_craftdesc.Text)).Rows.Count > 0)
                //{
                //    MessageBox.Show("工艺名称重复", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                //         throw new Exception("工艺名称重复");
                //}

                string err = string.Empty;
                string err1;

                //if ((err = refWebtCraftInfo.Instance.InsertRefCraftInfo(new WebServices.tCraftInfo.tCraftInfo1()
                //  {
                //      beworkseg = this.cb_bworkseg.Text.Trim(),
                //      craftId = this.tb_craftid.Text.Trim(),
                //      craftname = this.tb_craftdesc.Text.Trim(),
                //      craftparameterurl = this.tb_craftparametfileurl.Text.Trim(),
                //      TestFlag = tb_craftflag.Text.Trim()
                //  }, this.GetCraftItem().ToArray(), out err1)) != "OK")

                Dictionary <string, object> dic = new Dictionary <string, object>();
                publicfuntion.SerializeControl(dic, panel5);
                if ((err = refWebtCraftInfo.Instance.InsertRefCraftInfo(ReleaseData.DictionaryToJson(dic), ReleaseData.ListDictionaryToJson(GetCraftItem()), out err1)) != "OK")

                {
                    this.mFrm.ShowPrgMsg(err, MainParent.MsgType.Error);
                    return;
                }
                ShowCraftInfo();
                this.mFrm.ShowPrgMsg(string.Format("工艺\"{0}\"添加成功",
                                                   this.txt_craftname.Text), MainParent.MsgType.Outgoing);

                this.txt_craftname.Text         = "";
                this.txt_craftid.Text           = "";
                this.txt_CRAFTPARAMETERURL.Text = "";
                this.tb_qutrycraftid.Text       = "";
            }
            catch (Exception ex)
            {
                this.mFrm.ShowPrgMsg(ex.Message, MainParent.MsgType.Error);
            }
        }
Exemple #2
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, "提示");
            }
        }