private void itemDelete_Click(object sender, RoutedEventArgs e) { DTO_ScorpionAccess.ListViewItem item = (DTO_ScorpionAccess.ListViewItem)lbListSockets.SelectedItem; if (item == null) { return; } MessageBoxResult result = MessageBox.Show("Bạn có muốn xóa terminal này không?", "Xác nhận", MessageBoxButton.YesNo, MessageBoxImage.Question); if (result == MessageBoxResult.Yes) { DTO_DoorSocket socket = door.Sockets.FirstOrDefault(s => s.Id == item.Key); SQLResult sQLResult = bUS_DoorSocket.DeleteSocket(socket.Id, socket.ConnectedDeviceSocketId); if (sQLResult.Result) { DTO_Door selectedDoor = Repository.lstAllDoor.FirstOrDefault(d => d.Id == door.Id); if (selectedDoor != null) { selectedDoor.Sockets.Remove(socket); } BindSocketToListItemView(); } else { MessageBox.Show(sQLResult.Detail, "Lỗi", MessageBoxButton.OK, MessageBoxImage.Error); } } }
private void MyDoorWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { btSave.IsEnabled = true; if (result.Result) { if (this.mode == EType.WindowMode.ADD_MODE) { if (getDoorWorker.IsBusy) { getDoorWorker.CancelAsync(); } else { getDoorWorker.RunWorkerAsync(); } } else { DTO_Door oldDoor = Repository.lstAllDoor.FirstOrDefault(c => c.Id == door.Id); if (oldDoor != null) { oldDoor = door; } this.DialogResult = true; this.Hide(); } } else { MessageBox.Show(result.Detail, "", MessageBoxButton.OK, MessageBoxImage.Error); } }
/// <summary> /// Insert new door to database /// </summary> /// <param name="door"></param> /// <returns></returns> public SQLResult AddNewDoor(DTO_Door door) { 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 = "spLDoorSave"; command.Parameters.AddWithValue("WorkType", "A"); command.Parameters.AddWithValue("Id", ""); if (door.Name == null) { command.Parameters.AddWithValue("Name", DBNull.Value); } else { command.Parameters.AddWithValue("Name", door.Name); } command.Parameters.AddWithValue("LOTimeOut", door.LOTimeOut); command.Parameters.AddWithValue("DOTimeOut", door.DOTimeOut); command.Parameters.AddWithValue("Mode", door.Mode.Id); if (door.Description == null) { command.Parameters.AddWithValue("Description", DBNull.Value); } else { command.Parameters.AddWithValue("Description", door.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); }
/// <summary> /// Update door information /// </summary> /// <param name="door">The door object want to update</param> /// <returns>Return true if update success, Error if update fail or validate fail</returns> public SQLResult UpdateDoor(DTO_Door door) { if (door == null) { return(new SQLResult(false, "Cửa rỗng.")); } if (!door.Validation().Result) { return(new SQLResult(false, door.Validation().Detail)); } return(dal.UpdateDoor(door)); }
private void Window_Loaded(object sender, RoutedEventArgs e) { InitData(); switch (mode) { case EType.WindowMode.ADD_MODE: ResetControl(); door = new DTO_Door(); break; default: BindData(); break; } }
private void DelDoorWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { if (result.Result) { DTO_Door oldDoor = Repository.lstAllDoor.FirstOrDefault(d => d.Id == door.Id); if (oldDoor != null) { Repository.lstAllDoor.Remove(oldDoor); } this.DialogResult = true; this.Hide(); } else { MessageBox.Show(result.Detail, "", MessageBoxButton.OK, MessageBoxImage.Error); } }
/// <summary> /// Get all Door /// </summary> /// <returns>Return list door or null if error</returns> public List <DTO_Door> GetAllDoor() { List <DTO_Door> lstDoors = new List <DTO_Door>(); DataTable dt = dal.GetAllDoor(); if (dt.Rows.Count < 0) { return(null); } try { foreach (DataRow row in dt.Rows) { DTO_Door door = new DTO_Door(); door.Id = row["Id"] == DBNull.Value ? null : row["Id"].ToString(); door.Name = row["Name"] == DBNull.Value ? null : row["Name"].ToString(); door.LOTimeOut = row["LOTimeout"] == DBNull.Value ? 0 : (int)row["LOTimeout"]; door.DOTimeOut = row["DOTimeout"] == DBNull.Value ? 0 : (int)row["DOTimeout"]; door.Description = row["Description"] == DBNull.Value ? null : row["Description"].ToString(); DTO_DoorMode mode = new DTO_DoorMode(); mode.Id = row["DMode"] == DBNull.Value ? null : row["DMode"].ToString(); mode.Name = row["DoorModeName"] == DBNull.Value ? null : row["DoorModeName"].ToString(); mode.ReaderUse = row["ReadersUse"] == DBNull.Value ? 0 : (int)row["ReadersUse"]; mode.InputUse = row["InputUse"] == DBNull.Value ? 0 : (int)row["InputUse"]; mode.OutputUse = row["OutputUse"] == DBNull.Value ? 0 : (int)row["OutputUse"]; mode.Description = row["DoorModeDescr"] == DBNull.Value ? null : row["DoorModeDescr"].ToString(); door.Mode = mode; door.Sockets = bus_Socket.GetDoorSocketInDoor(door.Id); lstDoors.Add(door); } return(lstDoors); } catch (Exception ex) { return(null); } }
public List <DTO_Door> GetDoorInRight(string rightId) { List <DTO_Door> lstDoor = new List <DTO_Door>(); DataTable dt = dal.GetRightDetailByRight(rightId, 0); if (dt.Rows.Count <= 0) { return(lstDoor); } foreach (DataRow dr in dt.Rows) { string id = dr["DetailId"].ToString(); DTO_Door door = bus_Door.GetDoorByKey(id); lstDoor.Add(door); } return(lstDoor); }
/// <summary> /// Get door by key (Id) /// </summary> /// <param name="Id"></param> /// <returns>Return door if founed or null if error</returns> public DTO_Door GetDoorByKey(string Id) { DataTable dt = dal.GetDoorById(Id); if (dt.Rows.Count < 0) { return(null); } try { DataRow row = dt.Rows[0]; DTO_Door door = new DTO_Door(); door.Id = row["Id"] == DBNull.Value ? null : row["Id"].ToString(); door.Name = row["Name"] == DBNull.Value ? null : row["Name"].ToString(); door.LOTimeOut = row["LOTimeOut"] == DBNull.Value ? 0 : (int)row["LOTimeOut"]; door.DOTimeOut = row["DOTimeOut"] == DBNull.Value ? 0 : (int)row["DOTimeOut"]; door.Description = row["Description"] == DBNull.Value ? null : row["Description"].ToString(); DTO_DoorMode mode = new DTO_DoorMode(); mode.Id = row["DMode"] == DBNull.Value ? null : row["DMode"].ToString(); mode.Name = row["DoorModeName"] == DBNull.Value ? null : row["DoorModeName"].ToString(); mode.ReaderUse = row["ReadersUse"] == DBNull.Value ? 0 : (int)row["ReadersUse"]; mode.InputUse = row["InputUse"] == DBNull.Value ? 0 : (int)row["InputUse"]; mode.OutputUse = row["OutputUse"] == DBNull.Value ? 0 : (int)row["OutputUse"]; mode.Description = row["DoorModeDescr"] == DBNull.Value ? null : row["DoorModeDescr"].ToString(); door.Mode = mode; door.Sockets = bus_Socket.GetDoorSocketInDoor(door.Id); return(door); } catch { return(null); } }
public wdDoorDetail(EType.WindowMode mode, DTO_Door door) { InitializeComponent(); this.mode = mode; this.door = door; }
public wdDoorSocketDetail(DTO_Door door) { InitializeComponent(); this.door = door; }
private void BindSocketToListItemView() { door = Repository.lstAllDoor.FirstOrDefault(d => d.Id == door.Id); listViewItems = new List <DTO_ScorpionAccess.ListViewItem>(); foreach (DTO_DoorSocket socket in door.Sockets) { DTO_ScorpionAccess.ListViewItem listViewItem = new DTO_ScorpionAccess.ListViewItem(); switch (socket.Type) { case EType.DoorSocketType.CONTACT: if (socket.ConnectedDevice != null) { listViewItem.ImageSource = "/Icon/c_character_gray_50px.png"; } else { listViewItem.ImageSource = "/Icon/c_character_green_50px.png"; } break; case EType.DoorSocketType.LOCK: if (socket.ConnectedDevice != null) { listViewItem.ImageSource = "/Icon/l_character_gray_50px.png"; } else { listViewItem.ImageSource = "/Icon/l_character_green_50px.png"; } break; case EType.DoorSocketType.READER: if (socket.ConnectedDevice != null) { listViewItem.ImageSource = "/Icon/e_character_gray_50px.png"; } else { listViewItem.ImageSource = "/Icon/e_character_green_50px.png"; } break; case EType.DoorSocketType.REX: if (socket.ConnectedDevice != null) { listViewItem.ImageSource = "/Icon/r_character_gray_50px.png"; } else { listViewItem.ImageSource = "/Icon/r_character_green_50px.png"; } break; } listViewItem.TextBinding = socket.Name; listViewItem.Key = socket.Id; listViewItems.Add(listViewItem); } lbListSockets.ItemsSource = listViewItems; }
private void btSave_Click(object sender, RoutedEventArgs e) { socket.Name = tbSocketName.Text; if (cbConnectSocket.SelectedItem != null) { socket.ConnectedDeviceSocketId = cbConnectSocket.SelectedValue.ToString(); } switch (socket.Type) { case EType.DoorSocketType.CONTACT: DTO_Contact contact = new DTO_Contact(); contact.Type = (EType.ContactType)cbSocketDetailType.SelectedItem; contact.Mode = (EType.ContactMode)cbSocketDetailMode.SelectedItem; socket.Property = contact; break; case EType.DoorSocketType.LOCK: DTO_Lock llock = new DTO_Lock(); llock.Type = (EType.LockType)cbSocketDetailType.SelectedItem; socket.Property = llock; break; case EType.DoorSocketType.READER: DTO_Reader reader = new DTO_Reader(); reader.Type = (EType.ReaderType)cbSocketDetailType.SelectedItem; socket.Property = reader; break; case EType.DoorSocketType.REX: DTO_Rex rex = new DTO_Rex(); rex.Type = (EType.RexType)cbSocketDetailType.SelectedItem; socket.Property = rex; break; } SQLResult result; if (mode == EType.WindowMode.ADD_MODE) { result = bUS_DoorSocket.AddNewSocket(socket); if (result.Result) { socket = bUS_DoorSocket.GetDoorSocketById(result.ExtraData); DTO_Door selectedDoor = Repository.lstAllDoor.FirstOrDefault(d => d.Id == doorId); if (selectedDoor != null) { selectedDoor.Sockets.Add(socket); } this.DialogResult = true; this.Hide(); } else { MessageBox.Show(result.Detail, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } else { result = bUS_DoorSocket.UpdateSocket(socket); if (result.Result) { DTO_Door selectedDoor = Repository.lstAllDoor.FirstOrDefault(d => d.Id == doorId); if (selectedDoor != null) { DTO_DoorSocket oldSocket = (DTO_DoorSocket)selectedDoor.Sockets.FirstOrDefault(s => s.Id == socket.Id); oldSocket = socket; } this.DialogResult = true; this.Hide(); } else { MessageBox.Show(result.Detail, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } }
private void Window_Loaded(object sender, RoutedEventArgs e) { bUS_Right = new BUS_Right(); listRightDetails = new List <ListDetailItem>(); listRightDetails.Clear(); if (mode == DOOR_MODE) { foreach (DTO_Door door in Repository.lstAllDoor) { ListDetailItem item = new ListDetailItem(); item.TextBinding = door.Name; item.Key = door.Id; DTO_Door d = right.Doors.FirstOrDefault(o => o.Id == door.Id); if (d == null) { item.IsChecked = false; } else { item.IsChecked = true; } listRightDetails.Add(item); } lbRightDetail.ItemsSource = listRightDetails; return; } if (mode == SCHEDULE_MODE) { foreach (DTO_Schedule schedule in Repository.lstAllSchedules) { ListDetailItem item = new ListDetailItem(); item.TextBinding = schedule.Name; item.Key = schedule.Id; DTO_Schedule d = right.Schedules.FirstOrDefault(o => o.Id == schedule.Id); if (d == null) { item.IsChecked = false; } else { item.IsChecked = true; } listRightDetails.Add(item); } lbRightDetail.ItemsSource = listRightDetails; return; } if (mode == PERSON_MODE) { foreach (DTO_CardHolder hodler in Repository.lstAllCardHolders) { ListDetailItem item = new ListDetailItem(); item.TextBinding = hodler.Name; item.Key = hodler.Id; DTO_CardHolder d = right.CardHolders.FirstOrDefault(o => o.Id == hodler.Id); if (d == null) { item.IsChecked = false; } else { item.IsChecked = true; } listRightDetails.Add(item); } lbRightDetail.ItemsSource = listRightDetails; return; } }
private void btSave_Click(object sender, RoutedEventArgs e) { if (mode == DOOR_MODE) { List <DTO_Door> oldDoors = right.Doors; foreach (DTO_Door door in oldDoors) { bUS_Right.DeleteDoorInRight(rightId, door.Id); } right.Doors.Clear(); List <DTO_Door> newDoors = new List <DTO_Door>(); foreach (ListDetailItem item in listRightDetails) { if (item.IsChecked) { DTO_Door door = Repository.lstAllDoor.FirstOrDefault(d => d.Id == item.Key); newDoors.Add(door); right.Doors.Add(door); } } foreach (DTO_Door door in newDoors) { bUS_Right.AddDoorToRight(rightId, door.Id); } Repository.lstAllRIght.FirstOrDefault(r => r.Id == rightId).Doors = right.Doors; this.DialogResult = true; this.Hide(); return; } if (mode == SCHEDULE_MODE) { List <DTO_Schedule> oldSchedules = right.Schedules; foreach (DTO_Schedule schedule in oldSchedules) { bUS_Right.DeleteScheduleInRight(rightId, schedule.Id); } right.Schedules.Clear(); List <DTO_Schedule> newSchedules = new List <DTO_Schedule>(); foreach (ListDetailItem item in listRightDetails) { if (item.IsChecked) { DTO_Schedule schedule = Repository.lstAllSchedules.FirstOrDefault(d => d.Id == item.Key); newSchedules.Add(schedule); } } right.Schedules = newSchedules; foreach (DTO_Schedule schedule in newSchedules) { bUS_Right.AddScheduleToRight(rightId, schedule.Id); } Repository.lstAllRIght.FirstOrDefault(r => r.Id == rightId).Schedules = right.Schedules; this.DialogResult = true; this.Hide(); return; } if (mode == PERSON_MODE) { List <DTO_CardHolder> oldPersons = right.CardHolders; foreach (DTO_CardHolder person in oldPersons) { bUS_Right.DeletePersonInRight(rightId, person.Id); } right.CardHolders.Clear(); List <DTO_CardHolder> newPersons = new List <DTO_CardHolder>(); foreach (ListDetailItem item in listRightDetails) { if (item.IsChecked) { DTO_CardHolder person = Repository.lstAllCardHolders.FirstOrDefault(d => d.Id == item.Key); newPersons.Add(person); right.CardHolders.Add(person); } } foreach (DTO_CardHolder person in newPersons) { bUS_Right.AddPersonToRight(rightId, person.Id); } Repository.lstAllRIght.FirstOrDefault(r => r.Id == rightId).CardHolders = right.CardHolders; this.DialogResult = true; this.Hide(); return; } }