Exemplo n.º 1
0
        private void BtnWriteCard_Click(object sender, EventArgs e)
        {
            this._LastCard = GetCardModel(true, out string strErrMessage);
            if (this._LastCard == null)
            {
                CMessageBox.ShowError(strErrMessage, Config.DialogTitle);
                return;
            }

            if (CardConfiger.GetInstance().Switch.Equals(ConfigerBase.ESwitch.CLOSE))
            {
                if (MessageBox.Show("制卡串口当前已关闭,请先开启后再重试,确定现在开启吗?", Config.DialogTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                {
                    return;
                }
                CardConfiger.GetInstance().Start(RunVariable.CurrentSetting.WriteComProperty);
            }
            else
            {
                if (MessageBox.Show("确定要把当前数据写入卡吗?", Config.DialogTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                {
                    return;
                }
            }

            //先查询卡片,看是否已经存在数据库中,置写卡标志为1
            _WriteFlag = true;
            if (!CardConfiger.GetInstance().ReadCard(out strErrMessage))
            {
                CMessageBox.ShowError(string.Format("读卡失败,错误如下:\r\n{0}", strErrMessage), Config.DialogTitle);
                _WriteFlag = false;
            }
        }
Exemplo n.º 2
0
        protected override void BtnOK_Click(object sender, EventArgs e)
        {
            //验证逻辑
            string strOldPassword        = txtOldPassword.Text;
            string strNewPassword        = txtNewPassword.Text;
            string strNewConfirmPassword = txtNewConfirmPassword.Text;

            if (strOldPassword.Equals("") || strNewPassword.Equals("") || strNewConfirmPassword.Equals(""))
            {
                CMessageBox.ShowError("旧密码、新密码和确认密码都必须填写!", Config.DialogTitle);
                txtOldPassword.Focus();
                return;
            }
            if (!strNewPassword.Equals(strNewConfirmPassword))
            {
                CMessageBox.ShowError("新密码和确认密码不一致,请重新输入!", Config.DialogTitle);
                txtNewPassword.Focus();
                return;
            }

            CardManage.IDAL.IUserInfo objUser = CardManage.DALFactory.DALFactory.UserInfo();
            bool bIfSucc = objUser.ChangePassword(RunVariable.CurrentUserInfo.ID, Functions.Md5_32(strOldPassword), Functions.Md5_32(strNewPassword), out string strErrorInfo);

            if (!bIfSucc)
            {
                CMessageBox.ShowError(string.Format("对不起,修改密码错误,错误如下:\r\n{0}!", strErrorInfo), Config.DialogTitle);
                return;
            }
            CMessageBox.ShowSucc("恭喜您,密码修改成功!", Config.DialogTitle);
            this.DialogResult = DialogResult.OK;
        }
Exemplo n.º 3
0
        protected override void BtnOK_Click(object sender, EventArgs e)
        {
            //验证逻辑
            string strUserName = txtUserName.Text.Trim();
            string strPassword = txtPassword.Text.Trim();

            if (strUserName.Equals(""))
            {
                CMessageBox.ShowError("请输入用户名!", Config.DialogTitle);
                return;
            }

            IUserInfo objUser = DALFactory.DALFactory.UserInfo();
            int       iUserID = objUser.Login(strUserName, Functions.Md5_32(strPassword), out string strErrorInfo);

            if (iUserID <= 0)
            {
                CMessageBox.ShowError("输入的用户名或密码错误,请重新输入!", Config.DialogTitle);
                return;
            }
            RunVariable.CurrentUserInfo = objUser.GetModel(iUserID);
            if (RunVariable.CurrentUserInfo == null)
            {
                CMessageBox.ShowError(string.Format("无法找到编号为{0}的用户!", iUserID), Config.DialogTitle);
                return;
            }
            //保存用户名到临时文件
            Manager.GetInstance().SaveUserName(strUserName);
            this.DialogResult = DialogResult.OK;
        }
Exemplo n.º 4
0
        /// <summary>
        /// 回调方法-配置器当扇区重置返回时
        /// </summary>
        private void SelChsForm_OnChsCleanReponse(uint iCardNo, string strErrInfo)
        {
            if (string.IsNullOrEmpty(strErrInfo))
            {
                try
                {
                    this.Invoke(new EventHandler(delegate
                    {
                        //CMessageBox.ShowSucc(string.Format("恭喜您,扇区重置成功!"), Config.DialogTitle);
                        //字体颜色恢复默认
                        rbList[_rbInt].ForeColor = Color.Black;
                        _ChsCleanList.Remove(_rbInt);
                        btnChsClean.Text = "扇区选择";

                        //删除数据库卡片数据
                        IDAL.ICard objDAL = DALFactory.DALFactory.Card();
                        IList <CardManage.Model.Card> CleanCard = objDAL.GetListByWhere(1, string.Format("cardno = {0}", iCardNo));
                        if (CleanCard.Count > 0 && !objDAL.Delete(CleanCard[0].ID))
                        {
                            CMessageBox.ShowError(string.Format("恭喜您,扇区重置成功,但是删除数据库卡片数据失败!"), Config.DialogTitle);
                            return;
                        }

                        CMessageBox.ShowSucc(string.Format("恭喜您,扇区重置和保存卡片数据到数据库都成功!"), Config.DialogTitle);
                    }));
                }
                catch { }
            }
            else
            {
                CMessageBox.ShowError(string.Format("操作失败,错误原因如下:\r\n{0}", strErrInfo), Config.DialogTitle);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// 创建选择的数据
        /// </summary>
        private void DeleteSelectedData(object state)
        {
            bool   bIfSucc      = false;
            string strErrMessag = "未知错误";

            SetButtonEnabled(false);
            try
            {
                if (this._FormIfClose)
                {
                    return;
                }
                Model.SelecedTreeNodeData objSelecedTreeNodeData = (Model.SelecedTreeNodeData)state;
                if (!(objSelecedTreeNodeData.SelectedDataList == null || objSelecedTreeNodeData.SelectedDataList.Count == 0))
                {
                    IDAL.IBuilding objDalBuilding = DALFactory.DALFactory.Building();
                    IDAL.ISys      objDalSys      = DALFactory.DALFactory.Sys();
                    foreach (Model.NodeData objData in objSelecedTreeNodeData.SelectedDataList)
                    {
                        if (objData.Flag.Equals(-1))
                        {
                            //全部
                            bIfSucc = objDalSys.DeleteData(0);
                        }
                        else if (objData.Flag >= 0 && objData.Flag <= 3)
                        {
                            bool bSucc = objDalBuilding.Delete(objData.ID);
                            if (bSucc)
                            {
                                bIfSucc = bSucc;
                            }
                        }
                    }
                }
                if (bIfSucc)
                {
                    InitTree();
                }
            }
            catch (Exception err)
            {
                strErrMessag = err.Message;
            }
            if (bIfSucc)
            {
                RefreshTreeByThread();
            }
            SetButtonEnabled(true);
            if (bIfSucc)
            {
                CMessageBox.ShowSucc("恭喜您,删除成功!", Config.DialogTitle);
                //当建筑信息删除时,通知其他已开启的树
                Manager.GetInstance().BuildingDataChangeNotice();
            }
            else
            {
                CMessageBox.ShowError(string.Format("对不起,删除失败,错误原因:\r\n{0}", strErrMessag), Config.DialogTitle);
            }
        }
Exemplo n.º 6
0
        private void BtnReadCard_Click(object sender, EventArgs e)
        {
            if (_CurrentAction.Equals(EAction.Edit))
            {
                //修改资料
                this._LastCard = GetCardModel(false, out string strErrMessage);
                if (this._LastCard == null)
                {
                    CMessageBox.ShowError(strErrMessage, Config.DialogTitle);
                    return;
                }

                if (MessageBox.Show("确定要保存修改吗?", Config.DialogTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                {
                    return;
                }
                IDAL.ICard objDAL  = DALFactory.DALFactory.Card();
                bool       bIfSucc = objDAL.Update(this._LastCard, out string strErrorInfo);
                if (bIfSucc)
                {
                    CMessageBox.ShowError(string.Format("恭喜您,保存成功!"), Config.DialogTitle);
                }
                else
                {
                    CMessageBox.ShowError(string.Format("保存失败,错误如下:\r\n{0}", strErrorInfo), Config.DialogTitle);
                }
            }
            else
            {
                //读卡
                if (CardConfiger.GetInstance().Switch.Equals(ConfigerBase.ESwitch.CLOSE))
                {
                    if (MessageBox.Show("制卡串口当前已关闭,请先开启后再重试,确定现在开启吗?", Config.DialogTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                    {
                        return;
                    }
                    CardConfiger.GetInstance().Start(RunVariable.CurrentSetting.WriteComProperty);
                }
                else
                {
                    if (MessageBox.Show("确定现在读卡吗?", Config.DialogTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                    {
                        return;
                    }
                    if (!CardConfiger.GetInstance().ReadCard(out string strErrMessage))
                    {
                        CMessageBox.ShowError(string.Format("读卡失败,错误如下:\r\n{0}", strErrMessage), Config.DialogTitle);
                    }
                }
            }
        }
Exemplo n.º 7
0
        protected override void BtnOK_Click(object sender, EventArgs e)
        {
            string strDeviceAddress          = txtDeviceAddress.Text.Trim();
            string strOringinalDeviceAddress = strDeviceAddress;

            if (strDeviceAddress.Equals(""))
            {
                txtDeviceAddress.Focus();
                CMessageBox.ShowError(string.Format("设备地址必须填写,且必须是16进制字符!"), Config.DialogTitle);
                return;
            }
            if (strDeviceAddress.Length > 8)
            {
                strDeviceAddress = strDeviceAddress.Substring(0, 8);
            }
            strDeviceAddress = strDeviceAddress.PadRight(8, '0');

            if (!CheckDeviceAddress(strDeviceAddress))
            {
                txtDeviceAddress.Focus();
                CMessageBox.ShowError(string.Format("设备地址必须填写,且必须是16进制字符!"), Config.DialogTitle);
                return;
            }
#if DEBUG
            _CurrentPingNum = 1;
#else
            this._CurrentPingNum++;
#endif
            if (this._CurrentPingNum < 0 || this._CurrentPingNum > 9999)
            {
                this._CurrentPingNum = 0;
            }
            DeviceAddress objDeviceAddress = new DeviceAddress()
            {
                DeviceNo         = strDeviceAddress,
                OriginalDeviceNo = strOringinalDeviceAddress,
                PingNum          = this._CurrentPingNum,
                DeviceType       = Convert.ToInt32(((ComboBoxItem)cbDeviceType.SelectedItem).Value)
            };

            if (!CardMonitor.GetInstance().Ping(objDeviceAddress, out string strErrInfo))
            {
                Tools.CMessageBox.ShowError(string.Format("对不起,ping设备失败,错误原因:\r\n{0}!", strErrInfo), Config.DialogTitle);
            }
            else
            {
                //浅表副本 复制给定时任务 用于失败重试
                _LastDeviceAddress = (DeviceAddress)objDeviceAddress.Clone();
                timer1.Enabled     = true;
            }
        }
Exemplo n.º 8
0
        protected override void BtnOK_Click(object sender, EventArgs e)
        {
            int    iFlag       = cbFlag.SelectedIndex - 1;
            string strUserName = txtUserName.Text.Trim();
            string strPassword = txtPassword.Text.Trim();
            string strMemo     = txtMemo.Text.Trim();

            if (iFlag == -1 || strUserName.Equals("") || strPassword.Equals(""))
            {
                CMessageBox.ShowError("角色、用户名和密码都必须输入!", Config.DialogTitle);
                return;
            }

            if (MessageBox.Show("确定要保存吗?", Config.DialogTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
            {
                return;
            }

            Model.UserInfo objModel = new Model.UserInfo()
            {
                Flag     = iFlag,
                ID       = this._CurrentID,
                UserName = strUserName,
                UserPwd  = (this._CurrentAction.Equals(EAction.Create)) ? Functions.Md5_32(strPassword) : ((strPassword.Equals(this._OriginalPassword) ? this._OriginalPassword : Functions.Md5_32(strPassword))),
                Memo     = strMemo
            };
            string strErrorInfo = "";

            IDAL.IUserInfo objDAL = DALFactory.DALFactory.UserInfo();
            if (this._CurrentAction.Equals(EAction.Create))
            {
                int iNewID = objDAL.Add(objModel, out strErrorInfo);
                if (iNewID <= 0)
                {
                    CMessageBox.ShowError(string.Format("创建用户失败,错误如下:\r\n{0}!", strErrorInfo), Config.DialogTitle);
                    return;
                }
            }
            else
            {
                bool bIfSucc = objDAL.Update(objModel, out strErrorInfo);
                if (!bIfSucc)
                {
                    CMessageBox.ShowError(string.Format("修改用户失败,错误如下:\r\n{0}!", strErrorInfo), Config.DialogTitle);
                    return;
                }
            }
            this.DialogResult = DialogResult.OK;
        }
Exemplo n.º 9
0
        /// <summary>
        /// 扇区重置
        /// </summary>
        private void BtnChsClean_Click(object sender, EventArgs e)
        {
            string strErrMessage = "";

            if (btnChsClean.Text == "扇区选择")
            {
                if (MessageBox.Show("更改写入扇区可能导致扇区混乱,确定更改写入扇区吗?", Config.DialogTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                {
                    return;
                }
                //更改写入扇区,并更改配置文件
                RunVariable.CurrentSetting.OtherSetting.Chs = _rbInt;

                if (!SysConfiger.SaveSetting(RunVariable.CurrentSetting, RunVariable.IniPathAndFileName, out strErrMessage))
                {
                    CMessageBox.ShowError(string.Format("对不起,保存配置失败,错误如下:\r\n{0}", strErrMessage), Config.DialogTitle);
                }
                else
                {
                    Manager.GetInstance().SettingChangeNotice();
                    CMessageBox.ShowSucc(string.Format("恭喜您,保存配置成功!"), Config.DialogTitle);
                }
                this.btnCancel.PerformClick();
            }
            else
            {
                if (CardConfiger.GetInstance().Switch.Equals(ConfigerBase.ESwitch.CLOSE))
                {
                    if (MessageBox.Show("制卡串口当前已关闭,请先开启后再重试,确定现在开启吗?", Config.DialogTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                    {
                        return;
                    }
                    CardConfiger.GetInstance().Start(RunVariable.CurrentSetting.WriteComProperty);
                }
                else
                {
                    if (MessageBox.Show("当前操作会清除扇区所有数据\n确定现在重置扇区吗?", Config.DialogTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No)
                    {
                        return;
                    }

                    if (!CardConfiger.GetInstance().ChsClean(_rbInt.ToString(), out strErrMessage))
                    {
                        CMessageBox.ShowError(string.Format("重置扇区失败,错误如下:\r\n{0}", strErrMessage), Config.DialogTitle);
                    }
                }
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// 删除数据
        /// </summary>
        /// <param name="selectedItems">当前选择的所有项</param>
        protected override void OnDelete(ListView.SelectedListViewItemCollection selectedItems)
        {
            if (MessageBox.Show(string.Format("删除{0}数据的同时会把下属的建筑数据以及卡片信息一起删除,请慎重选择,确定要删除当前选择的{1}数据吗?", this._DataTypeName, this._DataTypeName), Config.DialogTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
            {
                return;
            }

            int iSuccNum  = 0;
            int iFaultNum = 0;

            foreach (ListViewItem selectedItem in selectedItems)
            {
                Building       objModel = (Building)selectedItem.Tag;
                IDAL.IBuilding objDal   = DALFactory.DALFactory.Building();
                if (objDal.Delete(objModel.ID))
                {
                    iSuccNum++;
                }
                else
                {
                    iFaultNum++;
                }
            }

            if (iSuccNum == 0)
            {
                CMessageBox.ShowError("对不起,删除失败!", Config.DialogTitle);
            }
            else if (iFaultNum == 0)
            {
                CMessageBox.ShowSucc("恭喜您,删除成功!", Config.DialogTitle);
            }
            else
            {
                CMessageBox.ShowSucc(string.Format("{0}个删除成功,{1}个删除失败", iSuccNum, iFaultNum), Config.DialogTitle);
            }
            if (iSuccNum > 0)
            {
                //重新刷新列表
                BindLVData(0, this.CurrentSqlWhere);
                //当建筑信息删除时,通知其他已开启的树
                Manager.GetInstance().BuildingDataChangeNotice();
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// 删除数据
        /// </summary>
        /// <param name="selectedItems">当前选择的行项</param>
        protected override void OnDelete(ListView.SelectedListViewItemCollection selectedItems)
        {
            if (MessageBox.Show(string.Format("确定要删除当前选择的卡片信息吗?"), Config.DialogTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
            {
                return;
            }

            int iSuccNum  = 0;
            int iFaultNum = 0;

            foreach (ListViewItem selectedItem in selectedItems)
            {
                Card       objModel = (Card)selectedItem.Tag;
                IDAL.ICard objDal   = DALFactory.DALFactory.Card();
                if (objDal.Delete(objModel.ID))
                {
                    iSuccNum++;
                }
                else
                {
                    iFaultNum++;
                }
            }

            if (iSuccNum > 0)
            {
                //重新刷新列表
                BindLVData(0, this.CurrentSqlWhere);
            }

            if (iSuccNum == 0)
            {
                CMessageBox.ShowError("对不起,删除失败!", Config.DialogTitle);
            }
            else if (iFaultNum == 0)
            {
                CMessageBox.ShowSucc("恭喜您,删除成功!", Config.DialogTitle);
            }
            else
            {
                CMessageBox.ShowSucc(string.Format("{0}个删除成功,{1}个删除失败", iSuccNum, iFaultNum), Config.DialogTitle);
            }
        }
Exemplo n.º 12
0
        protected override void BtnOK_Click(object sender, EventArgs e)
        {
            string strDBIP         = Functions.FormatString(txtDBIP.Text);
            string strUserName     = Functions.FormatString(txtUserName.Text);
            string strUserPassword = Functions.FormatString(txtUserPassword.Text);

            //地址
            if (string.IsNullOrEmpty(strDBIP) || strDBIP.Equals(""))
            {
                txtDBIP.Focus();
                CMessageBox.ShowError(string.Format("请输入数据库地址!"), Config.DialogTitle);
                return;
            }
            //名称
            if (string.IsNullOrEmpty(strUserName) || strUserName.Equals(""))
            {
                txtUserName.Focus();
                CMessageBox.ShowError(string.Format("请输入数据库用户名!"), Config.DialogTitle);
                return;
            }

            DBLinkTestForm objModal = new DBLinkTestForm(string.Format("SERVER={0};Port={1};User ID={2};Password={3};Charset={4};Database=mysql;allow user variables=true", strDBIP, "3308", strUserName, strUserPassword, System.Text.Encoding.Default.HeaderName.ToString()));

            if (objModal.ShowDialog() == DialogResult.OK)
            {
                _DBSetting = new DBSetting()
                {
                    DB_IP       = strDBIP,
                    DB_User     = strUserName,
                    DB_Password = strUserPassword
                };
                this.DialogResult = DialogResult.OK;
            }
            else if (objModal.ShowDialog() == DialogResult.No)
            {
                CMessageBox.ShowError(string.Format("目的服务器配置错误,原因可能是数据库未安装或则用户名密码错误,请重新设置和排查!"), Config.DialogTitle);
            }
            else
            {
                Application.Exit();
            }
        }
Exemplo n.º 13
0
        private void BtnCheckDBSetting_Click(object sender, EventArgs e)
        {
            DBSetting objDBSetting = GetSettingFromUI();

            if (!CheckDBSettings(objDBSetting, out string strErrInfo))
            {
                CMessageBox.ShowError(string.Format("数据库配置错误,错误如下:\r\n{0}", strErrInfo), Config.DialogTitle);
                return;
            }
            DBLinkTestForm objModal = new DBLinkTestForm(string.Format("SERVER={0};Port={1};User ID={2};Password={3};Charset={4};Database={5};allow user variables=true", objDBSetting.DB_IP, "3308", objDBSetting.DB_User, objDBSetting.DB_Password, System.Text.Encoding.Default.HeaderName.ToString(), objDBSetting.DB_Name));

            if (objModal.ShowDialog() == DialogResult.OK)
            {
                CMessageBox.ShowSucc(string.Format("恭喜您,数据库连接成功!"), Config.DialogTitle);
            }
            else if (objModal.ShowDialog() == DialogResult.No)
            {
                CMessageBox.ShowError(string.Format("对不起,数据库连接失败!请重新配置软件参数!"), Config.DialogTitle);
                File.Delete(RunVariable.IniPathAndFileName);
            }
        }
Exemplo n.º 14
0
        private void OpenForm(CardManage.Model.Menu objMenuInfo)
        {
            if (objMenuInfo == null || string.IsNullOrEmpty(objMenuInfo.FormName))
            {
                return;
            }

            try
            {
                FormBase objForm;
                string   strFormName = string.Format("{0}Form", objMenuInfo.Name);
                objForm = GetFormByFormName(strFormName);
                if (objForm != null)
                {
                    if (objForm.WindowState == FormWindowState.Minimized || objForm.WindowState == FormWindowState.Normal)
                    {
                        objForm.WindowState = FormWindowState.Maximized;
                    }
                    objForm.Activate();
                }
                else
                {
                    objForm      = (FormBase)Activator.CreateInstance(Type.GetType(string.Format("CardManage.Forms.{0}", objMenuInfo.FormName)), new object[] { objMenuInfo.Title, objMenuInfo.IsModal, RunVariable.CurrentUserInfo, objMenuInfo.WindowSize, objMenuInfo.Flag });
                    objForm.Name = strFormName;
                    if (objMenuInfo.IsModal)
                    {
                        objForm.ShowDialog();
                    }
                    else
                    {
                        objForm.MdiParent = this._MainForm;
                        objForm.Show();
                    }
                }
            }
            catch (Exception err)
            {
                CMessageBox.ShowError(string.Format("出现异常,异常信息如下:{0}", err.Message), Config.DialogTitle);
            }
        }
Exemplo n.º 15
0
        /// <summary>
        /// 创建全部数据
        /// </summary>
        private void DeleteAllData(object state)
        {
            bool   bIfSucc      = false;
            string strErrMessag = "未知错误";

            SetButtonEnabled(false);
            try
            {
                if (this._FormIfClose)
                {
                    return;
                }
                IDAL.ISys objDal = DALFactory.DALFactory.Sys();
                bIfSucc = objDal.DeleteData(0);
                if (bIfSucc)
                {
                    InitTree();
                }
            }
            catch (Exception err)
            {
                strErrMessag = err.Message;
            }
            if (bIfSucc)
            {
                RefreshTreeByThread();
            }
            //SetButtonEnabled(true);
            if (bIfSucc)
            {
                CMessageBox.ShowSucc("恭喜您,删除成功!", Config.DialogTitle);
                //当建筑信息删除时,通知其他已开启的树
                //Manager.GetInstance().BuildingDataChangeNotice();
            }
            else
            {
                CMessageBox.ShowError(string.Format("对不起,删除失败,错误原因:\r\n{0}", strErrMessag), Config.DialogTitle);
            }
        }
Exemplo n.º 16
0
 /// <summary>
 /// 回调方法-配置器当写卡返回时
 /// </summary>
 private void CardViewForm_OnWriteCardReponse(uint iCardNo, string strErrInfo)
 {
     if (this._LastCard == null)
     {
         return;
     }
     if (iCardNo != uint.MaxValue && string.IsNullOrEmpty(strErrInfo))
     {
         try
         {
             this.Invoke(new EventHandler(delegate
             {
                 txtCardNo.Text        = iCardNo.ToString();
                 this._LastCard.CardNo = iCardNo;
                 //保存数据库
                 IDAL.ICard objDAL = DALFactory.DALFactory.Card();
                 if (!_UpdateFlag)
                 {
                     int iNewID = objDAL.Add(this._LastCard, out string strErrorInfo);
                     if (iNewID <= 0)
                     {
                         CMessageBox.ShowError(string.Format("恭喜您,写卡成功,但是保存卡片数据到数据库失败,错误如下:\r\n{0}!", strErrorInfo), Config.DialogTitle);
                         return;
                     }
                 }
                 else
                 {
                     bool bIfSucc = objDAL.Update(this._LastCard, out string strErrorInfo);
                     if (!bIfSucc)
                     {
                         CMessageBox.ShowError(string.Format("恭喜您,写卡成功,但是保存卡片数据到数据库失败,错误如下:\r\n{0}!", strErrorInfo), Config.DialogTitle);
                         return;
                     }
                 }
                 Manager.GetInstance().CardDataChangeNotice();
                 CMessageBox.ShowSucc(string.Format("恭喜您,写卡和保存卡片数据到数据库都成功!"), Config.DialogTitle);
             }));
         }
Exemplo n.º 17
0
        private void TsbSaveDebugContent_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFileDialog1 = new SaveFileDialog()
            {
                Filter           = " txt files(*.txt)|*.txt", //设置文件类型
                RestoreDirectory = true                       //保存对话框是否记忆上次打开的目录
            };

            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    StreamWriter aWriter = new StreamWriter(saveFileDialog1.OpenFile());
                    aWriter.Write(Regex.Replace(this.tbxComunicateData.Text, "\n", "\r\n", RegexOptions.IgnoreCase));
                    aWriter.Close();
                    aWriter = null;
                    CMessageBox.ShowSucc("保存文件成功!", Config.DialogTitle);
                }
                catch (Exception err)
                {
                    CMessageBox.ShowError(string.Format("保存文件失败,错误原因:{0}", err), Config.DialogTitle);
                }
            }
        }
Exemplo n.º 18
0
        protected override void BtnOK_Click(object sender, EventArgs e)
        {
            string strSyncTimePL = txtSyncPL.Text.Trim();

            if (string.IsNullOrEmpty(strSyncTimePL) || !Functions.IsInt(strSyncTimePL))
            {
                tabControl1.SelectedTab = tabPage4;
                txtSyncPL.Focus();
                CMessageBox.ShowError(string.Format("时间同步频率不能为空,且必须为大于等于1的整数"), Config.DialogTitle);
                return;
            }
            else
            {
                int iSyncTimePL = Convert.ToInt32(strSyncTimePL);
                if (iSyncTimePL < 1)
                {
                    tabControl1.SelectedTab = tabPage4;
                    txtSyncPL.Focus();
                    CMessageBox.ShowError(string.Format("时间同步频率必须为大于等于1的整数"), Config.DialogTitle);
                    return;
                }
            }

            string strChs = tBChs.Text.Trim();

            if (string.IsNullOrEmpty(strChs) || !Functions.IsInt(strChs))
            {
                tabControl1.SelectedTab = tabPage4;
                tBChs.Focus();
                CMessageBox.ShowError(string.Format("默认扇区不能为空,且必须为大于0小于16的整数"), Config.DialogTitle);
                return;
            }
            else
            {
                int iChs = Convert.ToInt32(strChs);
                if (iChs < 1)
                {
                    tabControl1.SelectedTab = tabPage4;
                    txtSyncPL.Focus();
                    CMessageBox.ShowError(string.Format("默认扇区必须为大于0小于16的整数"), Config.DialogTitle);
                    return;
                }
            }

            //验证逻辑
            Setting objSetting = GetSettingFromUI();

            if (!SysConfiger.CheckSettings(objSetting, out string strErrInfo))
            {
                if (strErrInfo.IndexOf("数据库") >= 0 && strErrInfo.IndexOf("制卡") < 0 && strErrInfo.IndexOf("监控") < 0)
                {
                    //只有数据库配置错误
                    tabControl1.SelectedTab = tabPage1;
                }
                else if (strErrInfo.IndexOf("制卡") >= 0 && strErrInfo.IndexOf("数据库") < 0 && strErrInfo.IndexOf("监控") < 0)
                {
                    //只有写卡配置错误
                    tabControl1.SelectedTab = tabPage2;
                }
                else if (strErrInfo.IndexOf("监控") >= 0 && strErrInfo.IndexOf("数据库") < 0 && strErrInfo.IndexOf("制卡") < 0)
                {
                    //只有写卡配置错误
                    tabControl1.SelectedTab = tabPage3;
                }
                CMessageBox.ShowError(string.Format("配置错误,错误如下:\r\n{0}", strErrInfo), Config.DialogTitle);
            }
            else
            {
                if (!SysConfiger.SaveSetting(objSetting, RunVariable.IniPathAndFileName, out strErrInfo))
                {
                    CMessageBox.ShowError(string.Format("对不起,保存配置失败,错误如下:\r\n{0}", strErrInfo), Config.DialogTitle);
                }
                else
                {
                    if (this._IfLoginBefore)
                    {
                        CMessageBox.ShowSucc(string.Format("恭喜您,保存配置成功!"), Config.DialogTitle);
                    }
                    else
                    {
                        Manager.GetInstance().SettingChangeNotice();
                        CMessageBox.ShowSucc(string.Format("恭喜您,保存配置成功,要使数据库的配置生效,必须重新启动系统,数据库以外的配置可即刻生效!"), Config.DialogTitle);
                    }
                    this.DialogResult = DialogResult.OK;
                }
            }
        }
Exemplo n.º 19
0
        private void MDIParent1_Load(object sender, EventArgs e)
        {
            //总管理器
            Manager.GetInstance().OnSettingChange += new Manager.SettingChangeHandler(OnSettingChange);

            //配置器
            //CardConfiger.GetInstance().OnNotice += new ConfigerBase.NoticeHandler(CardConfiger_OnNotice);
            CardConfiger.GetInstance().OnStartFault += new ConfigerBase.StartFaultHandler(CardConfiger_OnStartFault);
            CardConfiger.GetInstance().OnStartSucc  += new ConfigerBase.StartSuccHandler(CardConfiger_OnStartSucc);
            CardConfiger.GetInstance().OnStopFault  += new ConfigerBase.StopFaultHandler(CardConfiger_OnStopFault);
            CardConfiger.GetInstance().OnStopSucc   += new ConfigerBase.StopSuccHandler(CardConfiger_OnStopSucc);

            //监控器
            CardMonitor.GetInstance().OnStartFault += new ConfigerBase.StartFaultHandler(CardMonitor_OnStartFault);
            CardMonitor.GetInstance().OnStartSucc  += new ConfigerBase.StartSuccHandler(CardMonitor_OnStartSucc);
            CardMonitor.GetInstance().OnStopFault  += new ConfigerBase.StopFaultHandler(CardMonitor_OnStopFault);
            CardMonitor.GetInstance().OnStopSucc   += new ConfigerBase.StopSuccHandler(CardMonitor_OnStopSucc);


            this.Hide();
            //全局变量初始化
            //运行配置
            RunVariable.IfDebug = GetDebugStatus();//是否是调试模式,如果是调试模式则在已发送的命令输出区输出指令码

            RunVariable.IniPathAndFileName = string.Format("{0}\\{1}", Application.StartupPath, Config.IniFileName);
            string strErrInfo = "";

            bool         bIfLoop = true;
            DialogResult dResult;
            string       strErrMessage = "";

            //1.创建数据库或使用现有数据库
            //1.判断文件是否在
            if (!IOHelper.Exists(RunVariable.IniPathAndFileName))
            {
                dResult = MessageBox.Show("未找到数据库配置文件,进入系统前必须配置好数据库,如需新建数据库请按[是]键,使用现有的数据库请按[否]键,退出系统请按[取消]键?", Config.DialogTitle, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
                if (dResult == DialogResult.Yes)
                {
                    //创建数据库
                    DBServerSettingForm objModalDBServerForm = new DBServerSettingForm("数据库服务器配置", true, RunVariable.CurrentUserInfo, new WindowSize(365, 288));
                    dResult = objModalDBServerForm.ShowDialog();
                    if (dResult == DialogResult.OK)
                    {
                        //连接成功,创建数据库
                        DBSetting objDBSetting = objModalDBServerForm.GetDBSetting();
                        if (objDBSetting != null)
                        {
                            string    strSqlContent = Properties.Resources.db;
                            DBManager objDM         = new DBManager(objDBSetting.DB_IP, objDBSetting.DB_User, objDBSetting.DB_Password);
                            bool      bIfCanLink    = objDM.CheckCanLink();
                            if (bIfCanLink)
                            {
                                string strDBName = Config.DefaultDBName;
                                if (!objDM.IsExists(strDBName))
                                {
                                    bool bIfCreateSucc = objDM.CreateBySql(strDBName, strSqlContent, out strErrMessage);
                                    if (!bIfCreateSucc)
                                    {
                                        //退出系统
                                        CMessageBox.ShowError(string.Format("数据库创建失败,请重新开启软件重试,错误原因\r\n{0}", strErrMessage), Config.DialogTitle);
                                        bIfLoop = false;
                                        Application.Exit();
                                    }
                                    else
                                    {
                                        CMessageBox.ShowSucc("恭喜你,数据库创建成功!", Config.DialogTitle);
                                    }
                                }
                                Model.Setting objAllSetting = new Setting();
                                //数据库
                                objAllSetting.DBSetting             = new DBSetting();
                                objAllSetting.DBSetting.DB_IP       = objDBSetting.DB_IP;
                                objAllSetting.DBSetting.DB_Name     = strDBName;
                                objAllSetting.DBSetting.DB_User     = objDBSetting.DB_User;
                                objAllSetting.DBSetting.DB_Password = objDBSetting.DB_Password;
                                //制卡串口
                                objAllSetting.WriteComProperty          = new Classes.ComProperty();
                                objAllSetting.WriteComProperty.BaudRate = 9600;
                                objAllSetting.WriteComProperty.DataBits = 8;
                                objAllSetting.WriteComProperty.StopBits = System.IO.Ports.StopBits.One;
                                objAllSetting.WriteComProperty.Parity   = System.IO.Ports.Parity.None;
                                //监控串口
                                objAllSetting.MonitorComProperty          = new Classes.ComProperty();
                                objAllSetting.MonitorComProperty.BaudRate = 19200;
                                objAllSetting.MonitorComProperty.DataBits = 8;
                                objAllSetting.MonitorComProperty.StopBits = System.IO.Ports.StopBits.One;
                                objAllSetting.MonitorComProperty.Parity   = System.IO.Ports.Parity.None;
                                //其他配置
                                objAllSetting.OtherSetting            = new OtherSetting();
                                objAllSetting.OtherSetting.SyncTimePL = 10;
                                objAllSetting.OtherSetting.Chs        = 1;
                                objAllSetting.OtherSetting.SyncAuto   = 0;

                                SysConfiger.SaveSetting(objAllSetting, RunVariable.IniPathAndFileName, out strErrMessage);
                            }
                            else
                            {
                                //退出系统
                                CMessageBox.ShowError("数据库服务器连接失败,请重新开启软件重试!", Config.DialogTitle);
                                bIfLoop = false;
                                Application.Exit();
                            }
                        }
                        else
                        {
                            //退出系统
                            bIfLoop = false;
                            Application.Exit();
                        }
                    }
                    else
                    {
                        //退出系统
                        bIfLoop = false;
                        Application.Exit();
                    }
                }
                else if (dResult == DialogResult.No)
                {
                    //使用现有的数据库
                    //弹出配置串口
                    DBSettingForm objModalSysForm = new DBSettingForm("数据库设置", true, RunVariable.CurrentUserInfo, new WindowSize(382, 339));
                    if (objModalSysForm.ShowDialog() != DialogResult.OK)
                    {
                        bIfLoop = false;
                        Application.Exit();
                    }
                    else
                    {
                        bIfLoop = true;
                    }
                }
                else
                {
                    //退出系统
                    bIfLoop = false;
                    Application.Exit();
                }
            }

            //2.加载配置文件
            while (bIfLoop)
            {
                //2.配置文件载入验证
                RunVariable.CurrentSetting = SysConfiger.LoadSetting(RunVariable.IniPathAndFileName, out strErrInfo);
                if (RunVariable.CurrentSetting == null || !strErrInfo.Equals(""))
                {
                    CMessageBox.ShowError(string.Format("无法载入系统配置文件,错误信息如下:\r\n{0}", strErrInfo), Config.DialogTitle);
                    bIfLoop = false;
                    Application.Exit();
                }

                //3.数据库连接验证
                DBSetting objDb = RunVariable.CurrentSetting.DBSetting;

                string         strConnectStringTest = string.Format("SERVER={0};Port={1};User ID={2};Password={3};Charset={4};Database={5};allow user variables=true", objDb.DB_IP, "3308", objDb.DB_User, objDb.DB_Password, Encoding.Default.HeaderName.ToString(), objDb.DB_Name);
                string         strConnectStringReal = string.Format("SERVER={0};Port={1};User ID={2};Password={3};Charset={4};Database={5};allow user variables=true", objDb.DB_IP, "3308", objDb.DB_User, objDb.DB_Password, System.Text.Encoding.Default.HeaderName.ToString(), objDb.DB_Name);
                DBLinkTestForm objDBLinkModal       = new DBLinkTestForm(strConnectStringTest);
                if (objDBLinkModal.ShowDialog() == DialogResult.OK)
                {
                    //数据库连接成功
                    RunVariable.ConnectionString = strConnectStringReal;
                    CardManage.DBUtility.DbHelperSQL.connectionString = RunVariable.ConnectionString;
                    LoginForm objLoginForm = new LoginForm("用户登录", true, null, new Model.WindowSize(350, 260));
                    if (objLoginForm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        LayoutManager.GetInstance().InitLayout(this);
                        CardConfiger.GetInstance().Start(RunVariable.CurrentSetting.WriteComProperty);
                        CardMonitor.GetInstance().Start(RunVariable.CurrentSetting.MonitorComProperty);
                        CardMonitor.GetInstance().SetSyncTimePL(RunVariable.CurrentSetting.OtherSetting.SyncTimePL * 60);
                        CardMonitor.GetInstance().StartTask(RunVariable.CurrentSetting.OtherSetting.SyncAuto);
                        UpdateStatusDesc();
                        this.Show();
                        bIfLoop = false;
                    }
                    else
                    {
                        bIfLoop = false;
                        Application.Exit();
                    }
                }
                else if (objDBLinkModal.ShowDialog() == DialogResult.No)
                {
                    if (MessageBox.Show("数据库连接失败,需要配置好数据库信息才能进入系统,如需马上配置请按[是]键,退出系统请按[否]键?", Config.DialogTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        //弹出配置串口
                        DBSettingForm objModalSysForm = new DBSettingForm("数据库设置", true, RunVariable.CurrentUserInfo, new WindowSize(382, 339));
                        if (objModalSysForm.ShowDialog() != DialogResult.OK)
                        {
                            bIfLoop = false;
                            Application.Exit();
                        }
                    }
                    else
                    {
                        bIfLoop = false;
                        Application.Exit();
                    }
                }
                else
                {
                    bIfLoop = false;
                    Application.Exit();
                }
            }
        }
Exemplo n.º 20
0
        protected override void BtnOK_Click(object sender, EventArgs e)
        {
            int    iAreaID      = Convert.ToInt32(((Model.ComboBoxItem)cbArea.SelectedItem).Value);
            int    iBuildID     = Convert.ToInt32(((Model.ComboBoxItem)cbBuild.SelectedItem).Value);
            int    iUnitID      = Convert.ToInt32(((Model.ComboBoxItem)cbUnit.SelectedItem).Value);
            string strBeginCode = txtRoomCodeBegin.Text.Trim();
            string strEndCode   = txtRoomCodeEnd.Text.Trim();

            if (iAreaID <= 0)
            {
                CMessageBox.ShowError("请选择一个小区!", Config.DialogTitle);
                return;
            }
            if (iBuildID <= 0)
            {
                CMessageBox.ShowError("请选择一个楼栋!", Config.DialogTitle);
                return;
            }
            if (iUnitID <= 0)
            {
                CMessageBox.ShowError("请选择一个单元!", Config.DialogTitle);
                return;
            }

            if (strBeginCode.Equals("") || !Functions.IsInt(strBeginCode))
            {
                txtRoomCodeBegin.Focus();
                CMessageBox.ShowError(string.Format("请输入起始楼层房间编码,且范围必须是0~9999之间的整数!"), Config.DialogTitle);
                return;
            }

            int iBeginCode = Functions.FormatInt(strBeginCode);

            if (!(iBeginCode >= 0 && iBeginCode <= 9999))
            {
                txtRoomCodeBegin.Focus();
                CMessageBox.ShowError(string.Format("输入的起始楼层房间编码超出范围,取值范围是0~9999之间的整数!"), Config.DialogTitle);
                return;
            }

            if (strEndCode.Equals("") || !Functions.IsInt(strEndCode))
            {
                txtRoomCodeEnd.Focus();
                CMessageBox.ShowError(string.Format("请输入结束楼层房间编码,且范围必须是0~9999之间的整数!"), Config.DialogTitle);
                return;
            }

            int iEndCode = Functions.FormatInt(strEndCode);

            if (!(iEndCode >= 0 && iEndCode <= 9999))
            {
                txtRoomCodeEnd.Focus();
                CMessageBox.ShowError(string.Format("输入的结束楼层房间编码超出范围,取值范围是0~9999之间的整数!"), Config.DialogTitle);
                return;
            }

            if (iBeginCode >= iEndCode)
            {
                txtRoomCodeBegin.Focus();
                CMessageBox.ShowError(string.Format("输入的起始楼层房间编码大于或等于结束楼层房间编码,请保证前者比后则小!"), Config.DialogTitle);
                return;
            }

            string strBegin   = FormatRoomCode(iBeginCode);
            string strEnd     = FormatRoomCode(iEndCode);
            int    iBeginRoom = Convert.ToInt32(strBegin.Substring(2, 2));
            int    iEndRoom   = Convert.ToInt32(strEnd.Substring(2, 2));

            if (iBeginRoom >= iEndRoom)
            {
                txtRoomCodeBegin.Focus();
                CMessageBox.ShowError(string.Format("输入的起始房间编码大于或等于结束房间编码,请保证前者比后则小!"), Config.DialogTitle);
                return;
            }

            if (MessageBox.Show("确定要现在批量生成吗?", Config.DialogTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
            {
                return;
            }
            //0010 0011
            //0018 1111

            btnOK.Enabled     = false;
            btnCancel.Enabled = false;
            tbxComunicateData.Clear();
            Model.BuidingBatchCondition objCondition = new Model.BuidingBatchCondition(iUnitID, iBeginCode, iEndCode);
            ThreadPool.QueueUserWorkItem(new WaitCallback(TaskProcess), objCondition);
        }
Exemplo n.º 21
0
        protected override void BtnOK_Click(object sender, EventArgs e)
        {
            DBSetting objDBSetting = GetSettingFromUI();

            if (!CheckDBSettings(objDBSetting, out string strErrInfo))
            {
                CMessageBox.ShowError(string.Format("数据库配置错误,错误如下:\r\n{0}", strErrInfo), Config.DialogTitle);
                return;
            }
            Setting objAllSetting = new Setting()
            {
                //数据库
                DBSetting = objDBSetting,
                //制卡串口
                WriteComProperty = new Classes.ComProperty()
            };

            objAllSetting.WriteComProperty.PortName = "";
            objAllSetting.WriteComProperty.BaudRate = 9600;
            objAllSetting.WriteComProperty.DataBits = 8;
            objAllSetting.WriteComProperty.StopBits = System.IO.Ports.StopBits.One;
            objAllSetting.WriteComProperty.Parity   = System.IO.Ports.Parity.None;
            //监控串口
            objAllSetting.MonitorComProperty = new Classes.ComProperty()
            {
                PortName = "",
                BaudRate = 19200,
                DataBits = 8,
                StopBits = System.IO.Ports.StopBits.One,
                Parity   = System.IO.Ports.Parity.None
            };
            //其他配置
            objAllSetting.OtherSetting = new OtherSetting()
            {
                SyncTimePL = 10,
                SyncAuto   = 0,
                Chs        = 1
            };
            if (this._OldSetting != null)
            {
                //制卡串口
                if (this._OldSetting.WriteComProperty != null)
                {
                    objAllSetting.WriteComProperty.BaudRate = this._OldSetting.WriteComProperty.BaudRate;
                    objAllSetting.WriteComProperty.DataBits = this._OldSetting.WriteComProperty.DataBits;
                    objAllSetting.WriteComProperty.StopBits = this._OldSetting.WriteComProperty.StopBits;
                    objAllSetting.WriteComProperty.Parity   = this._OldSetting.WriteComProperty.Parity;
                }
                //监控串口
                if (this._OldSetting.MonitorComProperty != null)
                {
                    objAllSetting.MonitorComProperty.BaudRate = this._OldSetting.MonitorComProperty.BaudRate;
                    objAllSetting.MonitorComProperty.DataBits = this._OldSetting.MonitorComProperty.DataBits;
                    objAllSetting.MonitorComProperty.StopBits = this._OldSetting.MonitorComProperty.StopBits;
                    objAllSetting.MonitorComProperty.Parity   = this._OldSetting.MonitorComProperty.Parity;
                }
                //其他配置
                if (this._OldSetting.OtherSetting != null)
                {
                    objAllSetting.OtherSetting.SyncTimePL = this._OldSetting.OtherSetting.SyncTimePL;
                    objAllSetting.OtherSetting.SyncAuto   = this._OldSetting.OtherSetting.SyncAuto;
                    objAllSetting.OtherSetting.Chs        = this._OldSetting.OtherSetting.Chs;
                }
            }

            if (!SysConfiger.SaveSetting(objAllSetting, RunVariable.IniPathAndFileName, out strErrInfo))
            {
                CMessageBox.ShowError(string.Format("对不起,保存数据库配置失败,错误如下:\r\n{0}", strErrInfo), Config.DialogTitle);
            }
            else
            {
                CMessageBox.ShowSucc(string.Format("恭喜您,保存数据库配置成功!"), Config.DialogTitle);
                this.DialogResult = DialogResult.OK;
            }
        }
Exemplo n.º 22
0
 /// <summary>
 /// 回调方法-监控器当停止失败时
 /// </summary>
 /// <param name="strErrorMessage"></param>
 private void CardMonitor_OnStopFault(string strErrorMessage)
 {
     RenderLayout();
     CMessageBox.ShowError(string.Format("监控串口关闭失败,错误如下:\r\n{0}", strErrorMessage), Config.DialogTitle);
 }
Exemplo n.º 23
0
 /// <summary>
 /// 回调方法-配置器当打开失败时
 /// </summary>
 /// <param name="strErrorMessage"></param>
 private void CardViewForm_OnStartFault(string strErrorMessage)
 {
     CMessageBox.ShowError(string.Format("制卡串口开启失败,请查看您的配置,错误原因如下:\r\n{0}", strErrorMessage), Config.DialogTitle);
     ShowComStatus();
 }
Exemplo n.º 24
0
        protected override void BtnOK_Click(object sender, EventArgs e)
        {
            int iNewAreaID  = 0;
            int iNewBuildID = 0;
            int iNewUnitID  = 0;

            int    iCode       = 0;
            int    iFatherID   = 0;
            string strBName    = txtName.Text.Trim();
            string strCode     = txtCode.Text.Trim();
            string strContact  = txtContact.Text.Trim();
            string strTel      = txtTel.Text.Trim();
            string strSerialNo = txtSerialNo.Text.Trim();

            int iSelectID = 0;

            if (cbArea.Visible)
            {
                iSelectID = Convert.ToInt32(((Model.ComboBoxItem)cbArea.SelectedItem).Value);
                if (iSelectID <= 0)
                {
                    CMessageBox.ShowError("请选择一个小区!", Config.DialogTitle);
                    return;
                }
                if (this._DataType.Equals(1))
                {
                    iFatherID = iSelectID;
                }
                iNewAreaID = iSelectID;
            }
            if (cbBuild.Visible)
            {
                iSelectID = Convert.ToInt32(((Model.ComboBoxItem)cbBuild.SelectedItem).Value);
                if (iSelectID <= 0)
                {
                    CMessageBox.ShowError("请选择一个楼栋!", Config.DialogTitle);
                    return;
                }
                if (this._DataType.Equals(2))
                {
                    iFatherID = iSelectID;
                }
                iNewBuildID = iSelectID;
            }
            if (cbUnit.Visible)
            {
                iSelectID = Convert.ToInt32(((Model.ComboBoxItem)cbUnit.SelectedItem).Value);
                if (iSelectID <= 0)
                {
                    CMessageBox.ShowError("请选择一个单元!", Config.DialogTitle);
                    return;
                }
                if (this._DataType.Equals(3))
                {
                    iFatherID = iSelectID;
                }
                iNewUnitID = iSelectID;
            }

            if (strBName.Equals(""))
            {
                txtName.Focus();
                CMessageBox.ShowError(string.Format("请输入{0}名称!", this._DataTypeName), Config.DialogTitle);
                return;
            }
            if (strCode.Equals("") || !Functions.IsInt(strCode))
            {
                txtCode.Focus();
                CMessageBox.ShowError(string.Format("{0}编码不能为空,且范围必须是{1}之间的整数!", this._DataTypeName, (this._DataType.Equals(3) ? "0~9999" : "0~99")), Config.DialogTitle);
                return;
            }
            iCode = Functions.FormatInt(strCode);
            if (cbUnit.Visible)
            {
                //是房间
                if (!(iCode >= 0 && iCode <= 9999))
                {
                    txtCode.Focus();
                    CMessageBox.ShowError(string.Format("输入的{0}编码超出范围,取值范围是0~9999之间的整数!", this._DataTypeName), Config.DialogTitle);
                    return;
                }
            }
            else
            {
                if (!(iCode >= 0 && iCode <= 99))
                {
                    txtCode.Focus();
                    CMessageBox.ShowError(string.Format("输入的{0}编码超出范围,取值范围是0~99之间的整数!", this._DataTypeName), Config.DialogTitle);
                    return;
                }
            }

            if (this._DataType.Equals(0) && !CheckSerialNo(strSerialNo))
            {
                txtSerialNo.Focus();
                CMessageBox.ShowError(string.Format("序列号必须填写,且必须是16字节的16进制字符!"), Config.DialogTitle);
                return;
            }

            if (MessageBox.Show("确定要保存吗?", Config.DialogTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
            {
                return;
            }
            Model.Building objModel = new Model.Building()
            {
                Flag             = _DataType,
                FID              = iFatherID,
                ID               = this._CurrentID,
                BName            = strBName,
                Code             = iCode,
                Contact          = strContact,
                Tel              = strTel,
                BuildingSerialNo = strSerialNo
            };
            string strErrorInfo = "";

            IDAL.IBuilding objDAL = DALFactory.DALFactory.Building();
            if (this._CurrentAction.Equals(EAction.Create))
            {
                int iNewID = objDAL.Add(objModel, out strErrorInfo);
                if (iNewID <= 0)
                {
                    CMessageBox.ShowError(string.Format("创建{0}数据失败,错误如下:\r\n{1}!", this._DataTypeName, strErrorInfo), Config.DialogTitle);
                    return;
                }
            }
            else
            {
                bool bIfSucc = objDAL.Update(objModel, out strErrorInfo);
                if (!bIfSucc)
                {
                    CMessageBox.ShowError(string.Format("修改{0}数据失败,错误如下:\r\n{1}!", this._DataTypeName, strErrorInfo), Config.DialogTitle);
                    return;
                }
            }
            //是否通知建筑数据已经改变
            bool bIfNotice = false;

            if (this._CurrentAction == EAction.Create)
            {
                //新增必通知
                bIfNotice = true;
            }
            else
            {
                if (string.Compare(this._OldName, strBName) != 0 || !this._OldCode.Equals(iCode) || !this._OldAreaID.Equals(iNewAreaID) || !this._OldBuildID.Equals(iNewBuildID) || !this._OldUnitID.Equals(iNewUnitID))
                {
                    //条件满足通知
                    bIfNotice = true;
                }
            }
            if (bIfNotice)
            {
                Manager.GetInstance().BuildingDataChangeNotice();
            }
            this.DialogResult = DialogResult.OK;
        }
Exemplo n.º 25
0
 /// <summary>
 /// 回调方法-配置器当打开失败时
 /// </summary>
 /// <param name="strErrorMessage"></param>
 private void CardConfiger_OnStartFault(string strErrorMessage)
 {
     RenderLayout();
     CMessageBox.ShowError(string.Format("写卡串口开启失败,请查看您的配置,错误如下:\r\n{0}", strErrorMessage), Config.DialogTitle);
 }