public Change(BD.Tasks task) { InitializeComponent(); using (CRMContext dbContext = new CRMContext()) { foreach (var item in dbContext.CatalogTasks) { l_task.Items.Add(item.Task); } foreach (var item in dbContext.CatalogStatus) { l_status.Items.Add(item.Status); } foreach (var item in dbContext.Managers) { l_manager.Items.Add(item.Name); } foreach (var item in dbContext.Clients) { l_client.Items.Add(item.Name); } l_id.Text = task.Id.ToString(); l_manager.Text = task.Manager; l_info.Text = task.Info; l_status.SelectedItem = task.Status; l_client.Text = task.Client; l_task.Text = task.Task; d_complete.SelectedDate = task.DateComplete; d_start.SelectedDate = task.DateStart; del_task = task; } }
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) { using (CRMContext dbContext = new CRMContext()) { var task = new BD.Tasks(); Random rnd = new Random(); try { int i = 1 + rnd.Next(10000); task.Id = i; } catch (Exception) { MessageBox.Show("Повторите попытку"); } task.Client = l_client.Text; task.Manager = l_manager.Text; task.Task = l_task.Text; task.Info = l_info.Text; task.Status = l_status.Text; task.DateStart = d_start.SelectedDate; task.DateComplete = d_complete.SelectedDate; var results = new List <System.ComponentModel.DataAnnotations.ValidationResult>(); var context = new ValidationContext(task); if (!Validator.TryValidateObject(task, context, results, true)) { foreach (var error in results) { MessageBox.Show(error.ErrorMessage); } } else { dbContext.Tasks.Add(task); dbContext.SaveChanges(); } if (Validator.TryValidateObject(task, context, results, true)) { this.Close(); } } }
static public void openXml_tasks() { 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.Tasks task; foreach (XmlNode n in nodes) { if ("Task".Equals(n.Name)) { for (XmlNode d = n.FirstChild; d != null; d = d.NextSibling) { if ("Task".Equals(d.Name)) { task = new CRM.BD.Tasks(); for (XmlNode k = d.FirstChild; k != null; k = k.NextSibling) { if ("ID".Equals(k.Name)) { task.Id = Convert.ToInt16(k.FirstChild.Value); } else if ("Заказчик".Equals(k.Name)) { task.Client = k.FirstChild.Value; } else if ("Исполнитель".Equals(k.Name)) { task.Manager = k.FirstChild.Value; } else if ("Задача".Equals(k.Name)) { task.Task = k.FirstChild.Value; } else if ("Информация".Equals(k.Name)) { task.Info = k.FirstChild.Value; } else if ("Дата_начала".Equals(k.Name)) { task.DateStart = Convert.ToDateTime(k.FirstChild.Value); } else if ("Дата_завершения".Equals(k.Name)) { task.DateComplete = Convert.ToDateTime(k.FirstChild.Value); } else if ("Статус".Equals(k.Name)) { task.Status = k.FirstChild.Value; } } using (CRMContext dbContext = new CRMContext()) { try { dbContext.Tasks.Add(task); dbContext.SaveChanges(); } catch (Exception ee) { MessageBox.Show("Ошибка!" + ee.Message); } } } } } } }
public Delete(BD.Tasks t) { InitializeComponent(); del_obj = t; }