public async Task <IActionResult> Edit(int id, [Bind("OborudovanieId,PomeshenieId,OborudovanieName,OborudovanieCount")] Oborudovanie oborudovanie) { if (id != oborudovanie.OborudovanieId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(oborudovanie); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!OborudovanieExists(oborudovanie.OborudovanieId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["PomeshenieId"] = new SelectList(_context.Pomeshenie, "PomeshenieId", "PomeshenieName", oborudovanie.PomeshenieId); return(View(oborudovanie)); }
private void ListGrid_SelectionChanged(object sender, SelectionChangedEventArgs e) { DataGrid dataGrid = sender as DataGrid; if (dataGrid.SelectedIndex >= 0) { DataGridRow row = (DataGridRow)dataGrid.ItemContainerGenerator.ContainerFromIndex(dataGrid.SelectedIndex); DataGridCell RowColumn = dataGrid.Columns[0].GetCellContent(row).Parent as DataGridCell; int CellValue = Int32.Parse(((TextBlock)RowColumn.Content).Text); int selectedIndex = LoadedOborud.FindIndex(a => a.InvNum_OsnovnSredstva.Value == CellValue); DataSet dataSetData = new DataSet(); var a22 = LoadedOborud[selectedIndex]; Oborudovanie eEngine = LoadedOborud[selectedIndex]; var listOfFields1 = eEngine.GetType().GetProperties().ToList(); IList <IAttribute> attList = new List <IAttribute>(); foreach (var a in listOfFields1) { var propvalue = a.GetValue(eEngine, null) as IAttribute; attList.Add(propvalue); } dtGrid_dataOutput.ItemsSource = attList; } }
public async Task <IActionResult> Create(Oborudovanie oborudovanie) { if (ModelState.IsValid) { _context.Add(oborudovanie); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["PomeshenieId"] = new SelectList(_context.Pomeshenie, "PomeshenieId", "PomeshenieName", oborudovanie.PomeshenieId); return(View(oborudovanie)); }
private void btn_GetData_Click(object sender, RoutedEventArgs e) { string url = "https://dev.beloil.by/cint/kisnpops/hs/ref/osbyperson/1090/"; var req = (HttpWebRequest)WebRequest.Create(url); req.Credentials = new NetworkCredential("august", "august08"); var response = req.GetResponse(); using (var reader = new System.IO.StreamReader(response.GetResponseStream())) { string responseBody = reader.ReadToEnd(); var jarray = (JArray)JsonConvert.DeserializeObject(responseBody); foreach (var jobj in jarray) { if (!LoadedOborud.Any(item => item.InvNum_OsnovnSredstva.Value == int.Parse(jobj["ИнвентарныйНомер"].ToString()))) { Oborudovanie obor = new Oborudovanie(); bool containsItem = oborudovanies.Any(item => item.ShifrByCalssificator_OsnovnSredstva.Value == int.Parse(jobj["Шифр"].ToString())); if (containsItem) { var item = oborudovanies.Single(a => a.ShifrByCalssificator_OsnovnSredstva.Value == int.Parse(jobj["Шифр"].ToString())); Type type = item.GetType(); obor = (Oborudovanie)Activator.CreateInstance(type); } obor.InvNum_OsnovnSredstva.Value = int.Parse(jobj["ИнвентарныйНомер"].ToString()); obor.Name_OsnovnSredstva.Value = jobj["Наименование"].ToString(); obor.ShifrByCalssificator_OsnovnSredstva.Value = int.Parse(jobj["Шифр"].ToString()); obor.RUP_PartName.Value = jobj["ПодразделениеРУП"].ToString(); obor.ORG_PartName.Value = jobj["Подразделение"].ToString(); obor.Year_OsnovnSredstva.Value = int.Parse(jobj["ГодВыпуска"].ToString()); obor.Vvod_v_Expl_Date.Value = DateTime.ParseExact(jobj["ДатаВводаВЭксплуатацию"].ToString().Replace("000000", ""), "yyyyMMdd", CultureInfo.InvariantCulture); obor.MatOtv_Person.Value = jobj["МОЛ"].ToString(); obor.Dislocation_OsnovnSredstva.Value = jobj["Местонахождение"].ToString(); LoadedOborud.Add(obor); } } } string connectionString = "mongodb://localhost:27017"; MongoClient client = new MongoClient(connectionString); IMongoDatabase database = client.GetDatabase("BN"); var collection = database.GetCollection <Oborudovanie>("BNCol"); var cust1 = new BsonDocument(); collection.InsertMany(LoadedOborud); string json = JsonConvert.SerializeObject(LoadedOborud, Formatting.Indented); UpdateOborList(); }
private void btn_TypeChangeButton_Click(object sender, RoutedEventArgs e) { try { if (indexObor >= 0 && LoadedOborud.Count > 0) { var a = LoadedOborud[indexObor]; Console.WriteLine(LoadedOborud[indexObor].GetType().ToString()); LoadedOborud[indexObor] = (Oborudovanie)Activator.CreateInstance(keyItem.Key); LoadedOborud[indexObor].InvNum_OsnovnSredstva.Value = a.InvNum_OsnovnSredstva.Value; LoadedOborud[indexObor].Name_OsnovnSredstva.Value = a.Name_OsnovnSredstva.Value; LoadedOborud[indexObor].ShifrByCalssificator_OsnovnSredstva.Value = a.ShifrByCalssificator_OsnovnSredstva.Value; LoadedOborud[indexObor].RUP_PartName.Value = a.RUP_PartName.Value; LoadedOborud[indexObor].ORG_PartName.Value = a.ORG_PartName.Value; LoadedOborud[indexObor].Year_OsnovnSredstva.Value = a.Year_OsnovnSredstva.Value; LoadedOborud[indexObor].Vvod_v_Expl_Date.Value = a.Vvod_v_Expl_Date.Value; LoadedOborud[indexObor].MatOtv_Person.Value = a.MatOtv_Person.Value; LoadedOborud[indexObor].Dislocation_OsnovnSredstva.Value = a.Dislocation_OsnovnSredstva.Value; Console.WriteLine(LoadedOborud[indexObor].GetType().ToString()); var item = typeNameList.Single(c => c.Key == LoadedOborud[indexObor].GetType()); TypeLable.Content = item.Value; Oborudovanie eEngine = LoadedOborud[indexObor]; var listOfFields1 = eEngine.GetType().GetProperties().ToList(); IList <IAttribute> attList = new List <IAttribute>(); foreach (var b in listOfFields1) { var propvalue = b.GetValue(eEngine, null) as IAttribute; attList.Add(propvalue); } dtGrid_dataOutput.ItemsSource = attList; } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
/// <summary> /// Инициализация таблицы "Оборудование" /// </summary> /// <param name="serviceProvider"></param> /// <param name="configuration"></param> /// <returns></returns> public static async Task CreateOborudovanie(IServiceProvider serviceProvider, IConfiguration configuration) { using (var serviceScope = serviceProvider.GetRequiredService <Microsoft.Extensions.DependencyInjection.IServiceScopeFactory>().CreateScope()) { AppIdentityDBContext context = serviceScope.ServiceProvider.GetService <AppIdentityDBContext>(); #region Инициализация таблицы "Оборудование" if (!await context.Oborudovanie.AnyAsync()) { Oborudovanie OborudovanieName1 = new Oborudovanie { OborudovanieId = 1, PomeshenieId = 3, OborudovanieName = "Стол", OborudovanieCount = 8 }; Oborudovanie OborudovanieName2 = new Oborudovanie { OborudovanieId = 2, PomeshenieId = 3, OborudovanieName = "Стул", OborudovanieCount = 16 }; Oborudovanie OborudovanieName3 = new Oborudovanie { OborudovanieId = 3, PomeshenieId = 3, OborudovanieName = "Доска", OborudovanieCount = 1 }; Oborudovanie OborudovanieName4 = new Oborudovanie { OborudovanieId = 4, PomeshenieId = 3, OborudovanieName = "Компьютер", OborudovanieCount = 6 }; Oborudovanie OborudovanieName5 = new Oborudovanie { OborudovanieId = 5, PomeshenieId = 3, OborudovanieName = "Проектор", OborudovanieCount = 1 }; Oborudovanie OborudovanieName6 = new Oborudovanie { OborudovanieId = 6, PomeshenieId = 5, OborudovanieName = "Стенд", OborudovanieCount = 4 }; await context.Oborudovanie.AddRangeAsync( OborudovanieName1, OborudovanieName2, OborudovanieName3, OborudovanieName4, OborudovanieName5, OborudovanieName6 ); await context.SaveChangesAsync(); } #endregion } }