/// <summary> /// Открытие окна настроек сохраненных данных /// </summary> /// <param name="name">имя файла</param> /// <param name="main">окно <see cref="Main"/></param> /// <param name="sender">объект инициализируемый при нажатии на кнопку в <see cref="Table"/></param> public static void OpenCustomizeWindow(string name, Main main, object sender) { //инициализируем кнопку и массив Button button = sender as Button; string[][] desposed = WriteAndRead.GetArrayDll(name); //получаем индекс строчки и снимаев выделение int index = Int32.Parse(button.Tag.ToString()); main.dgTable.SelectedIndex = -1; //настройки содержимого окна корректировки данных Customize customize = new Customize { Owner = main }; customize.lHead.Content = $"Правка данных ({index + 1})"; //заголовок окна customize.Title = name; //имя окна, по умолчанию используется для получения имени учета customize.tbVolume.Text = desposed[index][3]; //объем заправки customize.tbVolume.DataContext = desposed[index][3]; customize.tbCost.Text = desposed[index][4]; //стоимость customize.tbCost.DataContext = desposed[index][4]; customize.cbType.Text = desposed[index][2]; //тип топлива customize.cbType.DataContext = desposed[index][2]; customize.tbConsumption.Text = desposed[index][5]; //средний расход топлива customize.tbConsumption.DataContext = desposed[index][5]; if (desposed[index][1] != "Не указано") { customize.tbGS.Text = desposed[index][1]; //наименование АЗС customize.tbGS.DataContext = desposed[index][1]; } customize.dpChooiceDate.Text = DateTime.Parse (desposed[index][0]).ToShortDateString(); //дата customize.dpChooiceDate.DataContext = desposed[index][0]; customize.bSaveData.DataContext = index; //индекс элемента в desposed[][] customize.ShowDialog(); }
//удаляет выбранный объект учета public static void ToDeliteObject(string name, Main main, Customize customize, int e) { string[][] desposed = WriteAndRead.GetArrayDll(name); string[][] newDesposed = new string[desposed.Length - 1][]; //удаляем выбранный день for (int i = 0, j = 0; i < desposed.Length; i++) { if (i != e) { newDesposed[j++] = desposed[i]; } else { j++; } } WriteAndRead.WriteDll(name, newDesposed); MessageBox.Show("Элемент успешно удален", "Сообщение", MessageBoxButton.OK, MessageBoxImage.Information); customize.Close(); }
//сохроняет измененные данные public static void ToCorrectOfData(string name, Main main, Customize customize, int e) { //инициализация данных string[][] desposed = WriteAndRead.GetArrayDll(name); string GS = customize.tbGS.Text; string type = customize.cbType.Text; string volume = customize.tbVolume.Text; string cost = customize.tbCost.Text; string consumption = customize.tbConsumption.Text; string date = customize.dpChooiceDate.DataContext.ToString(); if (customize.dpChooiceDate.Text != DateTime.Parse(customize.dpChooiceDate.DataContext.ToString()).ToShortDateString()) { date = customize.dpChooiceDate.Text + " 12:30"; } string costLitr = null; string transit = null; if (GS == "" || GS == null || GS == Resources.Get(Resources.Names.textGS)) { GS = "Не указано"; } else if (!Exam.NumericValidation(volume)) { ; } else if (!Exam.NumericValidation(cost)) { ; } else if (!Exam.NumericValidation(consumption)) { ; } else if (!Exam.NamedExam(GS, "наименование АЗС", Resources.Get(Resources.Names.textGS))) { ; } else { customize.Close(); if ( GS != customize.tbGS.DataContext.ToString() || volume != customize.tbVolume.DataContext.ToString() || cost != customize.tbCost.DataContext.ToString() || consumption != customize.tbConsumption.DataContext.ToString() || type != customize.cbType.DataContext.ToString() || date != DateTime.Parse(customize.dpChooiceDate.DataContext.ToString()).ToShortDateString() + " 12:30" ) { costLitr = Calculate.GetCostLitr(volume, cost); transit = Calculate.GetTransit(consumption, volume); //инициализируем массив данных desposed[e] = new string[] { date, GS.Trim(' '), type, Formate(volume), Formate(cost, 2), Formate(consumption), Formate(costLitr), Formate(transit) }; //запись данных desposed = Calculate.DesposedSort(desposed); WriteAndRead.WriteDll(name, desposed); DataUpdate(main); MessageBox.Show("Данные успешно изменены", "Сообщение", MessageBoxButton.OK, MessageBoxImage.Information); } else { MessageBox.Show("Были сохранены исходные данные", "Сообщение", MessageBoxButton.OK, MessageBoxImage.Warning); } } customize.Close(); }