protected override void ShowFormDetail(ActionMode actionMode) { base.ShowFormDetail(actionMode); string UserID = null; if (actionMode != ActionMode.AddNew) { UserID = ((Desktop.Entity.DictionaryDataSet.EmployeeRow)((System.Data.DataRowView)bsList.Current).Row).UserID.ToString(); } var tableUser = oBLUser.Get(); var tableRole = oBLRole.Get(); DictionaryDataSet.UserDataTable dt = new DictionaryDataSet.UserDataTable(); DictionaryDataSet.UserJoinRoleDataTable dtRole = new DictionaryDataSet.UserJoinRoleDataTable(); if (tableUser.Select("UserID = '" + UserID + "'").Count() > 0) { dt.ImportRow(tableUser.Select("UserID = '" + UserID + "'")[0]); dsDictionary.User.Clear(); dsDictionary.Merge(dt); } DataRow[] dr = tableRole.Select("UserID = '" + UserID + "'"); if (dr.Count() > 0) { for (int i = 0; i < dr.Count(); i++) { dtRole.ImportRow(dr[i]); } dsDictionary.Role.Clear(); dsDictionary.Merge(dtRole); } using (var fDetail = new FrmEmployeeDetail()) { fDetail.DsDictionary = dsDictionary; fDetail.BsDetail = bsList; fDetail.objBLDetail = oBL; fDetail.FormActionMode = actionMode; if (fDetail.ShowDialog() != DialogResult.OK) { dsDictionary.Employee.RejectChanges(); } else { dsDictionary.Customer.AcceptChanges(); LoadDataForm(); } } ActiveAndSelectRow(); }
protected override int SaveData() { int result = 1; int resultAccount = 0; bool checkAccount = false; BsDetail.EndEdit(); if (!string.IsNullOrEmpty(txtUserName.Text) && !string.IsNullOrEmpty(txtPassword.Text) && !string.IsNullOrEmpty(txtCofirmPassword.Text)) { if (txtPassword.Text != txtCofirmPassword.Text) { MessageBoxCommon.ShowExclamation("Mật khẩu xác nhận không khớp. Vui lòng kiểm tra lại."); return(0); } checkAccount = true; } //var tableChanged = dsDictionary.Employee.GetChanges(); //if (tableChanged == null) //{ // return (int)EnumResultInsertUpdate.Success; //} //else //{ // if (tableChanged.Rows.Count == 0) // return (int)EnumResultInsertUpdate.Success; //} System.Data.DataRow drObjectChange = ((System.Data.DataRowView)bsDetail.Current).Row; if (drObjectChange != null) { ((Desktop.Entity.DictionaryDataSet.EmployeeRow)drObjectChange).IdentifyNumberIssuedDate = DateTime.Now; result = objBLDetail.InsertUpdate(drObjectChange); if (result == 1 && checkAccount) { DictionaryDataSet.UserDataTable table = new DictionaryDataSet.UserDataTable(); Guid userID = Guid.Empty; Guid UserJoinRoleID = Guid.NewGuid(); if (FormActionMode == ActionMode.AddNew) { DictionaryDataSet.UserRow drUser = table.NewUserRow(); drUser.UserID = Guid.NewGuid(); drUser.UserName = txtUserName.Text; drUser.Password = EncryptUtil.MD5Hash(txtPassword.Text); drUser.DisplayName = txtEmployeeName.Text; drUser.ChangedPasswordTime = DateTime.Now; drUser.Inactive = false; drUser.EmployeeID = ((Desktop.Entity.DictionaryDataSet.EmployeeRow)drObjectChange).EmployeeID; resultAccount = objBLDetail.InsertUpdateUser(drUser); userID = drUser.UserID; UserJoinRoleID = drUser.UserJoinRoleID; } else { DataRow drUser = dsDictionary.User.FindByUserID(userID); resultAccount = objBLDetail.InsertUpdateUser(drUser); userID = ((Desktop.Entity.DictionaryDataSet.UserRow)drUser).UserID; UserJoinRoleID = ((Desktop.Entity.DictionaryDataSet.UserRow)drUser).UserJoinRoleID; } if (resultAccount == 1) { DictionaryDataSet.UserJoinRoleDataTable tableRole = new DictionaryDataSet.UserJoinRoleDataTable(); if (FormActionMode == ActionMode.AddNew) { DictionaryDataSet.UserJoinRoleRow drRole = tableRole.NewUserJoinRoleRow(); drRole.UserID = userID; drRole.UserJoinRoleID = Guid.NewGuid(); if (rbAdmin.Checked) { drRole.RoleID = 0; } else if (rbBep.Checked) { drRole.RoleID = 5; } else if (rbLeTan.Checked) { drRole.RoleID = 3; } else if (rbPV.Checked) { drRole.RoleID = 2; } objBLDetail.InsertUpdateRole(drRole); } else { DataRow drRole = dsDictionary.UserJoinRole.FindByUserJoinRoleID(UserJoinRoleID); if (rbAdmin.Checked) { ((Desktop.Entity.DictionaryDataSet.UserJoinRoleRow)drRole).RoleID = 0; } else if (rbBep.Checked) { ((Desktop.Entity.DictionaryDataSet.UserJoinRoleRow)drRole).RoleID = 5; } else if (rbLeTan.Checked) { ((Desktop.Entity.DictionaryDataSet.UserJoinRoleRow)drRole).RoleID = 3; } else if (rbPV.Checked) { ((Desktop.Entity.DictionaryDataSet.UserJoinRoleRow)drRole).RoleID = 2; } resultAccount = objBLDetail.InsertUpdateUser(drRole); } } } } return(result); }