예제 #1
0
        //保存数据
        private void Save()
        {
            #region 验证数据输入的正确性
            string name = txtContName.Caption.Trim();
            if (name.Length == 0)
            {
                MessageBoxEx.Show("请填写联系人姓名!");
                txtContName.Focus();
                return;
            }
            if (cboContPost.SelectedValue == null)
            {
                MessageBoxEx.Show("请选择职务!");
                cboContPost.Focus();
                return;
            }
            string email = txtContEmail.Caption.Trim();
            //验证email
            if (email.Length != 0)
            {
                if (!Utility.Common.Validator.IsEmail(email))
                {
                    MessageBoxEx.Show("email验证错误,请填写正确的email");
                    txtContEmail.Focus();
                    return;
                }
            }
            //验证手机号
            string phone = txtContPhone.Caption.Trim();
            if (phone.Length > 0)
            {
                if (!Utility.Common.Validator.IsMobile(phone))
                {
                    MessageBoxEx.Show("手机号输入有误,请输入正确的手机号");
                    txtContPhone.Focus();
                    return;
                }
            }
            #endregion

            if (MessageBoxEx.Show("确认要保存吗?", "提示", MessageBoxButtons.OKCancel) != DialogResult.OK)
            {
                return;
            }
            #region  加密
            //Dictionary<string, string> dic = new Dictionary<string, string>();
            //dic.Add("cont_name", name);//姓名
            //dic.Add("cont_post", cboContPost.SelectedValue.ToString());//职务
            //dic.Add("cont_phone",EncryptByDB.GetEncFieldValue( phone));//手机
            //dic.Add("cont_tel", txtContTel.Caption);//电话
            //dic.Add("cont_email", email);//email
            //dic.Add("sex", rbMan.Checked?"1":"0");//性别
            //dic.Add("nation", CommonCtrl.IsNullToString(cboNation.SelectedValue));//民族
            ////dic.Add("is_default", chkIsDefault.Checked ? "1" : "0");//是否默认
            //dic.Add("remark", txtRemark.Caption);//备注
            //dic.Add("enable_flag", ((int)DataSources.EnumEnableFlag.USING).ToString());//标识未删除
            ////判断窗体状态
            //if (status == WindowStatus.Add || status == WindowStatus.Copy)
            //{
            //    dic.Add("status", ((int)DataSources.EnumStatus.Start).ToString());
            //    dic.Add("data_source", ((int)DataSources.EnumDataSources.SELFBUILD).ToString());
            //    dic.Add("cont_id", Guid.NewGuid().ToString());
            //    dic.Add("create_by", GlobalStaticObj.UserID);
            //    dic.Add("create_time", DateTime.UtcNow.Ticks.ToString());
            //    if (DBHelper.Submit_AddOrEdit("新增联系人", "tb_contacts", "", "", dic))
            //    {
            //        MessageBoxEx.Show("保存成功!");
            //        uc.BindData(contID);
            //        deleteMenuByTag(this.Tag.ToString(), uc.Name);
            //    }
            //    else
            //    {
            //        MessageBoxEx.Show("保存失败!");
            //    }
            //}
            //else if (status == WindowStatus.Edit)//编辑
            //{
            //    dic.Add("update_by", GlobalStaticObj.UserID);
            //    dic.Add("update_time", DateTime.UtcNow.Ticks.ToString());
            //    if (DBHelper.Submit_AddOrEdit("修改联系人", "tb_contacts", "cont_id", contID, dic))
            //    {
            //        MessageBoxEx.Show("修改成功!");
            //        uc.BindData(contID);
            //        deleteMenuByTag(this.Tag.ToString(), uc.Name);
            //    }
            //    else
            //    {
            //        MessageBoxEx.Show("修改失败!");
            //    }
            //}
            #endregion
            Dictionary <string, ParamObj> dic = new Dictionary <string, ParamObj>();
            //dic.Add("cont_name",new ParamObj("cont_name", name,SysDbType.NVarChar,40));//姓名
            //dic.Add("cont_post", new ParamObj("cont_post", cboContPost.SelectedValue, SysDbType.NVarChar, 40));//职务
            //dic.Add("cont_phone",new ParamObj("cont_phone", EncryptByDB.GetEncFieldValue(phone),SysDbType.varbi);//手机
            //dic.Add("cont_tel", txtContTel.Caption);//电话
            //dic.Add("cont_email", email);//email
            //dic.Add("sex", rbMan.Checked ? "1" : "0");//性别
            //dic.Add("nation", CommonCtrl.IsNullToString(cboNation.SelectedValue));//民族
            ////dic.Add("is_default", chkIsDefault.Checked ? "1" : "0");//是否默认
            //dic.Add("remark", txtRemark.Caption);//备注
            //dic.Add("enable_flag", ((int)DataSources.EnumEnableFlag.USING).ToString());//标识未删除
            List <SysSQLString> listSql = new List <SysSQLString>();
            SysSQLString        sysSql  = new SysSQLString();
            sysSql.cmdType = CommandType.Text;
            sysSql.Param   = new Dictionary <string, string>();
            //判断窗体状态
            if (status == WindowStatus.Add || status == WindowStatus.Copy)
            {
                //dic.Add("status", ((int)DataSources.EnumStatus.Start).ToString());
                //dic.Add("data_source", ((int)DataSources.EnumDataSources.SELFBUILD).ToString());
                //dic.Add("cont_id", Guid.NewGuid().ToString());
                //dic.Add("create_by", GlobalStaticObj.UserID);
                //dic.Add("create_time", DateTime.UtcNow.Ticks.ToString());
                string cont_id = Guid.NewGuid().ToString();
                sysSql.sqlString = string.Format(@"INSERT INTO [tb_contacts]
           ([cont_id]
           ,[cont_name]
           ,[cont_post]
           ,[cont_tel]
           ,[cont_email]
           ,[sex]
           ,[nation]
           ,[remark]
           ,[enable_flag]
           ,[data_source]
           ,[status]
           ,[create_by]
           ,[create_time]
           ,[cont_phone])
     VALUES
           ('{0}','{1}','{2}',{3},'{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}',{12},{13})",
                                                 cont_id.ToString(), name, cboContPost.SelectedValue,
                                                 EncryptByDB.GetEncFieldValue(txtContTel.Caption), email, rbMan.Checked ? "1" : "0", cboNation.SelectedValue, txtRemark.Caption, (int)DataSources.EnumEnableFlag.USING,
                                                 (int)DataSources.EnumStatus.Start, (int)DataSources.EnumDataSources.SELFBUILD, GlobalStaticObj.UserID,
                                                 Common.LocalDateTimeToUtcLong(DateTime.Now), EncryptByDB.GetEncFieldValue(phone));
                listSql.Add(sysSql);
                if (DBHelper.BatchExeSQLStringMultiByTrans("新增联系人", listSql))
                {
                    //Model.tb_contacts_ex tb_contacts=new Model.tb_contacts_ex ();
                    //tb_contacts.cont_email = txtContEmail.Caption.Trim();
                    //tb_contacts.cont_id = cont_id;
                    //tb_contacts.cont_name = txtContName.Caption.Trim();
                    //tb_contacts.cont_phone = txtContPhone.Caption.Trim();
                    //tb_contacts.cont_post = cboContPost.SelectedValue.ToString();
                    //tb_contacts.cont_tel = txtContTel.Caption.Trim();
                    //DBHelper.WebServHandler("", EnumWebServFunName.UpLoadCcontact, tb_contacts);
                    MessageBoxEx.Show("保存成功!");
                    uc.BindData(contID);
                    deleteMenuByTag(this.Tag.ToString(), uc.Name);
                }
                else
                {
                    MessageBoxEx.Show("保存失败!");
                }
            }
            else if (status == WindowStatus.Edit)//编辑
            {
                //dic.Add("update_by", GlobalStaticObj.UserID);
                //dic.Add("update_time", DateTime.UtcNow.Ticks.ToString());
                //if (DBHelper.Submit_AddOrEdit("修改联系人", "tb_contacts", "cont_id", contID, dic))
                //{
                //    MessageBoxEx.Show("修改成功!");
                //    uc.BindData(contID);
                //    deleteMenuByTag(this.Tag.ToString(), uc.Name);
                //}
                //else
                //{
                //    MessageBoxEx.Show("修改失败!");
                //}
                sysSql.sqlString = string.Format(@"update tb_contacts set cont_name='{0}',cont_post='{1}',cont_phone={2},cont_tel={3},cont_email='{4}',sex='{5}',
                                    nation='{6}',remark='{7}',update_by='{8}',update_time='{9}' where cont_id='{10}'", name, cboContPost.SelectedValue, EncryptByDB.GetEncFieldValue(phone),
                                                 EncryptByDB.GetEncFieldValue(txtContTel.Caption.Trim()), email, rbMan.Checked ? "1" : "0", cboNation.SelectedValue, txtRemark.Caption,
                                                 GlobalStaticObj.UserID, Common.LocalDateTimeToUtcLong(DateTime.Now), contID);
                listSql.Add(sysSql);
                if (DBHelper.BatchExeSQLStrMultiByTransNoLogNoBackup("修改联系人", listSql))
                {
                    MessageBoxEx.Show("修改成功!");
                    uc.BindData(contID);
                    deleteMenuByTag(this.Tag.ToString(), uc.Name);
                }
                else
                {
                    MessageBoxEx.Show("修改失败!");
                }
            }
        }
예제 #2
0
        //保存
        private bool Save()
        {
            Dictionary <string, ParamObj> dic     = new Dictionary <string, ParamObj>();
            List <SysSQLString>           listSql = new List <SysSQLString>();
            //List<SQLObj> listSql = new List<SQLObj>();
            SysSQLString sysSql = new SysSQLString();

            //SQLObj obj = new SQLObj();
            sysSql.cmdType = CommandType.Text;
            sysSql.Param   = new Dictionary <string, string>();
            //obj.cmdType = CommandType.Text;
            //obj.Param = new Dictionary<string, ParamObj>();
            string cont_id = Guid.NewGuid().ToString();

            //obj.Param.Add("cont_id", new ParamObj("cont_id", cont_id.ToString(), SysDbType.VarChar));//cont_id
            //obj.Param.Add("cont_name", new ParamObj("cont_name", txtContName.Caption, SysDbType.VarChar));//cont_name
            //obj.Param.Add("enable_flag", new ParamObj("enable_flag", (int)DataSources.EnumEnableFlag.USING, SysDbType.Int));//enable_flag
            //obj.Param.Add("data_source", new ParamObj("data_source", (int)DataSources.EnumDataSources.SELFBUILD, SysDbType.Int));//data_source
            //obj.Param.Add("status", new ParamObj("status", (int)DataSources.EnumStatus.Start, SysDbType.Int, 5));//status
            //obj.Param.Add("create_by", new ParamObj("create_by", GlobalStaticObj.UserID, SysDbType.VarChar));//create_by
            //obj.Param.Add("create_time", new ParamObj("create_time", Common.LocalDateTimeToUtcLong(DateTime.Now), SysDbType.DateTime));//create_time

            sysSql.sqlString = string.Format(@"INSERT INTO [tb_contacts]
                        ([cont_id]
                        ,[cont_name]       
                        ,[cont_tel]
                        ,[enable_flag]
                        ,[data_source]
                        ,[status]
                        ,[create_by]
                        ,[create_time]
                        ,[cont_phone])
                        VALUES
                        ('{0}','{1}',{2},'{3}','{4}','{5}','{6}','{7}',{8})",
                                             cont_id.ToString(),                                  //cont_id
                                             txtContName.Caption,                                 //cont_name
                                             EncryptByDB.GetEncFieldValue(txtContTel.Caption),    //cont_tel
                                             (int)DataSources.EnumEnableFlag.USING,               //enable_flag
                                             (int)DataSources.EnumDataSources.SELFBUILD,          //data_source
                                             (int)DataSources.EnumStatus.Start,                   //status
                                             GlobalStaticObj.UserID,                              //create_by
                                             Common.LocalDateTimeToUtcLong(DateTime.Now),         //create_time
                                             EncryptByDB.GetEncFieldValue(txtContPhone.Caption)); //cont_phone
            //            obj.sqlString = string.Format(@"INSERT INTO [tb_contacts]
            //            ([cont_id]
            //            ,[cont_name]
            //            ,[cont_tel]
            //            ,[enable_flag]
            //            ,[data_source]
            //            ,[status]
            //            ,[create_by]
            //            ,[create_time]
            //            ,[cont_phone])
            //            VALUES
            //            (@cont_id,@cont_name,{0},@enable_flag,@data_source,@status,@create_by,@create_time,{1})",
            //            EncryptByDB.GetEncFieldValue(txtContTel.Caption),//cont_tel
            //            EncryptByDB.GetEncFieldValue(txtContPhone.Caption));//cont_phone

            //listSql.Add(obj);
            listSql.Add(sysSql);
            if (DBHelper.BatchExeSQLStringMultiByTrans("新增联系人", listSql))
            {
                ContactsInfo continfo = new ContactsInfo();
                continfo.contDuty  = string.Empty;
                continfo.contID    = cont_id;
                continfo.contName  = txtContName.Caption;
                continfo.contPhone = txtContTel.Caption;
                continfo.crmId     = string.Empty;
                //保存成功后触发保存事件
                if (SaveEvent != null)
                {
                    SaveEvent.BeginInvoke(continfo, null, null);
                }
                MessageBoxEx.Show("保存成功!");
                return(true);
            }
            else
            {
                MessageBoxEx.Show("保存失败!");
                return(false);
            }
        }