private void MyRightWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { btSave.IsEnabled = true; if (result.Result) { if (this.mode == EType.WindowMode.ADD_MODE) { if (getRightWorker.IsBusy) { getRightWorker.CancelAsync(); } else { getRightWorker.RunWorkerAsync(); } } else { DTO_UserRight oldRight = Repository.lstAllRIght.FirstOrDefault(c => c.Id == userRight.Id); if (oldRight != null) { oldRight = userRight; } this.DialogResult = true; this.Hide(); } } else { MessageBox.Show(result.Detail, "", MessageBoxButton.OK, MessageBoxImage.Error); } }
private void btInfo_Click(object sender, RoutedEventArgs e) { wdRightDetail view = new wdRightDetail(EType.WindowMode.EDIT_MODE, MyRight); if (view.ShowDialog() == true) { if (view.funcClick == 1) { DTO_UserRight updatedRight = Repository.lstAllRIght.FirstOrDefault(r => r.Id == MyRight.Id); if (updatedRight != null) { MyRight = updatedRight; RightName = updatedRight.Name; Detail = updatedRight.Description; } BindingExpression binding = tbRightName.GetBindingExpression(TextBlock.TextProperty); binding.UpdateTarget(); BindingExpression binding1 = tbRightDetail.GetBindingExpression(TextBlock.TextProperty); binding1.UpdateTarget(); } else { this.DeleteClick(sender, e); } } }
/// <summary> /// Get right by key (id) /// </summary> /// <param name="id"></param> /// <returns>Return right if founed or null if error</returns> public DTO_UserRight GetRightByKey(string id) { DataTable dt = dal.GetRightById(id); if (dt.Rows.Count < 0) { return(null); } try { DataRow row = dt.Rows[0]; DTO_UserRight right = new DTO_UserRight(); right.Id = row["Id"] == DBNull.Value ? null : row["Id"].ToString(); right.Name = row["Name"] == DBNull.Value ? null : row["Name"].ToString(); right.Description = row["Description"] == DBNull.Value ? null : row["Description"].ToString(); right.Doors = GetDoorInRight(right.Id); right.Schedules = GetScheduleInRight(right.Id); right.CardHolders = GetPersonInRight(right.Id); return(right); } catch { return(null); } }
/// <summary> /// Get all card /// </summary> /// <returns>Return list card or null if error</returns> public List <DTO_UserRight> GetAllUserRight() { List <DTO_UserRight> lstRighgts = new List <DTO_UserRight>(); DataTable dt = dal.GetAllRIght(); if (dt.Rows.Count < 0) { return(null); } try { foreach (DataRow row in dt.Rows) { DTO_UserRight right = new DTO_UserRight(); right.Id = row["Id"] == DBNull.Value ? null : row["Id"].ToString(); right.Name = row["Name"] == DBNull.Value ? null : row["Name"].ToString(); right.Description = row["Description"] == DBNull.Value ? null : row["Description"].ToString(); right.Doors = GetDoorInRight(right.Id); right.Schedules = GetScheduleInRight(right.Id); right.CardHolders = GetPersonInRight(right.Id); lstRighgts.Add(right); } return(lstRighgts); } catch { return(null); } }
public RightDetailView(int mode, string RightId) { InitializeComponent(); this.mode = mode; this.rightId = RightId; right = Repository.lstAllRIght.FirstOrDefault(r => r.Id == rightId); }
/// <summary> /// Update right information /// </summary> /// <param name="card">The right object want to update</param> /// <returns>Return true if update success, Error if update fail or validate fail</returns> public SQLResult UpdateRight(DTO_UserRight right) { if (right == null) { return(new SQLResult(false, "Right null")); } return(dal.UpdateRight(right)); }
private void Window_Loaded(object sender, RoutedEventArgs e) { InitData(); switch (mode) { case EType.WindowMode.ADD_MODE: userRight = new DTO_UserRight(); ResetControl(); break; default: BindData(); break; } }
private void DelRightWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { if (result.Result) { DTO_UserRight oldRight = Repository.lstAllRIght.FirstOrDefault(c => c.Id == userRight.Id); if (oldRight != null) { Repository.lstAllRIght.Remove(oldRight); } this.DialogResult = true; this.Hide(); } else { MessageBox.Show(result.Detail, "", MessageBoxButton.OK, MessageBoxImage.Error); } }
/// <summary> /// Insert new right to database /// </summary> /// <param name="right"></param> /// <returns></returns> public SQLResult AddNewRight(DTO_UserRight right) { DataTable dt = new DataTable(); SQLResult result = new SQLResult(false, ""); try { _conn.Open(); SqlCommand command = new SqlCommand(); command.Connection = _conn; command.CommandType = CommandType.StoredProcedure; command.CommandText = "spLRightSave"; command.Parameters.AddWithValue("WorkType", "A"); command.Parameters.AddWithValue("Id", ""); command.Parameters.AddWithValue("Name", right.Name); command.Parameters.AddWithValue("Description", right.Description); SqlDataAdapter adapter = new SqlDataAdapter(); adapter.SelectCommand = command; adapter.Fill(dt); if (dt.Rows[0]["Result"].ToString() == "OK") { result.Result = true; } result.Detail = dt.Rows[0]["Detail"].ToString(); result.ExtraData = dt.Rows[0]["ExtraData"].ToString(); } catch (Exception ex) { result.Detail = ex.Message; } finally { _conn.Close(); } return(result); }
public wdRightDetail(EType.WindowMode mode, DTO_UserRight right) { InitializeComponent(); this.mode = mode; this.userRight = right; }