private void button9_Click(object sender, EventArgs e) { AddContakt.MyStruct m = new AddContakt.MyStruct(); if (dataGridView2.CurrentRow != null) { DataTable dtm = null; using (DataMy dt = DataMy.GetInstanse()) { dtm = dt.GetTable("group_contacts"); } int idContact = Convert.ToInt32(dataGridView2.CurrentRow.Cells[0].Value); var s = dtm.AsEnumerable(); var mm = from ss in s where ss["name_group"].ToString() == dataGridView2.CurrentRow.Cells[1].Value.ToString() select ss["id_group"]; var k = mm.FirstOrDefault(); if (k == null) { k = "0"; } m.id_group = Convert.ToInt32(k.ToString()); m.Date_reg = LogicMy.dtToUnix(Convert.ToDateTime(dataGridView2.CurrentRow.Cells[2].Value.ToString())); m.Name = dataGridView2.CurrentRow.Cells[4].Value.ToString(); m.Familiya = dataGridView2.CurrentRow.Cells[3].Value.ToString(); m.Date_of_birth = LogicMy.dtToUnix(Convert.ToDateTime(dataGridView2.CurrentRow.Cells[5].Value.ToString())); m.Phone = dataGridView2.CurrentRow.Cells[6].Value.ToString(); m.Email = dataGridView2.CurrentRow.Cells[7].Value.ToString(); m.Sex = dataGridView2.CurrentRow.Cells[8].Value.ToString(); m.Is_whats_app = dataGridView2.CurrentRow.Cells[9].Value.ToString().Trim() == "1" ? AddContakt.MyEnum.Yes : AddContakt.MyEnum.No; m.Subscrible = dataGridView2.CurrentRow.Cells[10].Value.ToString().Trim() == "1" ? AddContakt.MyEnum.Yes : AddContakt.MyEnum.No; m.coment = dataGridView2.CurrentRow.Cells[11].Value.ToString().Trim(); using (UpdateContacts uc = new UpdateContacts(idContact, m)) { if (uc.ShowDialog() == DialogResult.OK) { this.UpdateContactsGrid(); } } } else { MessageBox.Show("Выберите строку для редактирования!"); } }
/// <summary>Initializes a new instance of the <see cref="MainViewModel" /> class.</summary> public MainViewModel() { this.logInfo.SaveInfo(); // Сохранение информации о запустившем программу this.logger.Info("Запуск приложения Phonebook 3 Cindy"); try { // Вычитывание параметров из XML // Инициализация модели настроек this.settingsXml = new SettingsXml <RootElement>(SettingsPath); this.settings.SoftUpdate = new SoftUpdate(); this.settings.Contacts = new SettingsShell.Contacts(); if (!File.Exists(SettingsPath)) { this.settings = this.SetDefaultValue(this.settings); // Значения по умолчанию this.settingsXml.WriteXml(this.settings); } else { this.settings = this.settingsXml.ReadXml(this.settings); } this.updCont = new UpdateContacts(this.settings); this.Misc = new Misc { }; // (Environment.UserDomainName) == "ELCOM" if (true) { var upd = new SoftUpdater(this.settings); upd.UpdateSoft(); if (!File.Exists(DatabasePath)) { this.dbc.CreateBase(); this.dbc.EmployeeCreateTable(); this.dbc.CustomerCreateTable(); this.dbc.InfoCreateTable(); this.dbc.StatusCreateTable(); } File.Copy(DatabasePath, DatabasePathTemp, true); this.EmployeeLst = new ObservableCollection <Employee> { }; this.EmployeeLstT = new ObservableCollection <Employee> { }; this.EmployeeNewLst = new ObservableCollection <Employee> { }; this.CustomerLst = new ObservableCollection <Customer> { }; this.CustomerLstT = new ObservableCollection <Customer> { }; this.NewContact = new Customer { }; this.News = new ObservableCollection <NewEvent> { }; this.FutureNews = new ObservableCollection <NewEvent> { }; this.Statistic = new Statistic { }; this.Divisions = new ObservableCollection <Division> { }; this.SelectedDiv = new Employee { }; // Команды // Меню this.MenuMainCmd = new Command(arg => this.MenuMain()); this.MenuContactsCmd = new Command(arg => this.MenuContacts()); this.MenuStatisticCmd = new Command(arg => this.MenuStatistic()); // Сотрудники this.SearchEmployeeCmd = new Command(arg => this.SearchEmployee()); this.ClearFilterEmployeeCmd = new Command(arg => this.ClearFilterEmployee()); this.SelectDivEmployeeCmd = new Command(arg => this.SelectDivEmployee()); this.SelectEmployeeCmd = new Command(arg => this.SelectEmployee()); // Контакты this.SearchContactCmd = new Command(arg => this.SearchContact()); this.ClearFilterContactCmd = new Command(arg => this.ClearFilterContact()); this.DownloadContactCmd = new Command(arg => this.DownloadContact()); this.SaveContactCmd = new Command(arg => this.SaveContact()); this.AddNewContactCmd = new Command(arg => this.AddNewContact()); this.SortNameAscContactCmd = new Command(arg => this.SortNameAscContact()); this.SortNameDescContactCmd = new Command(arg => this.SortNameDescContact()); // Статистика this.UpdateNewersStatCmd = new Command(arg => this.UpdateNewersStat()); // Сортировка сотрудников this.SortNameAscCmd = new Command(arg => this.SortNameAsc()); this.SortNameDescCmd = new Command(arg => this.SortNameDesc()); this.SortBirthAscCmd = new Command(arg => this.SortBirthAsc()); this.SortBirthDescCmd = new Command(arg => this.SortBirthDesc()); this.SortStartAscCmd = new Command(arg => this.SortStartAsc()); this.SortStartDescCmd = new Command(arg => this.SortStartDesc()); // Сервисные this.DataUpdCmd = new Command(arg => this.DataUpd()); var tempEmpl = this.dbc.EmployeeRead(); this.EmployeeLst = tempEmpl; // Видимость стартовой страницы this.Misc.StartPageVisible = "Visible"; this.Misc.FilterPageVisible = "Collapsed"; // ----------------------------------------------------- // Новости var newsManag = new NewsManager(this.EmployeeLst); this.News = newsManag.GetNews(); this.FutureNews = newsManag.GetFutureNews(); this.Misc.EmployeeCount = this.EmployeeLst.Count(); var age = 0; var timeRec = 0; foreach (var em in this.EmployeeLst) { age += em.Age; var timeRecT = em.TimeRecord == "менее года" ? 0 : Convert.ToInt32(em.TimeRecord); timeRec += timeRecT; } this.Misc.MiddleAge = age / this.Misc.EmployeeCount; this.Misc.MiddleTimeRecord = timeRec / this.Misc.EmployeeCount; // Подразделения var divList = new List <string>(); foreach (var ee in this.EmployeeLst) { this.EmployeeLstT.Add(ee); divList.Add(ee.Division); } divList.Sort(); var result = (from m in divList select m).Distinct().ToList(); var division = new Division { Value = "1. Все" }; this.Divisions.Add(division); foreach (var s in result) { division = new Division { Value = s }; this.Divisions.Add(division); } this.SelectedDiv.Division = "1. Все"; this.emplStat = new EmplStatistic(this.EmployeeLst, this.Statistic); this.Statistic = this.emplStat.CalcCount(); var employeeNewLstT = this.emplStat.Newers(this.Statistic.StartNewers, DateTime.Now); this.EmployeeNewLst.Clear(); foreach (var ee in employeeNewLstT) { this.EmployeeNewLst.Add(ee); } this.SortNameAsc(); this.UpdateContacts(); this.Misc.ContactsCount = this.CustomerLst.Count(); this.SortNameAscContact(); this.MenuMain(); this.Misc = this.dbc.EmployeeReadStatusCount(this.Misc); this.DataUpd(); } else { this.Misc.AccessDenied = "Collapsed"; this.Misc.AccessDeniedMess = "Visible"; } } catch (Exception ex) { this.logger.Error(ex.Message); } }