public Change_Manager(BD.Managers manager) { InitializeComponent(); using (CRMContext dbContext = new CRMContext()) { foreach (var item in dbContext.CatalogPositions) { cb_position.Items.Add(item.Position); } foreach (var item in dbContext.CatalogGroupManagers) { cb_group.Items.Add(item.Group); } tb_name.Text = manager.Name; tb_login.Text = manager.Login; cb_position.SelectedItem = manager.Position; cb_group.SelectedItem = manager.Group; tb_address.Text = manager.Address; tb_phone.Text = manager.Phone; tb_passport.Text = manager.Passport; d_dateofbirth.SelectedDate = manager.DateOfBirth; d_daterecruitment.SelectedDate = manager.DateRecruitment; tb_email.Text = manager.Email; tb_info.Text = manager.Info; del_manager = manager; } }
public Delete(BD.Managers m) { InitializeComponent(); if (m.Name != "Харсеко Никита Игоревич") { del_obj = m; } }
static public XElement getXElement(object obj) { if (obj is CRM.BD.Clients) { CRM.BD.Clients ctmp = (CRM.BD.Clients)obj; XElement client = new XElement("Client"); client.Add(new XElement("Название", ctmp.Name)); client.Add(new XElement("Адрес", ctmp.Address)); client.Add(new XElement("Телефон", ctmp.Phone)); client.Add(new XElement("E_mail", ctmp.Email)); client.Add(new XElement("Расчетный_счёт", ctmp.CheckingAccount)); client.Add(new XElement("Банк", ctmp.Bank)); client.Add(new XElement("Директор", ctmp.Director)); client.Add(new XElement("Бухгалтер", ctmp.Accountant)); client.Add(new XElement("Информация", ctmp.Info)); return(client); } if (obj is CRM.BD.Managers) { CRM.BD.Managers mtmp = (CRM.BD.Managers)obj; XElement manager = new XElement("Manager"); manager.Add(new XElement("ФИО", mtmp.Name)); manager.Add(new XElement("Логин", mtmp.Login)); manager.Add(new XElement("Пароль", mtmp.Password)); manager.Add(new XElement("Должность", mtmp.Position)); manager.Add(new XElement("Группа", mtmp.Group)); manager.Add(new XElement("Адрес", mtmp.Address)); manager.Add(new XElement("Телефон", mtmp.Phone)); manager.Add(new XElement("Пасспорт", mtmp.Passport)); manager.Add(new XElement("Дата_рождения", mtmp.DateOfBirth)); manager.Add(new XElement("Дата_приема_на_работу", mtmp.DateRecruitment)); manager.Add(new XElement("E_mail", mtmp.Email)); if (mtmp.Info != null) { manager.Add(new XElement("Информация", mtmp.Info)); } else { manager.Add(new XElement("Информация", "")); } return(manager); } if (obj is CRM.BD.Tasks) { CRM.BD.Tasks ttmp = (CRM.BD.Tasks)obj; XElement task = new XElement("Task"); task.Add(new XElement("ID", ttmp.Id)); task.Add(new XElement("Заказчик", ttmp.Client)); task.Add(new XElement("Исполнитель", ttmp.Manager)); task.Add(new XElement("Задача", ttmp.Task)); task.Add(new XElement("Информация", ttmp.Info)); task.Add(new XElement("Дата_начала", ttmp.DateStart)); task.Add(new XElement("Дата_завершения", ttmp.DateComplete)); task.Add(new XElement("Статус", ttmp.Status)); return(task); } return(null); }
private void button_Click(object sender, RoutedEventArgs e) { try { using (CRMContext dbContext = new CRMContext()) { var manager = new BD.Managers(); manager.Name = tb_name.Text; manager.Login = tb_login.Text; manager.Password = Hash.EncryptPassword(tb_login.Text, tb_password.Text); manager.Position = cb_position.SelectedItem.ToString(); manager.Group = cb_group.SelectedItem.ToString(); manager.Address = tb_address.Text; manager.Phone = tb_phone.Text; manager.Passport = tb_passport.Text; if (d_dateofbirth.SelectedDate >= (DateTime.Today).AddYears(18)) { MessageBox.Show("Некорректный ввод даты рождения"); } else { manager.DateOfBirth = d_dateofbirth.SelectedDate; } manager.DateRecruitment = d_daterecruitment.SelectedDate; manager.Email = tb_email.Text; manager.Info = tb_info.Text; var results = new List <System.ComponentModel.DataAnnotations.ValidationResult>(); var context = new ValidationContext(manager); if (!Validator.TryValidateObject(manager, context, results, true)) { foreach (var error in results) { MessageBox.Show(error.ErrorMessage); } } else { dbContext.Managers.Add(manager); dbContext.SaveChanges(); EmailSender.SendMail("*****@*****.**", "w5323871w", manager.Email, "Регистрация", "Вы зарегистрировались в \"CRM - система\" \nВаш логин: " + manager.Login + "\nВаш пароль: " + tb_password.Text); } if (Validator.TryValidateObject(manager, context, results, true)) { this.Close(); } } } catch { MessageBox.Show("Ошибка! Некорректный ввод данных!"); } }
static public void openXml_managers() { OpenFileDialog ofd = new OpenFileDialog(); ofd.InitialDirectory = @"h:\Univer\Учеба\Курсач"; ofd.Filter = "Файлы xml |*.xml"; if (ofd.ShowDialog() == DialogResult.Cancel) { return; } filepath = ofd.FileName; XmlDocument doc = new XmlDocument(); doc.Load(filepath); XmlNodeList nodes = doc.ChildNodes; CRM.BD.Managers manager; foreach (XmlNode n in nodes) { if ("Manager".Equals(n.Name)) { for (XmlNode d = n.FirstChild; d != null; d = d.NextSibling) { if ("Manager".Equals(d.Name)) { manager = new CRM.BD.Managers(); for (XmlNode k = d.FirstChild; k != null; k = k.NextSibling) { if ("ФИО".Equals(k.Name)) { manager.Name = k.FirstChild.Value; } else if ("Логин".Equals(k.Name)) { manager.Login = k.FirstChild.Value; } else if ("Должность".Equals(k.Name)) { manager.Position = k.FirstChild.Value; } else if ("Группа".Equals(k.Name)) { manager.Group = k.FirstChild.Value; } else if ("Адрес".Equals(k.Name)) { manager.Address = k.FirstChild.Value; } else if ("Телефон".Equals(k.Name)) { manager.Phone = k.FirstChild.Value; } else if ("Пасспорт".Equals(k.Name)) { manager.Passport = k.FirstChild.Value; } else if ("Пароль".Equals(k.Name)) { manager.Password = Hash.EncryptPassword(manager.Login, "1111"); //manager.Password = Encoding.Default.GetBytes(k.FirstChild.Value); } else if ("Дата_рождения".Equals(k.Name)) { manager.DateOfBirth = Convert.ToDateTime(k.FirstChild.Value); } else if ("Дата_приема_на_работу".Equals(k.Name)) { manager.DateRecruitment = Convert.ToDateTime(k.FirstChild.Value); } else if ("E_mail".Equals(k.Name)) { manager.Email = k.FirstChild.Value; } else if ("Информация".Equals(k.Name)) { manager.Info = k.FirstChild.Value; } } using (CRMContext dbContext = new CRMContext()) { try { dbContext.Managers.Add(manager); dbContext.SaveChanges(); } catch (Exception ee) { MessageBox.Show("Ошибка!" + ee.Message); } } } } } } }