private void BtnEditRoom_Click(object sender, RoutedEventArgs e) { if (lbDisplayRooms.SelectedItem != null) { string query = "select * from kl_raum where geb_id=" + lbDisplayBuilding.SelectedValue + " and geschoss_id='" + Application.Current.Properties["LevelId"] + "' and cad_id='" + lbDisplayRooms.SelectedValue + "'"; DataTable dt = DataConnection.GetData(query); if (dt != null && dt.Rows.Count > 0) { //DataTable selectedTable = dt.AsEnumerable() // .Where(r => r.Field<int>("gebaeude_id") ==Convert.ToInt32(lbDisplayBuilding.SelectedValue) && r.Field<string>("geschoss_id")==lbDisplayLevels.SelectedValue.ToString() && r.Field<int>("cad_id")==Convert.ToInt32(lbDisplayRooms.SelectedValue)) // .CopyToDataTable(); AddNewRoom newRoom = new AddNewRoom(lbDisplayRooms.SelectedItem.ToString(), dt, "EditRoom"); newRoom.ShowDialog(); info.Content = AddNewRoom.Info; } } else { MessageBox.Show("Select room"); } }
private void BtnNewRoom_Click(object sender, RoutedEventArgs e) { if (lbDisplayLevels.SelectedItem != null) { string level = lbDisplayLevels.SelectedItem.ToString(); string query = "select top 1 cad_id from kl_raum where geb_id=" + lbDisplayBuilding.SelectedItem + " and geschoss_id='" + lbDisplayLevels.SelectedValue + "' order by cad_id desc"; DataTable dtResult = DataConnection.GetData(query); if (dtResult != null && dtResult.Rows.Count > 0) { if (dtResult.Rows[0][0].ToString() != "" || dtResult.Rows[0][0] != null) { string getRoom = dtResult.Rows[0][0].ToString().Substring(2, dtResult.Rows[0][0].ToString().Length - 2).ToString(); if (getRoom.StartsWith("000")) { getRoom = "001"; } else if (getRoom.StartsWith("00")) { getRoom = getRoom.Substring(2, 1).ToString(); int value = Int32.Parse(getRoom) + 1; if (value == 10) { getRoom = "0" + value.ToString(); } else { getRoom = "00" + value.ToString(); } } else if (getRoom.StartsWith("0")) { getRoom = getRoom.Substring(1, 2).ToString(); int value = Int32.Parse(getRoom) + 1; if (value == 100) { getRoom = value.ToString(); } else { getRoom = "0" + value.ToString(); } } else { } string[] levels = level.Split(':'); if (levels.Length == 2) { Application.Current.Properties["CadId"] = levels[1] + getRoom; AddNewRoom newRoom = new AddNewRoom(lbDisplayBuilding.SelectedItem.ToString(), lbDisplayLevels.SelectedItem.ToString(), levels[1] + getRoom, "NewRoom"); newRoom.ShowDialog(); info.Content = AddNewRoom.Info; lbDisplayRooms.Items.Add(levels[1] + getRoom); } } } else { string[] levels = level.Split(':'); if (levels.Length == 2) { Application.Current.Properties["CadId"] = levels[1] + "000"; AddNewRoom newRoom = new AddNewRoom(lbDisplayBuilding.SelectedItem.ToString(), lbDisplayLevels.SelectedItem.ToString(), levels[1] + "000", "NewRoom"); newRoom.ShowDialog(); info.Content = AddNewRoom.Info; lbDisplayRooms.Items.Add(levels[1] + "000"); } } } else { MessageBox.Show("Select levels"); } }