Exemplo n.º 1
0
        long addCount = 0;   //批量添加总数
        public frmMember(List<DB_Talk.Model.v_Member> lstvModel, int operate)//DB_Talk.Model.v_Member model, )
        {
            InitializeComponent();
          
            this.cmbNoType.SelectedIndexChanged+=new EventHandler(cmbNoType_SelectedIndexChanged);
            this.Load += new EventHandler(frmMember_Load);
           
            _operate = operate;
            if (operate == 0)
            {
                this.FormTitle = "添加";
                btnOK.Text = "添加";
            }
            else if(operate==1) //修改一个
            {
                _vModel = lstvModel[0];// model;
                _mModel = _BLL.GetModel(_vModel.ID);
                _mPreModel = (DB_Talk.Model.m_Member)_mModel.Clone();
                preNumber =int.Parse(_mModel.i_Number.ToString());
                this.FormTitle = "编辑";
                btnOK.Text = "编辑";
                txtTelEnd.Enabled = false;
                ShowModel();
            }
            else if (operate == 2)
            {
                this.FormTitle = "编辑多个";
                btnOK.Text = "编辑多个";
                txtName.Enabled = false;
                txtTel.Enabled = false;
                txtTelEnd.Enabled = false;
                cmbNoType.Enabled = false;
                txtUmtsImsi.Enabled = false;
                btnG.Enabled = false;
                _lstvModel = lstvModel;
               
            }

            //if (operate != 2)
            //{
                InitCmb();
                if (Global.Params.ConfigModel.SystemConfig.MaxNameTextLengh != 0)
                    this.txtName.MaxLength = Global.Params.ConfigModel.SystemConfig.MaxNameTextLengh;//  Global.Params.NameLen;

                this.txtTel.MaxLength = Global.Params.NumberLen;
                this.txtTelEnd.MaxLength = Global.Params.NumberLen;
            //}

                if (operate == 2)
                {
                    ShowModelMuti();
                }
        }
        public void LoadData()
        {
            string inNumber = Tools.MBoxOperate.GetCalledNumbers(MBoxSDK.ConfigSDK.CALLED_RULE_TYPE.入局, "");
            PreBoxModel.vc_NumberHead = inNumber;
            PreBoxModel = new DB_Talk.BLL.m_Box().GetModel(Global.Params.BoxID);
            //StringBuilder sb = new StringBuilder();
            //if (PreBoxModel.i_DispatchNumber != null) sb.Append(",'" + PreBoxModel.i_DispatchNumber.ToString() + "'");
            //if (PreBoxModel.i_EmergencyNumber != null) sb.Append(",'" + PreBoxModel.i_EmergencyNumber.ToString() + "'");
            //if (PreBoxModel.vc_NumberHead != null) sb.Append(",'" + PreBoxModel.vc_NumberHead.ToString() + "'");
            //string strW = string.Format(" i_Flag=0 and BoxID='{0}' ", Global.Params.BoxID);
            //if (sb.Length > 0)
            //{
            //    sb.Remove(0, 1);
            //    strW = string.Format(" i_Flag=0 and BoxID='{0}' and vc_CalledNumber in ({1})",
            //                         Global.Params.BoxID, sb.ToString());
            //}


            DB_Talk.Model.m_Member m = BLL.GetModel("i_Flag=0 and BoxID='" +
                                          Global.Params.BoxID + "' and i_IsDispatch='2'");
            txtDispatch.Tag = m;
            preModelDispatch = m;
            if (m != null)
            {
                txtDispatch.Text = m.i_Number.ToString();
                txtDispatchPassword.Text = m.i_NuPassword.ToString();
            }


            string strW = string.Format(" i_Flag=0 and BoxID='{0}' and i_CalledType = '{1}'", Global.Params.BoxID,MBoxSDK.ConfigSDK.CALLED_RULE_TYPE.入局.GetHashCode());
            OldlstCalledRule = new DB_Talk.BLL.m_CalledRule().GetModelList(strW);
            string strWhere = string.Format("i_Flag=0 and BoxID='" +Global.Params.BoxID+ "' and i_IsDispatch='1' order by ID");  //i_Number");
            lstMember = BLL.GetModelList(strWhere);
            //dgvList.DataSource = lstModel;
            dgvList.Rows.Clear();

            for (int i = 0; i < DispatchCount; i++)
            {
                DB_Talk.Model.m_Member model = new DB_Talk.Model.m_Member();
                if (lstMember.Count > i)
                {
                    model.ID = lstMember[i].ID;
                    model.vc_Name = lstMember[i].vc_Name;
                    model.i_Number = lstMember[i].i_Number;
                    dgvList.Rows[dgvList.Rows.Add(ID,
                    "调度员" + (i + 1).ToString(),
                    lstMember[i].vc_Name,
                    lstMember[i].i_Number != null && lstMember[i].i_Number.Value > 0 ? lstMember[i].i_Number.ToString() : ""
                    )].Tag = lstMember[i];
                }
                else
                {
                    dgvList.Rows.Add("", "调度员" + (i + 1).ToString(), "", "", "");
                    lstMember.Add(model);
                }
            }

            dgvList.ClearSelection();

            //if (lstModel.Count == DispatchCount)
            //{
            //    int index = 0;
            //    foreach (DB_Talk.Model.m_Member item in lstModel)
            //    {
            //        dgvList.Rows[dgvList.Rows.Add(ID,
            //            "调度员" + index.ToString(),
            //            item.vc_Name,
            //            item.i_Number
            //            )].Tag = item;
            //    }
            //}


        }
        private void GetDispatchModel(ref DB_Talk.Model.m_Member model,ref DB_Talk.Model.m_Member preModel)
        {
            model = new DB_Talk.Model.m_Member();
            preModel = txtDispatch.Tag as DB_Talk.Model.m_Member;
            try
            {
                if (txtDispatch.Text.Trim() == "")
                {
                    txtDispatch.Focus();
                    throw new Exception("视频调度号码不能为空");
                }
                else
                {
                    int num = 0;
                    if (int.TryParse(txtDispatch.Text.Trim(), out num))
                    {
                        model.i_Number = num;
                        model.vc_Name = txtDispatch.Text.Trim();
                    }
                    else
                    {
                        txtDispatch.Focus();
                        throw new Exception("视频调度号码只能为数字");
                    }
                    //model.i_Number = Convert.ToInt32(txtDispatch.Text.Trim());
                }

                if (txtDispatchPassword.Text.Trim() == "")
                {
                    txtDispatchPassword.Focus();
                    throw new Exception("视频调度密码不能为空");
                }
                else
                {
                    UInt64 num = 0;
                    if (UInt64.TryParse(txtDispatchPassword.Text.Trim(), out num))
                    {
                        model.i_NuPassword = Convert.ToUInt64(num);
                    }
                    else
                    {
                        txtDispatchPassword.Focus();
                        throw new Exception("视频调度号码只能为数字");
                    }
                }

                string mes = string.Empty;
                if (model.vc_Name != "" && model.i_Number > 0)
                {
                    string str = model.i_Number.ToString().Substring(0, 1);
                    if (model.i_Number.ToString().Length != Global.Params.NumberLen || Global.Params.strNumHead.IndexOf(str) < 0)
                    {
                        mes = Global.Params.strNumHead.Replace(",", "或");
                        throw new Exception("号码长度必须是【" + Global.Params.NumberLen + "】位,且以数字【" + mes + "】开头");
                    }
                    model.BoxID = Global.Params.BoxID;
                    model.i_IsDispatch = 2;
                    model.NumberTypeID = CommControl.PublicEnums.EnumNumberType.手机Wifi.GetHashCode();
                    model.i_Authority = CommControl.PublicEnums.EnumAuthority.国内长途.GetHashCode();
                    model.i_supplementSerive = MBoxSDK.ConfigSDK.SPM_DISPATCH | MBoxSDK.ConfigSDK.SPM_TELEAGENT | MBoxSDK.ConfigSDK.SPM_AUTO_RECORDING;
                    List<DB_Talk.Model.m_Member> temp = BLL.GetModelList(string.Format(" i_flag=0 and  i_Number='{0}' and BoxID='{1}'", model.i_Number, model.BoxID));
                    if (preModel != null)  //修改
                    {
                        model.ID = preModel.ID;
                        if (temp != null && temp.Count > 0)
                        {
                            //判断是否存在重复的号码
                            //if (model.ID != temp[0].ID)
                            //{
                            //    mes = (string.Format("数据库中号码【{0}】已存在!", model.i_Number));
                            //    throw new Exception(mes);
                            //}
                            //不需要修改
                            if (model.ID == temp[0].ID && temp[0].i_Number == model.i_Number
                                          && temp[0].i_NuPassword == model.i_NuPassword)
                            {
                                model = null;
                            }
                        }
                    }
                    else  //新增
                    {
                        if (temp != null && temp.Count > 0)
                        {
                            mes = (string.Format("数据库中号码【{0}】已存在!", model.i_Number));
                            throw new Exception(mes);
                        }
                    }
                    //NewlstMember.Add(model);
                }
                else
                {
                    mes = "【" + txtDispatch.Text.Trim() + "】名称为空或者号码不合法";
                    throw new Exception(mes);
                }
            }
            catch (Exception ex)
            {
                model = null;
                throw new Exception(ex.Message);
            }
            //return model;
        }
        private void GetModel()
        {
            NewBoxModel.ID = PreBoxModel.ID;
            if (txtDispatchCenter.Text.Trim() == "")
                throw new Exception("调度中心号码不能为空");
            else
                NewBoxModel.i_DispatchNumber = int.Parse(txtDispatchCenter.Text.Trim());
            if (TxtEmergencyNumber.Text.Trim() == "")
                throw new Exception("紧急呼叫号码不能为空");
            else
                NewBoxModel.i_EmergencyNumber = int.Parse(TxtEmergencyNumber.Text.Trim());

            if (NewBoxModel.i_DispatchNumber==NewBoxModel.i_EmergencyNumber )
            {
                throw new Exception("调度中心号码不能和紧急呼叫号码相同");
            }
            if (chkNumHead.EditValue.ToString() == "")
                throw new Exception("内部分机首位码不能为空");
            else
                NewBoxModel.vc_NumberHead = chkNumHead.EditValue.ToString().Replace(" ","");
            if (txtNumberLen.Text.Trim() == "")
                throw new Exception("内部分机号码长度不能为空");
            else
                NewBoxModel.i_NumberLen = int.Parse(txtNumberLen.Text.Trim());
            Global.Params.NumberLen = NewBoxModel.i_NumberLen.Value;
            Global.Params.strNumHead = chkNumHead.EditValue.ToString().Replace(" ","");

            //检查调度号码
            NewlstMember = new List<DB_Talk.Model.m_Member>();
            string mes = "";
            for (int i = 0; i < DispatchCount; i++)
            {
                DB_Talk.Model.m_Member model = new DB_Talk.Model.m_Member();
                model.vc_Name = dgvList.Rows[i].Cells["colName"].Value==null?"":dgvList.Rows[i].Cells["colName"].Value.ToString();
                int num = 0;
                if (dgvList.Rows[i].Cells["colNumber"].Value != null && int.TryParse(dgvList.Rows[i].Cells["colNumber"].Value.ToString(), out num))
                    model.i_Number = num;
                if (model.vc_Name != "" && model.i_Number > 0)
                {
                    string str = model.i_Number.ToString().Substring(0, 1);
                    if (model.i_Number.ToString().Length != Global.Params.NumberLen || Global.Params.strNumHead.IndexOf(str) < 0)
                    {
                        mes = Global.Params.strNumHead.Replace(",", "或");
                        throw new Exception("号码长度必须是【" + Global.Params.NumberLen + "】位,且以数字【" + mes + "】开头");
                    }

                    if (model.i_Number==NewBoxModel.i_DispatchNumber)
                    {
                        throw new Exception("手柄号码不能和调度中心号码相同!");
                    }
                    if( model.i_Number==NewBoxModel.i_EmergencyNumber)
                    {
                        throw new Exception("手柄号码不能和紧急呼叫号码相同!");
                    }
                    model.BoxID = Global.Params.BoxID;
                    model.i_IsDispatch = 1;
                    model.NumberTypeID = CommControl.PublicEnums.EnumNumberType.手机Wifi.GetHashCode();
                    model.i_Authority = CommControl.PublicEnums.EnumAuthority.国内长途.GetHashCode();
                    model.i_supplementSerive = MBoxSDK.ConfigSDK.SPM_DISPATCH | MBoxSDK.ConfigSDK.SPM_TELEAGENT | MBoxSDK.ConfigSDK.SPM_AUTO_RECORDING;
                    DB_Talk.Model.m_Member preModel = dgvList.Rows[i].Tag as DB_Talk.Model.m_Member;
                    List<DB_Talk.Model.m_Member> temp = BLL.GetModelList(string.Format(" i_flag=0 and  i_Number='{0}' and BoxID='{1}'", model.i_Number, model.BoxID));
                    if (preModel != null)  //修改
                    {
                        model.ID = preModel.ID;
                        if (temp != null && temp.Count > 0)
                        {
                            if (model.ID != temp[0].ID)
                            {
                                mes = (string.Format("数据库中号码【{0}】已存在!", model.i_Number));
                                throw new Exception(mes);
                            }
                        }
                    }
                    else  //新增
                    {
                        if (temp != null && temp.Count > 0)
                        {
                            mes = (string.Format("数据库中号码【{0}】已存在!", model.i_Number));
                            throw new Exception(mes);
                        }
                    }
                    NewlstMember.Add(model);
                }
                else
                {
                    mes = "【" + dgvList.Rows[i].Cells["colDispatch"].Value + "】名称为空或者号码不合法";
                    throw new Exception(mes);
                }
            }
        }
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public DB_Talk.Model.m_Member DataRowToModel(DataRow row)
        {
            DB_Talk.Model.m_Member model = new DB_Talk.Model.m_Member();
            if (row != null)
            {
                try
                {
                    model.BoxID = Global.Params.BoxID;
                    //model.NumberTypeID = 4;// CommControl.PublicEnums.EnumNumberType.SIP.GetHashCode();
                    //姓名
                    string strName = row["用户姓名"].ToString().Replace(" ", "");
                    bool CheckLen = strName.Length <=  Global.Params.ConfigModel.SystemConfig.MaxNameTextLengh;
                    if (Global.Params.ConfigModel.SystemConfig.MaxNameTextLengh == 0)
                        CheckLen = true;

                    if (row["用户姓名"] != null && strName != "" &&
                        CheckLen && 
                        checkFormat(false, ref strName, false))
                    {
                        model.vc_Name = strName;
                    }
                    else
                    {
                        return model=null;
                    }

                    //电话
                    string strTel = row["电话号码"].ToString().Replace(" ","");
                    if (row["电话号码"] != null && strTel != "" &&
                        strTel.Length == Global.Params.NumberLen &&
                        checkFormat(true, ref strTel, false))
                    {
                        string str = strTel.Trim().Substring(0, 1);
                        if (Global.Params.strNumHead.IndexOf(str) < 0)
                        {
                            return model = null;
                        }
                        model.i_Number = int.Parse(strTel);

                    }
                    else
                    {
                        return model = null;
                    }
                    if (model.i_Number > Math.Pow(10, Global.Params.NumberLen) - 1) return model = null;

                    //部门
                    string strDept = row["部门"].ToString().Replace(" ", "");
                    if (row["部门"] != null && strDept != "" && strDept.Length <= 10)
                    {
                       
                        DB_Talk.Model.m_Departments modelDept = new DB_Talk.BLL.m_Departments().GetModel("i_Flag=0 and vc_Name='" + strDept + "'");
                        if (modelDept != null)
                            model.DepartmentID = modelDept.ID;
                        else  //无部门时添加部门
                        {
                            modelDept = new DB_Talk.Model.m_Departments();
                            modelDept.vc_Name = strDept;
                            model.DepartmentID = new DB_Talk.BLL.m_Departments().Add(modelDept, true);
                        }
                    }
                    

                    //用户权限
                    if (row["用户权限"] != null && row["用户权限"].ToString() != "")
                    {
                        string strAuthority = row["用户权限"].ToString().Replace(" ", "");
                        switch (strAuthority)
                        {
                            case "国际长途":
                                model.i_Authority = 0;
                                break;
                            case "国内长途":
                                model.i_Authority = 1;
                                break;
                            case "市话":
                                model.i_Authority = 2;
                                break;
                            case "内部分机":
                                model.i_Authority = 3;
                                break;
                            case "禁止主叫":
                                model.i_Authority = 4;
                                break;

                            default:
                                return model = null;
                        }
                    }
                    else
                    {
                        return model = null;
                    }

                    //号码类型
                    if (row["电话类型"] != null && row["电话类型"].ToString() != "")
                    {
                        string strTellType = row["电话类型"].ToString().Replace(" ", "").ToUpper();
                        switch (strTellType)
                        {
                            case "WIFI手机":
                                model.i_TellType = PublicEnums.EnumTelType.WiFi手机.GetHashCode();
                                model.NumberTypeID = PublicEnums.EnumNumberType.手机Wifi.GetHashCode();
                                model.i_NuPasswordType = PublicEnums.EnumTelPasswordType.增加.GetHashCode();
                                model.i_NuPassword = (uint)model.i_Number;
                                break;
                            case "3G手机":
                                if (Global.Params.BoxType == MBoxSDK.ConfigSDK.EnumDeviceType.T_HT8000_3G)  //目前只有800B支持3G)
                                {
                                    model.i_TellType = PublicEnums.EnumTelType.G3G手机.GetHashCode();
                                    model.NumberTypeID = PublicEnums.EnumNumberType.手机3G.GetHashCode();
                                    if (row["标示码"] != null && row["标示码"].ToString() != "")
                                    {
                                        string strUmtsImsi = row["标示码"].ToString().Replace(" ", "");
                                        if (strUmtsImsi.Length == Global.Params.UmtsImsiLen)
                                            model.vc_UmtsImsi = strUmtsImsi;
                                        else
                                            return model = null;
                                    }
                                }
                                else
                                {
                                    return model = null;
                                }
                              
                                break;
                            case "固话":  //wifi和固话 默认密码为增加模式 与号码相同
                                 model.i_TellType = PublicEnums.EnumTelType.固话.GetHashCode();
                                 model.NumberTypeID = PublicEnums.EnumNumberType.固话.GetHashCode();
                                 model.i_NuPasswordType = PublicEnums.EnumTelPasswordType.增加.GetHashCode();
                                 model.i_NuPassword = (uint)model.i_Number;
                                break;
                            case "广播":  //wifi和固话 默认密码为增加模式 与号码相同
                                model.i_TellType = PublicEnums.EnumTelType.广播.GetHashCode();
                                model.NumberTypeID = PublicEnums.EnumNumberType.固话.GetHashCode();  //固话、wifi手机、广播=4
                                model.i_NuPasswordType = PublicEnums.EnumTelPasswordType.增加.GetHashCode();
                                model.i_NuPassword = (uint)model.i_Number;
                                if (row["广播IP"] != null && row["广播IP"].ToString() != "")
                                {
                                    string strIP = row["广播IP"].ToString().Replace(" ", "");
                                    if (Global.Methods.checkIP(strIP))
                                    {
                                        model.vc_IP = strIP;
                                    }
                                    else
                                        return model = null;
                                }
                                break;
                            default:
                                return model = null;
                        }
                    }
                    else
                    {
                        return model = null;
                    }
                    //if (model.i_Number < Math.Pow(10, Global.Params.NumberLen-1) - 1) return model = null;
                }
                catch
                {
                    model = null;
                }
            }
            return model;
        }
Exemplo n.º 6
0
        private void ModifyMuti()
        {
            List<DB_Talk.Model.m_Member> lst = _BLL.GetModelList(string.Format(" i_flag=0 and  i_Number='{0}' and BoxID='{1}'", _mModel.i_Number, _mModel.BoxID));

            int ModifyOk = 0;
            int ModifyNo = 0;
           
            foreach (DB_Talk.Model.v_Member vmodel in _lstvModel)
            {
                _mModel = _BLL.GetModel(vmodel.ID);
                _mPreModel = (DB_Talk.Model.m_Member)_mModel.Clone();
                preNumber = int.Parse(_mModel.i_Number.ToString());
                GetModelMuti(ref _mModel);
                string mes = "";
                bool bModify = ModifyTel(out mes);
                if (bModify && _BLL.Update(_mModel))
                {
                    UpdateAssociateNum(_mModel);
                    ModifyOk++;
                    //CommControl.MessageBoxEx.MessageBoxEx.Show("编辑成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    CommControl.SystemLogBLL.WriteLog(Global.Params.UserID, Global.Params.BoxID, CommControl.SystemLogBLL.EnumLogAction.Update, "编辑", "编辑了人员:" + _mModel.vc_Name, "");
                    //this.DialogResult = DialogResult.OK;
                    //this.Close();
                }
                else
                {
                    ModifyNo++;
                    //CommControl.MessageBoxEx.MessageBoxEx.Show(mes, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            string mess = "";
            if (ModifyOk > 0)
            {
                mess = ModifyOk + "个编辑成功!\r\n";
                this.DialogResult = DialogResult.OK;
            }
            else if (ModifyNo>0)
            {
                mess = ModifyOk + "个编辑失败!";
            }
            CommControl.MessageBoxEx.MessageBoxEx.Show(mess, "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            this.Close();

           
        }
Exemplo n.º 7
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                if (_operate != 2)  //添加或者修改1个
                    GetModel();
                else  //编辑多个
                {
                    _mModel = _BLL.GetModel(_lstvModel[0].ID);
                    GetModelMuti(ref _mModel );
                }
            }
            catch (Exception ex)
            {
                CommControl.MessageBoxEx.MessageBoxEx.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            try
            {
                if (btnOK.Text == "添加")
                {
                    if (addCount > 0)
                        AddMutiTel();
                    else
                    {
                        if (string.IsNullOrEmpty(_mModel.vc_Name)) _mModel.vc_Name=_mModel.i_Number.ToString();
                        Add();
                    }
                }
                else if (btnOK.Text == "编辑")
                {
                    Modify();
                }
                else if (btnOK.Text == "编辑多个")
                {
                    ModifyMuti();
                }
            }
            catch
            {
            }

        }