public FrmChangePass(TblUser _loggedUser)
        {
            InitializeComponent();
            this.loggedUser = _loggedUser;

            label1.Text = loggedUser.UserName;
            label2.Text = loggedUser.FullName;
        }
        public APIResult UpdateUser(TblUser data)
        {
            APIResult res = new APIResult();
            using (Sonartez_server db = new Sonartez_server(connectionString))
            {
                var matchedObj = (from c in db.TblUser
                                  where c.UserID == data.UserID
                                  select c).SingleOrDefault();

                if (matchedObj == null)
                {
                    try
                    {
                        // does not exist
                        Table<TblUser> TblObj = db.TblUser;
                        data.ServerUpdate = DateTime.Now;
                        TblObj.InsertOnSubmit(data);
                        TblObj.Context.SubmitChanges();

                        res.UpdateDate = data.ServerUpdate.Value;
                        res.Success = true;

                    }
                    catch (Exception ex)
                    {
                        res.Message = ex.Message;
                        res.Success = false;
                    }
                }
                else
                {
                    try
                    {
                        matchedObj.Active = data.Active;
                        matchedObj.Email = data.Email;
                        matchedObj.FullName = data.FullName;
                        matchedObj.LastLoginTime = data.LastLoginTime;
                        matchedObj.Password = data.Password;
                        matchedObj.PhoneNumber = data.PhoneNumber;
                        matchedObj.UserName = data.UserName;
                        matchedObj.ServerUpdate = DateTime.Now;
                        matchedObj.UpdateDate = data.UpdateDate;
                        db.SubmitChanges();

                        res.UpdateDate = data.UpdateDate.Value;
                        res.Success = true;
                    }
                    catch (Exception ex)
                    {
                        res.Message = ex.Message;
                        res.Success = false;
                    }
                }

            }
            return res;
        }
Beispiel #3
0
 partial void DeleteTblUser(TblUser instance);
Beispiel #4
0
 partial void UpdateTblUser(TblUser instance);
Beispiel #5
0
 partial void InsertTblUser(TblUser instance);
Beispiel #6
0
        private void btnEdit_Click(object sender, EventArgs e)
        {
            if (grvMainInfo.SelectedRowsCount > 0)
            {
                var obj = (TblUser)lstUser.ToList()[grvMainInfo.GetFocusedDataSourceRowIndex()];

                //var obj = (TblInfor)lstShowData.ToList()[grvMainInfo.GetDataSourceRowIndex(e.FocusedRowHandle)];
                if (obj != null)
                {
                    editFlag = true;
                    panel1.Height = 200;
                    panelEdit.Visible = true;

                    btnCreate.Enabled = false;
                    btnDelete.Enabled = false;

                    gridControl1.Enabled = false;

                    currentUser = user.GetUserByID(obj.UserID);
                    txtEmail.Text = currentUser.Email;
                    txtFullName.Text = currentUser.FullName;
                    txtPass.Enabled = false;
                    txtPass.Text = currentUser.Password;
                    txtPhone.Text = currentUser.PhoneNumber;
                    txtUserName.Text = currentUser.UserName;
                    txtUserName.Enabled = false;

                    chkActive.Checked = (currentUser.Active.Value == 1);

                    if (currentUser.Permission == Permission.Normal)
                        radioTraCuu.Checked = true;
                    if (currentUser.Permission == Permission.Approval)
                        radioKiemDuyet.Checked = true;
                    if (currentUser.Permission == Permission.Admin)
                        radioQuanLy.Checked = true;
                }
                else
                {
                    clearForm();
                    editFlag = false;
                }

            }
        }
Beispiel #7
0
 private void UserManager_Load(object sender, EventArgs e)
 {
     panelEdit.Visible = false;
     currentUser = null;
     panel1.Height = 40;
     LoadUser();
 }
Beispiel #8
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (!validFormData())
            {
                DevExpress.XtraEditors.XtraMessageBox.Show(DevExpress.LookAndFeel.UserLookAndFeel.Default, this.FindForm(),"Dữ liệu không đủ hoặc chính xác, hãy kiểm tra lại", "Không thể thêm mới " + txtFullName.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);

                return;
            }

            if (createNewFlag)
            {
                currentUser = new TblUser();
                currentUser.UserID = Guid.NewGuid();
                currentUser.Active = chkActive.Checked ? 1 : 0;

                currentUser.Email = txtEmail.Text;
                currentUser.FullName = txtFullName.Text;
                currentUser.Password = txtPass.Text;
                currentUser.PhoneNumber = txtPhone.Text;
                currentUser.UserName = txtUserName.Text;

                if (radioKiemDuyet.Checked)
                    currentUser.Permission = Permission.Approval;
                if (radioQuanLy.Checked)
                    currentUser.Permission = Permission.Admin;

                if (radioTraCuu.Checked)
                    currentUser.Permission = Permission.Normal;

                bool complete = false;
                try
                {
                    user.SaveUser(currentUser);
                    complete = true;
                }
                catch (Exception ex)
                {
                    //MessageBox.Show(ex.Message);
                    DevExpress.XtraEditors.XtraMessageBox.Show(DevExpress.LookAndFeel.UserLookAndFeel.Default, this.FindForm(), ex.Message, "Không thể thêm mới " + txtFullName.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);

                }

                if (complete)
                {
                    //MessageBox.Show("Thêm mới thành công");
                    DevExpress.XtraEditors.XtraMessageBox.Show(DevExpress.LookAndFeel.UserLookAndFeel.Default, this.FindForm(), "Thêm mới thành công  " + txtFullName.Text, "Thành công ", MessageBoxButtons.OK, MessageBoxIcon.Information);

                    ResetInCancel();

                    LoadUser();
                }

            }
                if (editFlag)
                {
                    currentUser.Active = chkActive.Checked ? 1 : 0;
                    if (radioKiemDuyet.Checked)
                        currentUser.Permission = Permission.Approval;
                    if (radioQuanLy.Checked)
                        currentUser.Permission = Permission.Admin;

                    if (radioTraCuu.Checked)
                        currentUser.Permission = Permission.Normal;
                    currentUser.Email = txtEmail.Text;
                    currentUser.FullName = txtFullName.Text;
                    currentUser.PhoneNumber = txtPhone.Text;

                    bool complete = false;
                    try
                    {
                        user.UpdateUser(currentUser);
                        complete = true;
                    }
                    catch (Exception ex)
                    {
                        //MessageBox.Show(ex.Message);
                        DevExpress.XtraEditors.XtraMessageBox.Show(DevExpress.LookAndFeel.UserLookAndFeel.Default, this.FindForm(), ex.Message, "Không thể cập nhập " + txtFullName.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);

                    }

                    if (complete)
                    {

                        DevExpress.XtraEditors.XtraMessageBox.Show(DevExpress.LookAndFeel.UserLookAndFeel.Default, this.FindForm(), "Thành công ", "Cập nhập thành công  " + txtFullName.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);

                        ResetInCancel();

                        LoadUser();
                    }

                }
        }