//CommControl.MessageBoxEx.MessageBoxEx messagebox;
        private void btnOK_Click(object sender, EventArgs e)
        {
            DB_Talk.BLL.m_Member _BLL = new DB_Talk.BLL.m_Member();
            List<DB_Talk.Model.m_Member> listCount = new List<DB_Talk.Model.m_Member>();
            listCount = _BLL.GetModelList(string.Format(" i_flag=0 and BoxID='{0}'", Global.Params.BoxID));
            if (listCount.Count >= Global.Params.MaxBoxMemberCount)
            {
                CommControl.MessageBoxEx.MessageBoxEx.Show(string.Format("不能导入,号码已经达到最大限制,【{0}】个!", Global.Params.MaxBoxMemberCount), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            Bestway.Windows.Forms.ProgressBarDialog procDlg = null;
            procDlg = new Bestway.Windows.Forms.ProgressBarDialog();
            try
            {
                procDlg.Show(Bestway.Windows.Forms.EnumDisplayType.LoadData, "      正在导入用户,请稍等...");
                DataTable dt = new DataTable();
                dt = (DataTable)dgvList.DataSource;
                if (dt == null)
                {
                    throw new Exception("没有数据!");
                    
                }
                DB_Talk.BLL.m_Member bll = new DB_Talk.BLL.m_Member();
                StringBuilder sbAdd = new StringBuilder();
                List<DB_Talk.Model.m_Member> listAdd = new List<DB_Talk.Model.m_Member>();

                StringBuilder sbNotAdd = new StringBuilder();
                StringBuilder sbAdded = new StringBuilder();     //box中已经存在的
                StringBuilder sbBoxMaxNotAdded = new StringBuilder();  //box到达最大值未添加的
                //List<DB_Talk.Model.m_Member> list = (List < DB_Talk.Model.m_Member >)dgvListOk.DataSource;
                List<DB_Talk.Model.m_Member> list = DataTableToModelList(dt);

                int iAdd=0,iAdded = 0;  //添加成功数,已经存在的数
                int iRepeatIP=0;  //IP已经存在的
                int iNotAdd = 0;     //添加失败数
                int iBoxMaxNotAdded = 0;    //到达最大后的用户
                if (dt.Rows.Count == 0)
                {
                    throw new Exception("没有数据可以导入!");
                }
                if (list.Count == 0)
                {
                    throw new Exception("没有合法的数据可以导入!");
                }

                foreach (DB_Talk.Model.m_Member item in list)
                {
                    if (listCount.Count + iAdded >= Global.Params.MaxBoxMemberCount)  //到达最大值
                    {
                        iBoxMaxNotAdded++;
                        sbBoxMaxNotAdded.Append("," + item.i_Number);

                    }
                    else
                    {
                        string strW = " i_Flag=0 and BoxID='" + Global.Params.BoxID + "'";
                        //strW += " and vc_Name='" + item.vc_Name + "'";
                        strW += " and i_Number='" + item.i_Number + "'";

                       

                        bool IsExist = MBoxSDK.ConfigSDK.MBOX_IsSubscriberExist(Global.Params.BoxHandle,(item.i_Number.Value));
                        CommControl.Tools.WriteLog.AppendLog("box添加号码", "boxHandle:" + Global.Params.BoxHandle + ", 号码:" + Convert.ToInt32(item.i_Number.ToString()) + ", 是否存在:" + IsExist);
          
                        if (bll.Exists(strW) || IsExist)
                            //MBoxSDK.ConfigSDK.MBOX_IsSubscriberExist(Global.Params.BoxHandle, Convert.ToInt32(item.i_Number.ToString())))
                        {
                            iAdded++;
                            sbAdded.Append("," + item.i_Number);//.vc_Name);
                        }
                        else if (item.i_TellType.Value == PublicEnums.EnumTelType.广播.GetHashCode() &&
                          _BLL.GetModelList(string.Format(" i_flag=0 and  vc_IP='{0}' and BoxID='{1}'", item.vc_IP, item.BoxID)).Count > 0)
                        {
                           //(string.Format("数据库中IP【{0}】已存在!", item.i_Number)
                            iRepeatIP++;
                        }
                        else
                        {
                            item.i_supplementSerive = (int)(MBoxSDK.ConfigSDK.SPM_MISS_CALL |
                                                            MBoxSDK.ConfigSDK.SPM_MISS_CALL_ON_BUSY |
                                                            MBoxSDK.ConfigSDK.SPM_SMS |
                                                            MBoxSDK.ConfigSDK.SPM_THREE_PARTY |
                                                            MBoxSDK.ConfigSDK.SPM_CALL_WAITING |
                                                            MBoxSDK.ConfigSDK.SPM_CALL_TRANSFER); // |
                                                           // MBoxSDK.ConfigSDK.SPM_CALL_PICKUP);
                            bool create= new frmMember(null, 0).AddBase(item);
                            //bool create =  MBoxSDK.ConfigSDK.MBOX_CreateSubscriber(Global.Params.BoxHandle,ref subscriberBase);
                            if (create)
                            //MBoxSDK.ConfigSDK.MBOX_CreateSubscriber(Global.Params.BoxHandle, Convert.ToInt32(item.i_Number.ToString())))
                            {
                                listAdd.Add(item);
                                //bll.Add(item);
                                //CommControl.SystemLogBLL.WriteLog(Global.Params.UserID, Global.Params.BoxID, CommControl.SystemLogBLL.EnumLogAction.Add, "导入", "导入了人员:" + item.vc_Name, "");
                                sbAdd.Append("," + item.i_Number);

                                iAdd++;
                                procDlg.Show(Bestway.Windows.Forms.EnumDisplayType.LoadData, "      用户【" + item.vc_Name + "】正在写入硬件,请稍等...");
                            }
                            else
                            {
                                sbNotAdd.Append("," + item.i_Number); //.vc_Name);
                                iNotAdd++;

                            }
                        }
                    }
                }
                string mes = "";
                bool bSave = false;
                if (iAdd > 0)
                {
                    TimeSpan sp = new TimeSpan(0);
                    DateTime dtstart = System.DateTime.Now;
                    bSave = MBoxSDK.ConfigSDK.MBOX_SaveHaveDoneCfg(Global.Params.BoxHandle); //保存更改
                    DateTime dtEnd = System.DateTime.Now;
                    if (bSave)
                    {
                        sp = dtEnd - dtstart;
                        //CommControl.MessageBoxEx.MessageBoxEx.Show(sp.TotalMilliseconds.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    //sbAdd.Remove(0, 1);
                }
                if (bSave)
                {
                    foreach (DB_Talk.Model.m_Member item in listAdd)
                    {
                        procDlg.Show(Bestway.Windows.Forms.EnumDisplayType.LoadData, "      用户【" + item.vc_Name + "】加入数据库,请稍等...");
                     
                        bll.Add(item);
                        CommControl.SystemLogBLL.WriteLog(Global.Params.UserID, Global.Params.BoxID, CommControl.SystemLogBLL.EnumLogAction.Add, "导入", "导入了人员:" + item.vc_Name, "");
                    }
                           
                    if (iAdd > 10)
                    {
                        mes = "共导入【" + iAdd + "】个用户!\r\n";
                    }
                    else if (iAdd > 0 && iAdd <= 10)
                    {
                        sbAdd.Remove(0, 1);
                        mes = "号码【" + sbAdd.ToString() + "】导入成功!\r\n";
                    }

                }
                else if (iAdd!=0)
                {
                    mes = "保存硬件配置失败!\r\n";
                }

                if (iNotAdd > 10)
                {
                    mes += "【" + iNotAdd + "】个号码写入硬件失败!\r\n";
                }
                else if (iNotAdd > 0 && iNotAdd <= 10)
                {
                    sbNotAdd.Remove(0, 1);
                    mes += "号码【" + sbNotAdd.ToString() + "】写入硬件失败!\r\n";
                }

                if (iAdded > 10)
                {
                    mes += "【" + iAdded + "】个号码已经存在,不再导入!\r\n";
                }
                else if (iAdded > 0 && iAdded <= 10)
                {
                    sbAdded.Remove(0, 1);
                    mes += "号码【" + sbAdded.ToString() + "】已经存在,不再导入!\r\n";
                }
                if(iBoxMaxNotAdded>5)
                {
                    mes += "设备中号码已经达到最大值,【" + iBoxMaxNotAdded + "】个号码,不再导入!";
                }
                else if (iBoxMaxNotAdded > 0 && iBoxMaxNotAdded <= 5)
                {
                    sbBoxMaxNotAdded.Remove(0, 1);
                    mes += "设备中号码已经达到最大值,号码【" + sbBoxMaxNotAdded + "】,不再导入!";
                }
                if (iRepeatIP>0)
                {
                    mes += "【" + iRepeatIP + "】个重复IP,不再导入!";
                }

                procDlg.Dispose();
                if (mes.Length > 0)
                {
                    CommControl.MessageBoxEx.MessageBoxEx.Show(mes, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.DialogResult = DialogResult.OK;
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                procDlg.Dispose();
                CommControl.MessageBoxEx.MessageBoxEx.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
           
            
           
         }
 private void btnAdd_Click(object sender, EventArgs e)
 {
     if (!IsSetBoxNumLenAndHead())
     {
         CommControl.MessageBoxEx.MessageBoxEx.Show("还未进行基本设置,不能执行添加操作!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
         return;
     }
     
     DB_Talk.BLL.m_Member _BLL = new DB_Talk.BLL.m_Member();
     List<DB_Talk.Model.m_Member> list = new List<DB_Talk.Model.m_Member>();
     list = _BLL.GetModelList(string.Format(" i_flag=0 and BoxID='{0}'", Global.Params.BoxID));
     if (list.Count >= Global.Params.MaxBoxMemberCount)
     {
         CommControl.MessageBoxEx.MessageBoxEx.Show(string.Format("不能添加,号码已经达到最大限制,【{0}】个!", Global.Params.MaxBoxMemberCount), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
         return;
     }
     UI.frmMember frm = new UI.frmMember(null, 0);
     frm.ShowDialog();
     if(frm.DialogResult==DialogResult.OK)
        LoadData("");
 
 }
Exemplo n.º 3
0
        private void GetModel()
        {
            _mModel.BoxID = Global.Params.BoxID;
            
            _mModel.vc_Name = txtName.Text.Trim();
            if (txtName.Enabled==true && _mModel.vc_Name == "")
            {
                txtName.Focus();
                throw new Exception("用户名称不可以为空");
            }
            if (_mModel.vc_Name.IndexOf("'") >= 0)
            {
                txtName.Focus();
                throw new Exception("名称中不可以有特殊字符");
            }
            /*
            if (_mModel.DepartmentID == null)
            {
                throw new Exception("请选择部门");
            }
            */
            if (txtTel.Text.Trim() == "" || int.Parse(txtTel.Text.Trim()) == 0 )
            {
                txtTel.Focus();
                throw new Exception("电话号码不可以为空或零");
            }

            string str = txtTel.Text.Trim().Substring(0,1);
            if (txtTel.Text.Trim().Length != Global.Params.NumberLen || CheckNumberRule(txtTel.Text.Trim(), Global.Params.strNumHead)==false)   
            {
                txtTel.Focus();
                string mes = Global.Params.strNumHead.Replace(",", "或");
                throw new Exception("用户号码长度必须是【" + Global.Params.NumberLen + "】位,且以数字【" + mes + "】开头");
                
            }

            DB_Talk.Model.m_Box modelBox = new DB_Talk.BLL.m_Box().GetModel(Global.Params.BoxID);
            if (modelBox != null)
            {
                if (modelBox.i_DispatchNumber == int.Parse(txtTel.Text.Trim()))
                {
                    throw new Exception("用户号码不能和调度号码(" + modelBox.i_DispatchNumber + ")相同!");
                }
                if (modelBox.i_EmergencyNumber == int.Parse(txtTel.Text.Trim()))
                {
                    throw new Exception("用户号码不能和紧急号码(" + modelBox.i_EmergencyNumber+ ")相同!");
                }
            }
            //if (txtTel.Text.Replace(" ", "").Length != Global.Params.NumberLen)
            //{
            //    txtTel.Focus();
            //    throw new Exception("电话号码必须是: "+Global.Params.NumberLen+" 位");
            //}

            _mModel.i_Number = int.Parse(txtTel.Text.Replace(" ", "").Trim());


            if (cmbNoType.SelectedValue.ToString() != CommControl.PublicEnums.EnumTelType.G3G手机.GetHashCode().ToString())
            {
                if (_mModel.i_NuPasswordType == null)
                    throw new Exception("请选择密码模式");
                if (_mModel.i_NuPasswordType == PublicEnums.EnumTelPasswordType.增加.GetHashCode())
                {
                    _mModel.i_NuPassword = (UInt64)_mModel.i_Number;
                }
                else
                {
                    if (txtPassword.Text.Trim() == "")
                    {
                        txtPassword.Focus();
                        throw new Exception("当密码模式为固定时,用户密码不能为空");
                    }
                    _mModel.i_NuPassword = UInt64.Parse(txtPassword.Text.Trim());
                    //UInt64 pasw = 0;
                    //if (UInt64.TryParse(txtPassword.Text.Trim(), out pasw) && pasw > 100 && pasw<=999999999999)
                    //    //pasw.ToString().Length >= 3 && pasw.ToString().Length <= 12)
                    //    _mModel.i_NuPassword = pasw;
                    //else
                    //    throw new Exception("用户密码必须是100~999999999999位之间的数字");
                    //    //throw new Exception("用户密码长度必须在3~12位之间,且大于零");
                }
            }
            else
            {
                _mModel.i_NuPasswordType=0;
                _mModel.i_NuPassword = 0;
            }

            if (_mModel.NumberTypeID == null)
            {
                throw new Exception("请选择号码类别");
            }
          
            _mModel.vc_MAC = txtMAC.Text.Trim();
            //if (_mModel.vc_MAC == "")
            //{
            //    txtMAC.Focus();
            //    throw new Exception("MAC不可以为空");
            //}
            if (_mModel.vc_MAC.IndexOf("'") >= 0)
            {
                txtName.Focus();
                throw new Exception("MAC中不可以有特殊字符");
            }

            if (txtTelEnd.Text.Trim() != "")
            {
                string strEnd = txtTelEnd.Text.Trim().Substring(0, 1);
                if (txtTelEnd.Text.Trim().Length != Global.Params.NumberLen || Global.Params.strNumHead.IndexOf(str) < 0)
                {
                    txtTelEnd.Focus();
                    string mes = Global.Params.strNumHead.Replace(",", "或");
                    throw new Exception("用户号码长度必须是【" + Global.Params.NumberLen + "】位,且以数字【" + mes + "】开头");

                }

                addCount =Int64.Parse(txtTelEnd.Text.Trim()) -_mModel.i_Number.Value;
                if (addCount < 0)
                {
                    txtTelEnd.Focus();
                    throw new Exception("终止号码不可以小于起始号码");
                }
                else 
                {
                    DB_Talk.BLL.m_Member _BLL = new DB_Talk.BLL.m_Member();
                    List<DB_Talk.Model.m_Member> listCount = new List<DB_Talk.Model.m_Member>();
                    listCount = _BLL.GetModelList(string.Format(" i_flag=0 and BoxID='{0}'", Global.Params.BoxID));
                    if (listCount != null && (addCount > Global.Params.MaxBoxMemberCount - listCount.Count))
                    {
                        throw new Exception(string.Format("终止号码过大,最多还能添加【{0}】个号码!", Global.Params.MaxBoxMemberCount-listCount.Count));
                    }
                }

              
               
            }


            if (txtIP1.Enabled)
            {
                if (txtIP1.Text=="" || txtIP2.Text=="")
                {
                    throw new Exception("起始或者终止IP地址不能为空!");
                }

                bool b = IsSameLanNet(IPAddress.Parse(txtIP1.Text.Trim()), IPAddress.Parse(txtIP2.Text.Trim()));
                if (!b)
                {
                     throw new Exception("起始IP与终止IP不在一个网段");
                }

                string[] IP1 = txtIP1.Text.Trim().Split(new string[] { "." }, StringSplitOptions.RemoveEmptyEntries);
                string[] IP2 = txtIP2.Text.Trim().Split(new string[] { "." }, StringSplitOptions.RemoveEmptyEntries);
                int addCountIP = int.Parse(IP2[3]) - int.Parse(IP1[3]);
                if (addCountIP < 0)
                {
                    txtIP2.Focus();
                    throw new Exception("终止IP不可以小于起始IP");
                }
                if (addCount==0 && addCountIP>0)
                {
                    throw new Exception("起始IP与终止IP不同时,终止号码不能为空!\n\n且增加号码个数与IP个数必须相同");                    
                }
                else if (addCount!=addCountIP)
                {
                    throw new Exception("增加的号码个数与IP个数不一致");                    
                }
                _mModel.vc_IP = txtIP1.Text.Trim();

            }

            if (_mModel.i_TellType == CommControl.PublicEnums.EnumTelType.G3G手机.GetHashCode()
                && txtUmtsImsi.Text.Trim()=="")
            {
                throw new Exception("3G号码标示码不能为空");
            }
            _mModel.vc_UmtsImsi = txtUmtsImsi.Text.Trim();

            _mModel.vc_Memo = txtMemo.Text.Trim();
            if (_mModel.vc_Memo.IndexOf("'") >= 0)
            {
                txtMemo.Focus();
                throw new Exception("备注中不可以有特殊字符");
            }

            if (groupBoxG.Visible == true)
            {
                if (chkUnCForward.Checked && txtUnCForward.Text == "")
                {
                    txtUnCForward.Focus();
                    throw new Exception("请设置无条件呼叫前转号码");
                }
                else if (txtUnCForward.Text != "")
                {
                    if (txtUnCForward.Text.Trim() == txtTel.Text.Trim())
                    {
                        txtUnCForward.Focus();
                        throw new Exception("无条件呼叫前转号码不能与自身号码相同");
                    }
                    _mModel.i_UnCForwardNu = int.Parse(txtUnCForward.Text);
                }
                else
                {
                    _mModel.i_UnCForwardNu = 0;
                }


                if (chkNoAnswerForward.Checked && txtNoAnswerForward.Text == "")
                {
                    txtNoAnswerForward.Focus();
                    throw new Exception("请设置无应答呼叫前转号码");
                }
                else if (txtNoAnswerForward.Text != "")
                {
                    if (txtNoAnswerForward.Text.Trim() == txtTel.Text.Trim())
                    {
                        txtNoAnswerForward.Focus();
                        throw new Exception("无应答呼叫前转号码不能与自身号码相同");
                    }
                    _mModel.i_NoAnswerForward = int.Parse(txtNoAnswerForward.Text);
                }
                else
                {
                    _mModel.i_NoAnswerForward = 0;
                }


                if (chkBusyForward.Checked && txtBusyForward.Text == "")
                {
                    txtBusyForward.Focus();
                    throw new Exception("请设置遇忙前转号码");
                }
                else if (txtBusyForward.Text != "")
                {
                    if (txtBusyForward.Text.Trim() == txtTel.Text.Trim())
                    {
                        txtBusyForward.Focus();
                        throw new Exception("遇忙转接号码不能与自身号码相同");
                    }
                    _mModel.i_BusyForward = int.Parse(txtBusyForward.Text);
                }
                else
                {
                    _mModel.i_BusyForward = 0;
                }

                if (chkPowerOffForward.Checked && txtPowerOffForward.Text == "")
                {
                    txtPowerOffForward.Focus();
                    throw new Exception("请设置关机前转号码");
                }
                else if (txtPowerOffForward.Text != "")
                {
                    if (txtPowerOffForward.Text.Trim() == txtTel.Text.Trim())
                    {
                        txtPowerOffForward.Focus();
                        throw new Exception("关机前转号码不能与自身号码相同");
                    }
                    _mModel.i_PowerOffForward = int.Parse(txtPowerOffForward.Text);
                }
                else
                {
                    _mModel.i_PowerOffForward = 0;
                }


                if (chkDirectNum.Checked && txtDirectNum.Text == "")
                {
                    txtDirectNum.Focus();
                    throw new Exception("请设置直通号码");
                }
                else if (txtDirectNum.Text != "")
                {
                    if (txtDirectNum.Text.Trim() == txtTel.Text.Trim())
                    {
                        txtDirectNum.Focus();
                        throw new Exception("直播号码不能与自身号码相同");
                    }
                    _mModel.i_DirectNum = int.Parse(txtDirectNum.Text);

                }
                else
                {
                    _mModel.i_DirectNum = 0;
                }


                if (chkAssociateNum1.Checked && txtAssociateNum1.Text == "")
                {
                    txtAssociateNum1.Focus();
                    throw new Exception("请设置关联号码1");
                }
                else if (txtAssociateNum1.Text != "")
                {
                    if (  _mModel.i_AssociateNum1 != int.Parse(txtAssociateNum1.Text))
                    {
                        _mModel.i_AssociateNum1 = int.Parse(txtAssociateNum1.Text);
                        CheckAssociateNum(_mModel.i_AssociateNum1.ToString());
                    }
                }
                else
                {
                    _mModel.i_AssociateNum1 = 0;
                }


                if (chkAssociateNum2.Checked && txtAssociateNum2.Text == "")
                {
                    txtAssociateNum2.Focus();
                    throw new Exception("请设置关联号码2");
                }
                else if (txtAssociateNum2.Text != "")
                {
                    _mModel.i_AssociateNum2 = int.Parse(txtAssociateNum2.Text);
                    CheckAssociateNum(_mModel.i_AssociateNum2.ToString());
                }
                else
                {
                    _mModel.i_AssociateNum2 = 0;
                }

                if (txtAssociateNum1.Text.Trim() != "" && txtAssociateNum2.Text.Trim() != "" && txtAssociateNum1.Text.Trim() == txtAssociateNum2.Text.Trim())
                {
                    txtAssociateNum2.Focus();
                    throw new Exception("两个关联号码不能相同");
                }

            }
        }