コード例 #1
0
        private void frmMain_Load(object sender, EventArgs e)
        {
            #region Xet Role
            //quyen admin
            if (GlobalVariable.userId == 1)
            {
                navBarMain.ActiveGroup = navBarGroupCategories;//cho hien thi group nao khi bat len

                barbtnScale.Enabled       = false;
                barBtnPrintLables.Enabled = false;

                //tat navbarItem
                navBarItemBookOrder.Enabled = true;
                navBarItemMixing.Enabled    = true;
                navBarItemIncoming.Enabled  = true;
                navBarItemCrush.Enabled     = true;

                GlobalVariable.importOrder = GlobalVariable.importMixing = GlobalVariable.importIncoming = GlobalVariable.importCrush = false;
            }
            else
            {
                navBarMain.ActiveGroup = navBarGroupStation;

                //check Roe
                DataTable _data = DbOperatorRole.Instance.GetOperatorRole(GlobalVariable.userId.ToString());
                if (_data.Rows.Count > 0)
                {
                    GlobalVariable.importOrder = Convert.ToBoolean(_data.Rows[0]["booking"].ToString().Split('|')[0]);


                    GlobalVariable.importMixing = Convert.ToBoolean(_data.Rows[0]["mixing"].ToString().Split('|')[0]);


                    GlobalVariable.importIncoming = Convert.ToBoolean(_data.Rows[0]["incoming"].ToString().Split('|')[0]);


                    GlobalVariable.importCrush = Convert.ToBoolean(_data.Rows[0]["crushing"].ToString().Split('|')[0]);

                    GlobalVariable.print  = Convert.ToBoolean(_data.Rows[0]["crushing"].ToString().Split('|')[1]);
                    GlobalVariable.scales = Convert.ToBoolean(_data.Rows[0]["crushing"].ToString().Split('|')[2]);

                    if (GlobalVariable.print)
                    {
                        barBtnPrintLables.Enabled = true;
                    }
                    else
                    {
                        barBtnPrintLables.Enabled = false;
                    }

                    if (GlobalVariable.scales)
                    {
                        barbtnScale.Enabled = true;
                    }
                    else
                    {
                        barbtnScale.Enabled = false;
                    }
                }

                navBarItemShifts.Enabled      = false;
                navBarItemLossType.Enabled    = false;
                navBarItemOperator.Enabled    = false;
                navBarItemOtherSource.Enabled = false;
                navBarItemReason.Enabled      = false;

                navBarItemAddNewUser.Enabled = false;
                navBarItemDatabase.Enabled   = false;
            }
            #endregion

            //dang ky scale
            _ScaleHelper = new ScaleHelper()
            {
                IPServer     = "192.168.1.236",
                PortServer   = 23,
                _Value       = 0,
                isAllowScale = true
            };
            _ScaleHelper.DataChanged += (s, o) => {
                value = Math.Round(Convert.ToDouble(o.ToString()), 3);                         //get khoi  lượng từ class cân
            };
            Task.Factory.StartNew(new Action(() => _ScaleHelper.ReadData()));                  //cho chạy method cân

            GlobalVariable.myEvent.ShowMixingEditorChanged += MyEvent_ShowMixingEditorChanged; //đăng ký event để MixingEditor
        }