private void button_Click(object sender, RoutedEventArgs e) { using (CRMContext dbContext = new CRMContext()) { var client = new BD.Clients(); client.Name = tb_name.Text; client.Address = tb_address.Text; client.Phone = tb_phone.Text; client.Email = tb_email.Text; client.CheckingAccount = tb_checkingAccoubt.Text; client.Bank = tb_bank.Text; client.Director = tb_director.Text; client.Accountant = tb_acccountant.Text; client.Info = tb_info.Text; var results = new List <System.ComponentModel.DataAnnotations.ValidationResult>(); var context = new ValidationContext(client); if (!Validator.TryValidateObject(client, context, results, true)) { foreach (var error in results) { MessageBox.Show(error.ErrorMessage); } } else { dbContext.Clients.Add(client); dbContext.SaveChanges(); } if (Validator.TryValidateObject(client, context, results, true)) { this.Close(); } } }
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); }
public Change_Client(BD.Clients client) { InitializeComponent(); using (CRMContext dbContext = new CRMContext()) { tb_name.Text = client.Name; tb_address.Text = client.Address; tb_phone.Text = client.Phone; tb_email.Text = client.Email; tb_checkingAccoubt.Text = client.CheckingAccount; tb_bank.Text = client.Bank; tb_director.Text = client.Director; tb_acccountant.Text = client.Accountant; tb_info.Text = client.Info; del_client = client; } }
static public void openXml_clients() { 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.Clients client; foreach (XmlNode n in nodes) { if ("Client".Equals(n.Name)) { for (XmlNode d = n.FirstChild; d != null; d = d.NextSibling) { if ("Client".Equals(d.Name)) { client = new CRM.BD.Clients(); for (XmlNode k = d.FirstChild; k != null; k = k.NextSibling) { if ("Название".Equals(k.Name)) { client.Name = (k.FirstChild.Value); } else if ("Адрес".Equals(k.Name)) { client.Address = k.FirstChild.Value; } else if ("Телефон".Equals(k.Name)) { client.Phone = k.FirstChild.Value; } else if ("E_mail".Equals(k.Name)) { client.Email = k.FirstChild.Value; } else if ("Расчетный_счёт".Equals(k.Name)) { client.CheckingAccount = k.FirstChild.Value; } else if ("Банк".Equals(k.Name)) { client.Bank = k.FirstChild.Value; } else if ("Директор".Equals(k.Name)) { client.Director = k.FirstChild.Value; } else if ("Бухгалтер".Equals(k.Name)) { client.Accountant = k.FirstChild.Value; } else if ("Информация".Equals(k.Name)) { client.Info = k.FirstChild.Value; } } using (CRMContext dbContext = new CRMContext()) { try { dbContext.Clients.Add(client); dbContext.SaveChanges(); } catch (Exception ee) { MessageBox.Show("Ошибка!" + ee.Message); } } } } } } }
public Delete(BD.Clients c) { InitializeComponent(); del_obj = c; }