示例#1
0
 private void btnSaveSetting_Click(object sender, EventArgs e)
 {
     using (BugTraceEntities context = new BugTraceEntities(EntityContextHelper.GetEntityConnString()))
     {
         string currUser = UserInfo.GetInstence().UserCode;
         var    userExt  = context.SYS_UserExt.Where(p => p.UserCode == currUser).FirstOrDefault();
         if (userExt == null)
         {
             userExt               = new SYS_UserExt();
             userExt.UserCode      = currUser;
             userExt.Host          = this.txtHOST.Text.Trim();
             userExt.Port          = this.txtPORT.Text.Trim();
             userExt.ServiceName   = this.txtSERVICENAME.Text.Trim();
             userExt.Username      = this.txtUsername.Text.Trim();
             userExt.Password      = this.txtPassword.Text.Trim();
             userExt.TempTableName = this.txtTableName.Text.Trim();
             context.SYS_UserExt.Add(userExt);
             context.SaveChanges();
         }
         else
         {
             userExt.Host          = this.txtHOST.Text.Trim();
             userExt.Port          = this.txtPORT.Text.Trim();
             userExt.ServiceName   = this.txtSERVICENAME.Text.Trim();
             userExt.Username      = this.txtUsername.Text.Trim();
             userExt.Password      = this.txtPassword.Text.Trim();
             userExt.TempTableName = this.txtTableName.Text.Trim();
             context.SaveChanges();
         }
         MessageBox.Show("保存配置成功!");
     }
 }
示例#2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            #region 验证
            if (string.IsNullOrWhiteSpace(this.txtTel.Text))
            {
                MessageBox.Show("电话不能为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.txtTel.Focus();
                return;
            }
            if (string.IsNullOrWhiteSpace(this.txtQQ.Text))
            {
                MessageBox.Show("QQ不能为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.txtQQ.Focus();
                return;
            }
            #endregion
            using (BugTraceEntities context = new BugTraceEntities(EntityContextHelper.GetEntityConnString()))
            {
                string strProject = string.Empty;
                if (this.lbProjectList.Items.Count > 0)
                {
                    foreach (var item in this.lbProjectList.Items)
                    {
                        strProject = strProject + item.ToString().Split(')')[0].Replace("(", "") + ",";
                    }
                    //strProject = strProject.Substring(0, strProject.Length-1);
                }

                string userCode    = UserInfo.GetInstence().UserCode;
                var    currUserExt = context.SYS_UserExt.Where(p => p.UserCode == userCode).FirstOrDefault();
                if (currUserExt != null)
                {
                    if (!string.IsNullOrWhiteSpace(this.txtEmailPassword.Text))
                    {
                        currUserExt.EmailPassword = Encrypt.TripleDESEncrypting(this.txtEmailPassword.Text);
                        currUserExt.CommonProject = strProject;
                        context.SaveChanges();
                    }
                }
                else
                {
                    currUserExt          = new SYS_UserExt();
                    currUserExt.UserCode = userCode;
                    if (!string.IsNullOrWhiteSpace(this.txtEmailPassword.Text))
                    {
                        currUserExt.EmailPassword = Encrypt.TripleDESEncrypting(this.txtEmailPassword.Text);
                    }
                    currUserExt.CommonProject = strProject;
                    context.SYS_UserExt.Add(currUserExt);
                    context.SaveChanges();
                }
                var currUser = context.SYS_User.Where(p => p.UserCode == userCode).FirstOrDefault();
                if (currUser != null && !string.IsNullOrWhiteSpace(this.cbxProject.SelectedValue.ToString()))
                {
                    currUser.DefaultProjectCode = this.cbxProject.SelectedValue.ToString();
                    currUser.QQ  = this.txtQQ.Text;
                    currUser.Tel = this.txtTel.Text;
                    context.SaveChanges();
                    UserInfo.GetInstence().DefaultProjectCode = this.cbxProject.SelectedValue.ToString();
                    UserInfo.GetInstence().QQ  = this.txtQQ.Text;
                    UserInfo.GetInstence().Tel = this.txtTel.Text;
                    MessageBox.Show("保存成功!");
                    try
                    {
                        bool isExist = FormSingle.IsExist(typeof(ProblemTraceList));
                        if (isExist)
                        {
                            var tempForm = FormSingle.GetForm(typeof(ProblemTraceList));
                            tempForm.Close();
                            tempForm = FormSingle.GetForm(typeof(ProblemTraceList));
                            tempForm.ShowNormal(this.ParentForm);
                        }
                        bool isExistPPL = FormSingle.IsExist(typeof(ProjectPlanList));
                        if (isExistPPL)
                        {
                            var tempForm = FormSingle.GetForm(typeof(ProjectPlanList));
                            tempForm.Close();
                            tempForm = FormSingle.GetForm(typeof(ProjectPlanList));
                            tempForm.ShowNormal(this.ParentForm);
                        }
                        bool isExistIndex = FormSingle.IsExist(typeof(FrmIndex));
                        if (isExistIndex)
                        {
                            var tempForm = FormSingle.GetForm(typeof(FrmIndex)) as FrmIndex;
                            tempForm.Close();
                            tempForm = FormSingle.GetForm(typeof(FrmIndex)) as FrmIndex;
                            tempForm.ShowNormal(this.ParentForm);
                        }
                    }
                    catch (Exception ex)
                    {
                        MyLog.LogError("保存个人设置后刷新各窗口失败!", ex);
                    }

                    this.Close();
                }
            }
        }