private void btn_Query_Click(object sender, EventArgs e)
 {
     //product info query
     if (this.txt_ProductNo.Text.Trim().Length > 0)
     {
         clearBOMText();
         List <MaterialInfo> materialsList = new List <MaterialInfo>();
         ProductBOMs         _productBOMs  = new ProductBOMs();
         if (this.txt_ProductNo.Text.Trim().Length > 0)
         {
             materialsList = _productBOMs.GetProductBOMList(this.txt_ProductNo.Text.Trim());
             materialsList = materialsList.OrderBy(o => o.MaterialSeq).ToList();//升序
             if (materialsList.Count > 0)
             {
                 fillMaterialsInfo(materialsList);
                 this.txt_ProductName.Text = ProductBOMBLL.GetProductName(this.txt_ProductNo.Text.Trim());
             }
             else
             {
                 SpMessageBox.Show("没有查找到对应产品BOM信息, 请重新输入正确的产品号.", "产品信息维护");
             }
         }
     }
     else
     {
     }
 }
        private void btnLogin_Click(object sender, EventArgs e)
        {
            if (this.comboProductionLine.Text.Trim() == string.Empty)
            {
                SpMessageBox.Show("请选择产线编号.", "用户登录");
                return;
            }
            else
            {
                CurrentProductionLine       = this.comboProductionLine.Text.Trim();
                CurrentProductionLineNumber = byte.Parse(System.Text.RegularExpressions.Regex.Replace(Login.CurrentProductionLine, @"[^0-9]+", ""));
            }

            if (this.cmbUser.Text.Trim() != string.Empty)
            {
                UserName = this.cmbUser.Text.Trim();

                if (!CheckUserandPswd(UserName, txtLoginPwd.Text.Trim()))
                {
                    ShowLoginTip("用户名或密码错误,请重新输入.");
                    return;
                }

                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            //string loginTrace = string.Format("{0}: User {1} Login", DateTime.Now, UserName);
            //LogerHelper.ToAutoTestLogFile(loginTrace);

            SystemLogs.WriteSystemLog(UserName, "Login to " + CurrentProductionLine, DateTime.Now);
            Login.Authority   = (LoginAuthority)UserInfos.GetRoleByUser(Login.UserName);
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
        private void btn_AddOrder_Click(object sender, EventArgs e)
        {
            if ((this.txtAddOrderNo.Text.Trim().Length > 0) && (this.txtAddProdNo.Text.Trim().Length > 0) && (RegularHelper.isNumericString(this.txtAddOrderCount.Text.Trim())))
            {
                DialogResult diaresult = SpMessageBox.Show("确定要补充该订单吗?", "订单补充", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);

                if (diaresult == DialogResult.OK)
                {
                    if (OrderInfoBLL.OrderAlreadyExsit(this.txtAddOrderNo.Text.Trim()))
                    {
                        if (OrderInfo.UpdateOrderCount(this.txtAddOrderNo.Text.Trim(), this.txtAddProdNo.Text.Trim(), int.Parse(this.txtAddOrderCount.Text.Trim())))
                        {
                            SpMessageBox.Show("该订单数量补充完成", "订单补充");
                        }
                    }
                    else
                    {
                        SpMessageBox.Show("该订单号不存在,请检查该订单号是否生效", "订单补充");
                    }


                    SystemLogs.WriteSystemLog(Login.UserName, "add order count:" + this.txtAddOrderCount.Text.Trim() + " for order " + this.txtAddOrderNo.Text.Trim() + " at " + Login.CurrentProductionLine, DateTime.Now);
                }
            }
            else
            {
                SpMessageBox.Show("请检查订单号,产品号,和订单数量的输入", "订单补充");
            }
        }
        private void btnRemove_Click(object sender, EventArgs e)
        {
            if (lsvUserInfo.SelectedItems.Count < 1)
            {
                SpMessageBox.Show("请先选择一个用户,再进行编辑.", "用户管理");
                return;
            }

            if (UserInfos.GetRoleByUser(Login.UserName) != (byte)LoginAuthority.Operator && UserInfos.GetRoleByUser(Login.UserName) != (byte)LoginAuthority.Unkown)
            {
                if (UserInfos.GetRoleByUser(lsvUserInfo.SelectedItems[0].SubItems[0].Text.Trim()) == (int)LoginAuthority.Administrator || UserInfos.GetRoleByUser(lsvUserInfo.SelectedItems[0].SubItems[0].Text.Trim()) == (int)LoginAuthority.SuperAdmin)
                {
                    SpMessageBox.Show("不能删除管理员用户!", "用户管理");
                    return;
                }
            }

            if (SpMessageBox.Show("确定删除?", "用户管理", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == System.Windows.Forms.DialogResult.OK)
            {
                UserInfo tmpUserInfo = new UserInfo();

                tmpUserInfo.UserName = lsvUserInfo.SelectedItems[0].SubItems[0].Text;

                if (tmpUserInfo.DeleteUserInfoTable())
                {
                    lsvUserInfo.SelectedItems[0].Remove();
                }
                else
                {
                    SpMessageBox.Show("删除失败!", "用户管理");
                    lsvUserInfo.SelectedItems[0].Selected = false;
                }

                //clear testbox;
                txt_UserName.Text             = String.Empty;
                txt_Password.Text             = String.Empty;
                txt_PasswordConfirm.Text      = String.Empty;
                combo_Authority.SelectedIndex = -1;

                btnRemove.Enabled = false;
                btnEdit.Enabled   = false;


                btnEdit.BackgroundImage   = Properties.Resources._5_edit_disable;
                btnRemove.BackgroundImage = Properties.Resources._5_delete_disable;


                btnAdd.Enabled     = true; //add
                btnEdit.Enabled    = true; //edit
                btnConfirm.Enabled = true; //confirm
                btnCancel.Enabled  = true; //cancel
                btnRemove.Enabled  = true; //delete

                btnAdd.BackgroundImage     = Properties.Resources._5_add;
                btnEdit.BackgroundImage    = Properties.Resources._4_edit;
                btnConfirm.BackgroundImage = Properties.Resources._5_ok;
                btnCancel.BackgroundImage  = Properties.Resources._5_cancel;
                btnRemove.BackgroundImage  = Properties.Resources._5_delete;
            }
        }
Beispiel #5
0
 private void btn_OK_Click(object sender, EventArgs e)
 {
     if (this.txt_MaterialNo.Text.Trim().Length > 0 &&
         this.txt_MaterialName.Text.Trim().Length > 0 &&
         RegularHelper.isNumericString(this.txt_MaterialPos.Text.Trim()) &&
         RegularHelper.isNumericString(this.txt_CountPerBox.Text.Trim()) &&
         RegularHelper.isNumericString(this.txt_UsageTime.Text.Trim()))
     {
         if (MaterialInfoBLL.UpdateMaterial(this.txt_MaterialNo.Text.Trim(), this.txt_MaterialName.Text.Trim(),
                                            byte.Parse(this.txt_MaterialPos.Text.Trim()), int.Parse(this.txt_CountPerBox.Text.Trim()), int.Parse(this.txt_UsageTime.Text.Trim())))
         {
             ShowLoginTip("零件信息更新成功.");
             updateCurrentRow();
         }
         else if (MaterialInfoBLL.InsertMaterial(this.txt_MaterialNo.Text.Trim(), this.txt_MaterialName.Text.Trim(),
                                                 byte.Parse(this.txt_MaterialPos.Text.Trim()), int.Parse(this.txt_CountPerBox.Text.Trim()), int.Parse(this.txt_UsageTime.Text.Trim())))
         {
             ShowLoginTip("零件信息添加成功.");
             Load_lsv_MaterialInfo();
         }
         else
         {
             SpMessageBox.Show(this.txt_MaterialName.Text.Trim() + "信息更新失败.", "零件信息维护");
         }
     }
 }
        private void btn_EmergSupplyOK_Click(object sender, EventArgs e)
        {
            if (this.comboMaterialNo.Text.Trim().Length > 0 && RegularHelper.isNumericString(this.txtMaterialCount.Text.Trim()))
            {
                try
                {
                    //调用tcp/ip 协议,发送紧急备料请求到库房App
                    //Server.
                    MainForm.CheckConnectionWithServer();
                    Program.S.SendMessageToWS(Login.CurrentProductionLineNumber.ToString(),
                                              this.comboMaterialNo.Text.Trim(),
                                              AH.Network.MsgType.Emerg);
                }
                catch (Exception excpt)
                {
                    SpMessageBox.Show("告警:" + excpt.Message, "通信-库房");
                }

                SystemLogs.WriteSystemLog(Login.UserName, "Sending urgent request for material " + this.comboMaterialNo.Text.Trim() + " at " + Login.CurrentProductionLine, DateTime.Now);

                ShowLoginTip("紧急Call料请求已发送.");
            }
            else
            {
                SpMessageBox.Show("请检查订单号,产品号,和订单数量的输入", "订单查询");
            }
        }
        private void btn_SwitchLine_Click(object sender, EventArgs e)
        {
            DialogResult diaresult = SpMessageBox.Show("确定要切线吗?", "切线操作", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);

            if (diaresult == DialogResult.OK)
            {
                if (UserInfos.GetRoleByUser(Login.UserName) == (byte)LoginAuthority.SuperAdmin || UserInfos.GetRoleByUser(Login.UserName) == (byte)LoginAuthority.Administrator)
                {
                    try
                    {
                        if (ProductionLineMaterial.GetMaterialsTotalRemainConsump(Login.CurrentProductionLineNumber, this.txtOrderNo.Text.Trim()) > 0) //切线前,先判断是否已经扣料了
                        {
                            SpMessageBox.Show("该订单生产还没有进行扣料,请先进行扣料然后再切线.", "生产切线");

                            try
                            {
                                Program.S.SendMessageToWS(Login.CurrentProductionLineNumber.ToString(),
                                                          this.txtOrderNo.Text.Trim() + "|" + this.textProdNo.Text.Trim() + "|" + this.textOrderCount.Text.Trim(),
                                                          AH.Network.MsgType.Deduct);
                            }
                            catch (Exception excpt)
                            {
                                SpMessageBox.Show("告警:" + excpt.Message, "通信-库房");
                            }
                            return;
                        }
                    }
                    catch (Exception excpt)
                    {
                        SpMessageBox.Show("告警:" + excpt.Message, "生产切线");
                        return;
                    }

                    SystemLogs.WriteSystemLog(Login.UserName, "Switch order from " + this.txtOrderNo.Text.Trim() + "to other order at " + Login.CurrentProductionLine, DateTime.Now);


                    ProductionLine.RemoveOrderAndProductionLineInfo(Login.CurrentProductionLineNumber, this.txtOrderNo.Text.Trim());


                    //切线时,没有必要删除database里这个order.....
                    this.listView_CurrentOrder.Items.Clear();
                    this.txtOrderNo.Clear();
                    this.textOrderCount.Clear();
                    this.textProdNo.Clear();

                    CurrentOrderMaterialsList.Clear();

                    // stop the timer when switch orders/producitonline
                    MainForm.timer_ReadSensors.Enabled = false;
                }
                else
                {
                    SpMessageBox.Show("当前用户没有权限执行切线操作,请联系 Administrator.", "切线操作");
                }
            }
        }
        private void CheckOrder()
        {
            List <MaterialInfo> materialsList = new List <MaterialInfo>();

            if ((this.textProdNo.Text.Trim().Length > 0) && (RegularHelper.isNumericString(this.textOrderCount.Text.Trim().ToString())))
            {
                OrderInfo.CheckOrderExsit(this.txtOrderNo.Text.Trim(), this.textProdNo.Text.Trim(), int.Parse(this.textOrderCount.Text.Trim().ToString()));
            }
            else
            {
                SpMessageBox.Show("请检查是否输入了产品号和订单数量?", "订单查询");
            }
        }
        private void UpdateProductionLineInfo()
        {
            if ((this.textProdNo.Text.Trim().Length > 0) && (RegularHelper.isNumericString(this.textOrderCount.Text.Trim().ToString())))
            {//string _orderNo, byte _productLineNo, string _productNo, int _orderCount
                ProductionLine.CheckProductionLineExsit(this.txtOrderNo.Text.Trim(), Login.CurrentProductionLineNumber, this.textProdNo.Text.Trim(), int.Parse(this.textOrderCount.Text.Trim().ToString()));

                if (!ProductionLineInfoBLL.CheckThisProductionLineInfo(Login.CurrentProductionLineNumber, this.txtOrderNo.Text.Trim()))  //如果当前产线号存在 productionline表里,需要double check order号是否也一样? 如果一样则OK, 如果不一样,则需要告警:还没切线呢
                {
                    SpMessageBox.Show("当前产线还未切线,不能输入进行新订单生产,请先执行切线操作", "订单查询");
                }
            }
            else
            {
                SpMessageBox.Show("请检查是否输入了正确的订单号和产品号.", "订单查询");
            }
        }
        private void btnOrderOK_Click(object sender, EventArgs e)
        {
            if ((this.txtOrderNo.Text.Trim().Length > 0) && (this.textProdNo.Text.Trim().Length > 0) && (RegularHelper.isNumericString(this.textOrderCount.Text.Trim().ToString())))
            {
                //check the order and product in db? if yes, just query the BOM list, else insert the order to db first, then query the BOM list
                CheckOrder();

                UpdateProductionLineInfo();
                //this.listView_CurrentOrder.Items.Clear();
                Load_Lsv_BOMList();
                CurrentProductOrder = this.txtOrderNo.Text.Trim();
                SystemLogs.WriteSystemLog(Login.UserName, "Scanning order " + this.txtOrderNo.Text.Trim() + " at " + Login.CurrentProductionLine, DateTime.Now);
            }
            else
            {
                SpMessageBox.Show("请检查订单号,产品号,和订单数量的输入.", "订单查询");
            }
        }
        private void btnEdit_Click(object sender, EventArgs e)
        {
            if (lsvUserInfo.SelectedItems.Count < 1)
            {
                SpMessageBox.Show("请先选择一个用户,再进行编辑.", "用户管理");
                return;
            }

            if (UserInfos.GetRoleByUser(Login.UserName) == (byte)LoginAuthority.Operator)
            {
                SpMessageBox.Show("您没有添加用户的权限!", "用户管理");
                return;
            }

            combo_Authority.Enabled = true;       //超级管理员用户才能编辑其他用户的权限

            txt_UserName.Enabled          = true; //could not change name
            txt_Password.Enabled          = true;
            txt_PasswordConfirm.Enabled   = true;
            txt_UserName.Text             = lsvUserInfo.SelectedItems[0].SubItems[0].Text.Trim();
            combo_Authority.SelectedIndex = ((lsvUserInfo.SelectedItems[0].SubItems[1].Text.Trim() == "管理员") ? 1 :
                                             ((combo_Authority.Text.Trim() == "超级管理员") ? 2 :
                                              ((combo_Authority.Text.Trim() == "操作员") ? 0 : -1)));;
            txt_Password.Text        = "";
            txt_PasswordConfirm.Text = "";

            btnAdd.Enabled     = false; //add
            btnEdit.Enabled    = false; //edit
            btnConfirm.Enabled = true;  //confirm
            btnCancel.Enabled  = true;  //cancel
            btnRemove.Enabled  = false; //delete

            btnAdd.BackgroundImage     = Properties.Resources._5_add_disable;
            btnEdit.BackgroundImage    = Properties.Resources._5_edit_disable;
            btnConfirm.BackgroundImage = Properties.Resources._5_ok;
            btnCancel.BackgroundImage  = Properties.Resources._5_cancel;
            btnRemove.BackgroundImage  = Properties.Resources._5_delete_disable;

            _opMode = Operation.Edit;

            lsvUserInfo.Enabled = false;
        }
Beispiel #12
0
        private void btnClear_Click(object sender, EventArgs e)
        {
            DialogResult diaresult = SpMessageBox.Show("确定要清空当前订单信息吗?", "清空信息", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);

            if (diaresult == DialogResult.OK)
            {
                if (UserInfos.GetRoleByUser(Login.UserName) == (byte)LoginAuthority.SuperAdmin || UserInfos.GetRoleByUser(Login.UserName) == (byte)LoginAuthority.Administrator)
                {
                    this.listView_NewOrder.Items.Clear();
                    this.txtNewOrderNo.Clear();
                    this.textNewOrderCount.Clear();
                    this.textProdNo.Clear();
                    this.comboBox_Prepare.SelectedIndex = -1;
                }
                else
                {
                    SpMessageBox.Show("当前用户没有权限执行清空操作,请联系 Administrator.", "清空信息");
                }
            }
        }
Beispiel #13
0
        private void sendMaterialReq()
        {
            try
            {
                //调用tcp/ip 协议,发送备料请求到库房App
                MainForm.CheckConnectionWithServer();
                Program.S.SendMessageToWS(Login.CurrentProductionLineNumber.ToString(),
                                          this.txtNewOrderNo.Text.Trim() + "|" + this.textProdNo.Text.Trim() + "|" + this.textNewOrderCount.Text.Trim(),
                                          AH.Network.MsgType.NewDut);
            }
            catch (Exception e)
            {
                SpMessageBox.Show("告警:" + e.Message, "通信-库房");
            }

            //ProductionLine.AddOrderAndProductionLineInfo(Login.CurrentProductionLineNumber,
            //                                              this.txtNewOrderNo.Text.Trim(),
            //                                              int.Parse(this.textNewOrderCount.Text.Trim()),
            //                                              this.textProdNo.Text.Trim());
            SystemLogs.WriteSystemLog(Login.UserName, "Sending materials request for new order " + this.txtNewOrderNo.Text.Trim() + " at " + Login.CurrentProductionLine, DateTime.Now);
        }
        private void btn_Add_Click(object sender, EventArgs e)
        {
            //product info add
            if (this.txt_ProductNo.Text.Trim().Length > 0 && this.txt_ProductName.Text.Trim().Length > 0)
            {
                try
                {
                    if (ProductBOMBLL.InsertProductBOMInfo(this.txt_ProductNo.Text.Trim(), this.txt_ProductName.Text.Trim(),
                                                           this.textBox1.Text.Trim().Length > 0 ? this.textBox1.Text.Trim() : null, (this.comboBox1.Text.Trim().Length > 0 && RegularHelper.isNumericString(this.comboBox1.Text.Trim())) ? byte.Parse(this.comboBox1.Text.Trim()) : (byte)0,
                                                           this.textBox2.Text.Trim().Length > 0 ? this.textBox2.Text.Trim() : null, (this.comboBox2.Text.Trim().Length > 0 && RegularHelper.isNumericString(this.comboBox2.Text.Trim())) ? byte.Parse(this.comboBox2.Text.Trim()) : (byte)0,
                                                           this.textBox3.Text.Trim().Length > 0 ? this.textBox3.Text.Trim() : null, (this.comboBox3.Text.Trim().Length > 0 && RegularHelper.isNumericString(this.comboBox3.Text.Trim())) ? byte.Parse(this.comboBox3.Text.Trim()) : (byte)0,
                                                           this.textBox4.Text.Trim().Length > 0 ? this.textBox4.Text.Trim() : null, (this.comboBox4.Text.Trim().Length > 0 && RegularHelper.isNumericString(this.comboBox4.Text.Trim())) ? byte.Parse(this.comboBox4.Text.Trim()) : (byte)0,
                                                           this.textBox5.Text.Trim().Length > 0 ? this.textBox5.Text.Trim() : null, (this.comboBox5.Text.Trim().Length > 0 && RegularHelper.isNumericString(this.comboBox5.Text.Trim())) ? byte.Parse(this.comboBox5.Text.Trim()) : (byte)0,
                                                           this.textBox6.Text.Trim().Length > 0 ? this.textBox6.Text.Trim() : null, (this.comboBox6.Text.Trim().Length > 0 && RegularHelper.isNumericString(this.comboBox6.Text.Trim())) ? byte.Parse(this.comboBox6.Text.Trim()) : (byte)0,
                                                           this.textBox7.Text.Trim().Length > 0 ? this.textBox7.Text.Trim() : null, (this.comboBox7.Text.Trim().Length > 0 && RegularHelper.isNumericString(this.comboBox7.Text.Trim())) ? byte.Parse(this.comboBox7.Text.Trim()) : (byte)0,
                                                           this.textBox8.Text.Trim().Length > 0 ? this.textBox8.Text.Trim() : null, (this.comboBox8.Text.Trim().Length > 0 && RegularHelper.isNumericString(this.comboBox8.Text.Trim())) ? byte.Parse(this.comboBox8.Text.Trim()) : (byte)0,
                                                           this.textBox9.Text.Trim().Length > 0 ? this.textBox9.Text.Trim() : null, (this.comboBox9.Text.Trim().Length > 0 && RegularHelper.isNumericString(this.comboBox9.Text.Trim())) ? byte.Parse(this.comboBox9.Text.Trim()) : (byte)0,
                                                           this.textBox10.Text.Trim().Length > 0 ? this.textBox10.Text.Trim() : null, (this.comboBox10.Text.Trim().Length > 0 && RegularHelper.isNumericString(this.comboBox10.Text.Trim())) ? byte.Parse(this.comboBox10.Text.Trim()) : (byte)0,
                                                           this.textBox11.Text.Trim().Length > 0 ? this.textBox11.Text.Trim() : null, (this.comboBox11.Text.Trim().Length > 0 && RegularHelper.isNumericString(this.comboBox11.Text.Trim())) ? byte.Parse(this.comboBox11.Text.Trim()) : (byte)0,
                                                           this.textBox12.Text.Trim().Length > 0 ? this.textBox12.Text.Trim() : null, (this.comboBox12.Text.Trim().Length > 0 && RegularHelper.isNumericString(this.comboBox12.Text.Trim())) ? byte.Parse(this.comboBox12.Text.Trim()) : (byte)0,
                                                           this.textBox13.Text.Trim().Length > 0 ? this.textBox13.Text.Trim() : null, (this.comboBox13.Text.Trim().Length > 0 && RegularHelper.isNumericString(this.comboBox13.Text.Trim())) ? byte.Parse(this.comboBox13.Text.Trim()) : (byte)0,
                                                           this.textBox14.Text.Trim().Length > 0 ? this.textBox14.Text.Trim() : null, (this.comboBox14.Text.Trim().Length > 0 && RegularHelper.isNumericString(this.comboBox14.Text.Trim())) ? byte.Parse(this.comboBox14.Text.Trim()) : (byte)0,
                                                           this.textBox15.Text.Trim().Length > 0 ? this.textBox15.Text.Trim() : null, (this.comboBox15.Text.Trim().Length > 0 && RegularHelper.isNumericString(this.comboBox15.Text.Trim())) ? byte.Parse(this.comboBox15.Text.Trim()) : (byte)0,
                                                           this.textBox16.Text.Trim().Length > 0 ? this.textBox16.Text.Trim() : null, (this.comboBox16.Text.Trim().Length > 0 && RegularHelper.isNumericString(this.comboBox16.Text.Trim())) ? byte.Parse(this.comboBox16.Text.Trim()) : (byte)0

                                                           ))
                    {
                        ShowLoginTip("产品信息添加成功.");
                    }
                    else
                    {
                        SpMessageBox.Show(this.txt_ProductName.Text.Trim() + "信息添加失败.", "产品信息维护");
                    }
                }
                catch
                {
                }
            }
        }
        private void btnAdd_Click(object sender, EventArgs e)
        {
            //actually, it should always pass here!
            if (UserInfos.GetRoleByUser(Login.UserName) == (byte)LoginAuthority.Operator)
            {
                SpMessageBox.Show("您没有添加用户的权限!", "用户管理");
                return;
            }
            //always, above.

            txt_UserName.Focus();
            txt_UserName.Enabled        = true;
            txt_Password.Enabled        = true;
            txt_PasswordConfirm.Enabled = true;
            combo_Authority.Enabled     = true;

            txt_UserName.Text             = String.Empty;
            txt_Password.Text             = String.Empty;
            txt_PasswordConfirm.Text      = String.Empty;
            combo_Authority.SelectedIndex = -1;

            btnAdd.Enabled     = false; //add
            btnEdit.Enabled    = false; //edit
            btnConfirm.Enabled = true;  //confirm
            btnCancel.Enabled  = true;  //cancel
            btnRemove.Enabled  = false; //delete


            btnAdd.BackgroundImage     = Properties.Resources._5_add_disable;
            btnEdit.BackgroundImage    = Properties.Resources._5_edit_disable;
            btnConfirm.BackgroundImage = Properties.Resources._5_ok;
            btnCancel.BackgroundImage  = Properties.Resources._5_cancel;
            btnRemove.BackgroundImage  = Properties.Resources._5_delete_disable;


            _opMode = Operation.Add;

            lsvUserInfo.Enabled = false;
        }
Beispiel #16
0
        private void btnNewOrderOK_Click(object sender, EventArgs e)
        {
            //query BOM list according to Product No.
            if ((this.txtNewOrderNo.Text.Trim().Length > 0) && (this.textProdNo.Text.Trim().Length > 0) && (RegularHelper.isNumericString(this.textNewOrderCount.Text.Trim().ToString())))
            {
                //check the order and product in db? if yes, just query the BOM list, else insert the order to db first, then query the BOM list
                CheckOrder();

                Load_Lsv_NewOrderBOM();

                SystemLogs.WriteSystemLog(Login.UserName, "Scanning new order " + this.txtNewOrderNo.Text.Trim() + " at " + Login.CurrentProductionLine, DateTime.Now);

                if (this.comboBox_Prepare.SelectedIndex == 0)
                {
                    sendMaterialReq(); //发送备料请求到库房App
                    ShowLoginTip("新订单备料请求已发送到库房.");
                }
            }
            else
            {
                SpMessageBox.Show("请检查订单号,产品号,和订单数量的输入", "订单查询");
            }
        }
 virtual public void DisableLeave()
 {
     SpMessageBox.Show(ResourceLang.SwitchFormWarning);                          //"添加或编辑操作未完成,不能切换到其他界面!"
     this.Focus();
 }
        static void Main()
        {
//#if DEBUG
//#else
//            KeyboardHook key = new KeyboardHook();
//            key.KeyMaskStop();
//            key.KeyMaskStart();
//            key.DisableTaskMgr(true);
//            key.HWindows();
//            key.HStar();
//#endif
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            Process instance = RunningInstance();

            if (instance == null)
            {
                try
                {
                    ConfigHelper _xmlconfigfile = new ConfigHelper();
                    _xmlconfigfile.FileName = "AutoTestConfig.xml";

                    string dataSrc = _xmlconfigfile.GetValue(@"Settings", @"DataSource");

                    if (dataSrc != "")
                    {
                        GP.MAGICL6800.ORM.ConnectStringHelper.ConnectString = dataSrc;
                    }
                    if (!CheckSqlServerService())
                    {
                        Application.Exit();

                        return;
                    }


                    Login login = new Login();
                    login.ControlBox = false;

                    if (login.ShowDialog() != DialogResult.OK)
                    {
                        //SpMessageBox.Show("Please input the correct username and password!", "Muber BT Test System Login");
                        return;
                    }

                    MainForm autoTestForm = new MainForm();
                    autoTestForm.ControlBox = false;
                    //autoTestForm.Show();

                    //read config file


                    serverIP4Client  = _xmlconfigfile.GetValue(@"Settings", @"IP_Port/ServerIpAddress");
                    clientPortListen = _xmlconfigfile.GetValue(@"Settings", @"IP_Port/ClientPortListen");

                    if (!RegularHelper.isNumericString(clientPortListen))
                    {
                        SpMessageBox.Show("Read Config file AutoTestConfig.xml ClientPortListen error, please check the format.");
                        return;
                    }

                    //string PLCPortListen = _xmlconfigfile.GetValue(@"Settings", @"IP_Port/PLCPortListen");
                    //if (!RegularHelper.isNumericString(PLCPortListen))
                    //{
                    //    SpMessageBox.Show("Read Config file AutoTestConfig.xml PLCPortListen error, please check the format.");
                    //    return;
                    //}

                    //string OutBufferListen = _xmlconfigfile.GetValue(@"Settings", @"IP_Port/OutBufferListen");
                    //if (!RegularHelper.isNumericString(OutBufferListen))
                    //{
                    //    SpMessageBox.Show("Read Config file AutoTestConfig.xml OutBufferListen error, please check the format.");
                    //    return;
                    //}

                    //string hostName = Dns.GetHostName();   //获取本机名
                    //IPHostEntry localhost = Dns.GetHostEntry(hostName);   //获取IPv6地址
                    //IPAddress localaddr = localhost.AddressList[0];
                    //string hostIpAddr = localaddr.ToString();


                    {
                        // S.InitServer(serverIP4Client, serverIP4PLC, int.Parse(clientPortListen), int.Parse(PLCPortListen), int.Parse(OutBufferListen), true);
                        S.InitClient(serverIP4Client, int.Parse(clientPortListen));

                        S.SendMessageToWS(Login.CurrentProductionLineNumber.ToString(),
                                          "register message",
                                          AH.Network.MsgType.Register);
                    }


                    Application.Run(autoTestForm);
                }
                catch (Exception ex)
                {
                    SpMessageBox.Show(ex.Message + ", Please contact the Administrator.", "App启动");
                    //LogerHelper.ToLog(ex.ToString(), false);
                }
            }
            else
            {
                HandleRunningInstance(instance);
            }
        }
        private void btnConfirm_Click(object sender, EventArgs e)
        {
            List <UserInfo> userInfoQryResultArr = UserInfos.GetUserInfoQryResult();

            int adminCount = userInfoQryResultArr.Count(c => c.Role == (byte)LoginAuthority.Administrator);

            if (txt_UserName.Text.Trim() == "")
            {
                SpMessageBox.Show("用户名不能为空!", "用户管理");
                return;
            }

            if (txt_Password.Text.Trim() == "")
            {
                SpMessageBox.Show("密码不能为空!", "用户管理");
                return;
            }

            StringComparer comparer = StringComparer.OrdinalIgnoreCase;

            if (0 == comparer.Compare(txt_UserName.Text.Trim(), "MuberAdmin"))
            {
                SpMessageBox.Show("此用户名不可用!", "用户管理");
                return;
            }

            if (String.Compare(txt_Password.Text, txt_PasswordConfirm.Text) != 0)
            {
                SpMessageBox.Show("两次输入的密码不一致!", "用户管理");
                return;
            }

            if (combo_Authority.SelectedIndex == -1)
            {
                SpMessageBox.Show("请选择用户权限!", "用户管理");
                return;
            }

            //add
            if (_opMode == Operation.Add)
            {
                foreach (ListViewItem lsvUserItemtmp in lsvUserInfo.Items)
                {
                    if (String.Compare(lsvUserItemtmp.Text, txt_UserName.Text.Trim()) == 0)
                    {
                        SpMessageBox.Show("用户已存在!", "用户管理");
                        return;
                    }
                }

                addoneuserintoDB();
            }
            else if (_opMode == Operation.Edit)//button 'Edit' has been clicked
            {
                //if (Login.Authority == LoginAuthority.SuperAdmin)
                //{
                //    if (adminCount > 1)
                //    {
                //        SpMessageBox.Show("只允许有一个管理员用户!");
                //        return;
                //    }
                //}

                UserInfo tmpUserInfo = new UserInfo();
                tmpUserInfo.UserID   = lsvUserInfo.SelectedItems[0].Tag.ToString();
                tmpUserInfo.UserName = txt_UserName.Text.Trim();
                tmpUserInfo.Password = txt_Password.Text.Trim();
                tmpUserInfo.Role     = (byte)((combo_Authority.Text.Trim() == "管理员") ? LoginAuthority.Administrator :
                                              ((combo_Authority.Text.Trim() == "超级管理员") ? LoginAuthority.SuperAdmin :
                                               ((combo_Authority.Text.Trim() == "操作员") ? LoginAuthority.Operator : LoginAuthority.Unkown)));

                if (tmpUserInfo.UpdateUserInfo())
                {
                    //if (Login.UserName != "MuberAdmin")
                    //{
                    //    Login.UserName = tmpUserInfo.UserName;
                    //    Login.Authority = (LoginAuthority)UserInfos.GetRoleByUser(tmpUserInfo.UserName);
                    //}

                    lsvUser_Load(tmpUserInfo.UserID);
                }
            }

            btnAdd.Enabled = (UserInfos.GetRoleByUser(Login.UserName) == (byte)LoginAuthority.Administrator || UserInfos.GetRoleByUser(Login.UserName) == (byte)LoginAuthority.SuperAdmin);

            _opMode = Operation.None;

            lsvUserInfo.Enabled = true;

            txt_UserName.Text             = String.Empty;
            txt_Password.Text             = String.Empty;
            txt_PasswordConfirm.Text      = String.Empty;
            combo_Authority.SelectedIndex = -1;

            btnAdd.Enabled     = true; //add
            btnEdit.Enabled    = true; //edit
            btnConfirm.Enabled = true; //confirm
            btnCancel.Enabled  = true; //cancel
            btnRemove.Enabled  = true; //delete

            btnAdd.BackgroundImage     = Properties.Resources._5_add;
            btnEdit.BackgroundImage    = Properties.Resources._4_edit;
            btnConfirm.BackgroundImage = Properties.Resources._5_ok;
            btnCancel.BackgroundImage  = Properties.Resources._5_cancel;
            btnRemove.BackgroundImage  = Properties.Resources._5_delete;
        }
        private void btnDownloadTags_Click(object sender, EventArgs e)
        {
            //MainForm.CheckComPorts();

            if (this.listView_CurrentOrder.Items.Count < 1)
            {
                SpMessageBox.Show("BOM清单为空,请重新查询订单.", "电子标签下发");
                return;
            }

            if (this.listView_CurrentOrder.Items.Count > MainForm.SupportedSerialPortNoList.Count)
            {
                SpMessageBox.Show("串口设备少于BOM清单数,请检查电子标签设备连接.", "电子标签下发");
                return;
            }


            int i;

            for (i = 0; i < this.listView_CurrentOrder.Items.Count; i++)
            {
                if (MainForm.SerialPortsList[i] != null)
                {
                    SerialPort sp = MainForm.SerialPortsList[i]; // find the right 实例化串口通讯类 from the list

                    foreach (var sptmp in MainForm.SerialPortsList)
                    {
                        if (int.Parse(System.Text.RegularExpressions.Regex.Replace(sptmp.PortName, @"[^0-9]+", "").Trim()) == int.Parse(CurrentOrderMaterialsList[i].MaterialSeq.ToString().Trim()) + 9)
                        { //匹配对应的串口, 根据物料的位置号, 获取对应的电子屏COM号,
                            sp = sptmp;
                            break;
                        }
                    }


                    if (!sp.IsOpen)
                    {
                        try
                        {
                            sp.Open();//打开串口
                        }
                        catch
                        {
                            SpMessageBox.Show("电子标签屏幕所对应的串口" + sp.PortName + "异常, 请检查串口连接.", "下发电子标签");
                        }
                    }

                    if (sp.IsOpen)
                    {
                        try
                        {
                            if (this.listView_CurrentOrder.Items[i].SubItems[1].Text.Trim().Length > 0)
                            {   // key codes
                                //packaging switch pictures cmd
                                byte[] cmds = { 0x5A, 0xA5, 0x07, 0x82, 0x00, 0x84, 0x5A, 0x01, 0x00, 0xFF };
                                cmds[9] = findLabelNoByMaterialNo(listView_CurrentOrder.Items[i].SubItems[1].Text.Trim()); // set the picture ID according to the 零件号
                                //cmds[9] = 0x04;  // for debug, will delete later

                                //packaging clear desc
                                byte[] clear = { 0x5A, 0xA5, 0x20, 0x82, 0x10, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
                                clear[5] = findLabelNoByMaterialNo(listView_CurrentOrder.Items[i].SubItems[1].Text.Trim());
                                //clear[5] = 0x40; // for debug, will delete later

                                //packaging  desc
                                byte[] desps = { 0x5A, 0xA5, 0x20, 0x82, 0x10, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
                                desps[5] = findLabelNoByMaterialNo(listView_CurrentOrder.Items[i].SubItems[1].Text.Trim());
                                desps[5] = 0x40; // for debug, will delete later

                                byte[] byteArray = System.Text.Encoding.ASCII.GetBytes(this.listView_CurrentOrder.Items[i].SubItems[1].Text.Trim());

                                byte[] byteArray1 = System.Text.Encoding.Default.GetBytes(this.listView_CurrentOrder.Items[i].SubItems[1].Text.Trim());

                                for (int j = 0; j < byteArray.Length; j++)
                                {
                                    desps[6 + j] = byteArray[j];
                                }


                                byte[] readbuffer = new byte[50];

                                try
                                {
                                    sp.Write(cmds, 0, cmds.Length);//发送切换picture指令
                                    System.Threading.Thread.Sleep(50);
                                    //sp.Read(readbuffer, 0, 20);  //接收串口返回消息
                                }
                                catch (Exception ex)
                                {
                                    SpMessageBox.Show(sp.PortName + "告警:" + ex.Message, "下发电子标签");
                                }
                                //Array.Clear(readbuffer, 0 , 50);
                                //sp.Write(clear, 0, clear.Length);//clear零件号描述 的指令
                                //sp.Read(readbuffer, 0, 20);

                                //Array.Clear(readbuffer, 0, 50);
                                //sp.Write(desps, 0, desps.Length);//发送更新零件号描述 指令
                                //sp.Read(readbuffer, 0, 20);

                                //LogerHelper.ToLog(this.listView_CurrentOrder.Items[i].SubItems[1].ToString() + "|" + "10" + " to " + sp.PortName, true);
                                LogerHelper.ToLog(desps + "|" + "10" + " to " + sp.PortName, true);

                                //if (i == 3)
                                //{
                                //    break;
                                //}
                            }
                        }
                        catch (Exception ex)
                        {
                            SpMessageBox.Show(sp.PortName + "告警:" + ex.Message, "下发电子标签");
                        }
                        sp.Close();
                    }
                }
            }

            if (i >= this.listView_CurrentOrder.Items.Count)
            {
                ShowLoginTip("电子标签下发成功.");

                // start the timer to detect the material box usages/consumption
                MainForm.timer_ReadSensors.AutoReset = true; //设置是执行一次(false)还是一直执行(true);
                MainForm.timer_ReadSensors.Enabled   = true; //是否执行System.Timers.Timer.Elapsed事件;
                MainForm.ModubusReadCounter          = 0;
                MainForm.TimerFinished = true;
                //MainForm.SensorsValues = new byte[8]; //切线之前,默认认为货架上的物料被清理干净了
            }
        }