private void buttonUpdate_Click(object sender, EventArgs e) { int indexRow = dataGridViewShowCategory.CurrentCell.RowIndex; int id = Convert.ToInt32(dataGridViewShowCategory.Rows[indexRow].Cells[0].Value); Category category = db.Categories.Find(id); UpdateCategory editCategory = new UpdateCategory(); editCategory.textBoxName.Text = category.Name; // что бы поля были видны в свойствах нужно было поменять private на internal editCategory.textBoxDiscription.Text = category.Discription; DialogResult result = editCategory.ShowDialog(this); // в свойствах DialogRisult надо указать ОК if (result == DialogResult.Cancel) { return; } category.Name = editCategory.textBoxName.Text; category.Discription = editCategory.textBoxDiscription.Text; db.SaveChanges(); updateDataGridView(); // обновляем грид MessageBox.Show("Объект изменён"); }
public void addUser() { using (var context = new LombardContext()) { var query = context.Users.Where(x => x.Login == textBoxLogin.Text && x.Password == textBoxPassword.Text); var user = new User() { Login = textBoxLogin.Text, Password = textBoxPassword.Text }; if (query.ToList().Count < 1) { context.Users.Add(user); context.SaveChanges(); MessageBox.Show("Пользователь успешно добавлен"); this.Close(); } else if (query.ToList().Count > 0) { MessageBox.Show("Логин или пароль уже есть в базе данных"); } textBoxLogin.Clear(); textBoxPassword.Clear(); } }
private void buttonUpdate_Click(object sender, EventArgs e) { int indexRow = dataGridViewShowClient.CurrentCell.RowIndex; int id = Convert.ToInt32(dataGridViewShowClient.Rows[indexRow].Cells[0].Value); Client client = db.Clients.Find(id); UpdateClient editClient = new UpdateClient(); editClient.textBoxSurname.Text = client.Surname; editClient.textBoxName.Text = client.Name; // что бы поля были видны в свойствах нужно было поменять private на internal editClient.textBoxPatronimic.Text = client.Patronimic; editClient.textBoxNumber.Text = client.Number.ToString(); editClient.textBoxSeria.Text = client.Seria.ToString(); editClient.dateTimePickerDatePas.Text = client.DatePas.ToString(); DialogResult result = editClient.ShowDialog(this); // в свойствах DialogRisult надо указать ОК if (result == DialogResult.Cancel) { return; } client.Surname = editClient.textBoxSurname.Text; client.Name = editClient.textBoxName.Text; client.Patronimic = editClient.textBoxPatronimic.Text; client.Number = Convert.ToInt32(editClient.textBoxNumber.Text); client.Seria = Convert.ToInt32(editClient.textBoxSeria.Text); client.DatePas = DateTime.Parse(editClient.dateTimePickerDatePas.Text); db.SaveChanges(); updateDataGridView(); // обновляем грид MessageBox.Show("Объект изменён"); }
private void buttonAddOrder_Click(object sender, EventArgs e) { using (var context = new LombardContext()) { var query = context.Categories.Where(x => x.Name == comboBoxCategory.SelectedItem.ToString()); int id = 0; foreach (var x in query.ToList()) { id = x.CategoryId; } var order = new Order() { CategoryId = id, ClientId = clientid, DiscriptionOrder = textBoxDiscriptionOrder.Text, DateGive = dateTimePickerDateGive.Value, DateTake = dateTimePickerDateTake.Value, Summa = int.Parse(textBoxSumma.Text.ToString()), Comission = int.Parse(textBoxComission.Text.ToString()) }; context.Orders.Add(order); context.SaveChanges(); var journal = new Journal() { Order = order.OrderId, Summa = int.Parse(textBoxSumma.Text.ToString()) }; context.Journals.Add(journal); context.SaveChanges(); textBoxDiscriptionOrder.Clear(); textBoxSumma.Clear(); textBoxComission.Clear(); MessageBox.Show("Запись успешно добавлена"); } }
public void addCategory() { using (var context = new LombardContext()) { var category = new Category() { Name = textBoxName.Text, Discription = textBoxDiscription.Text }; context.Categories.Add(category); context.SaveChanges(); textBoxName.Clear(); textBoxDiscription.Clear(); } }
private void buttonDeleteOrder_Click(object sender, EventArgs e) { if (dataGridViewShowOrder.SelectedRows.Count > 0) { int index = dataGridViewShowOrder.SelectedRows[0].Index; int id = 0; bool converted = Int32.TryParse(dataGridViewShowOrder[0, index].Value.ToString(), out id); if (converted == false) { return; } Order order = db.Orders.Find(id); db.Orders.Remove(order); db.SaveChanges(); MessageBox.Show("Обьект удален"); updateDataGridView(); } }
public void addClient() { using (var context = new LombardContext()) { var client = new Client() { Surname = textBoxSurname.Text, Name = textBoxName.Text, Patronimic = textBoxPatronimic.Text, Number = int.Parse(textBoxNumber.Text.ToString()), Seria = int.Parse(textBoxSeria.Text.ToString()), DatePas = dateTimePickerDatePas.Value }; context.Clients.Add(client); context.SaveChanges(); } textBoxSurname.Clear(); textBoxName.Clear(); textBoxPatronimic.Clear(); textBoxNumber.Clear(); textBoxSeria.Clear(); }
private void buttonImport_Click(object sender, EventArgs e) { XmlSerialization <CLIENT> xmlSerialization = new XmlSerialization <CLIENT>(); CLIENT cl = new CLIENT(); // путь к файлу string filePath = @"import.xml"; cl = (CLIENT)xmlSerialization.ReadData(filePath, cl); //дерсериализация for (int i = 0; i < cl.Client.Count; i++) { string clientName = cl.Client[i].Name; string clientSurname = cl.Client[i].Surname; string clientPatronimic = cl.Client[i].Patronimic; string clientNumber = cl.Client[i].Number; string clientSeria = cl.Client[i].Seria; string clientDatePas = cl.Client[i].DatePas; //добавление using (var context = new LombardContext()) { int number = Convert.ToInt32(clientNumber); int seria = Convert.ToInt32(clientSeria); DateTime datePas = DateTime.Parse(clientDatePas); var query = context.Clients.Where(x => x.Name == clientName && x.Surname == clientSurname && x.Patronimic == clientPatronimic && x.Number == number && x.Seria == seria && x.DatePas == datePas); var clients = new Client() { Name = clientName.ToString(), Surname = clientSurname.ToString(), Patronimic = clientPatronimic.ToString(), Number = number, Seria = seria, DatePas = datePas }; if (query.ToList().Count < 1) { context.Clients.Add(clients); context.SaveChanges(); } } for (int j = 0; j < cl.Client[i].Category.Count; j++) { string categoryname = cl.Client[i].Category[j].Name; string categorydisc = cl.Client[i].Category[j].Discription; using (var context = new LombardContext()) { var category = context.Categories.Where(x => x.Name == categoryname && x.Discription == categorydisc); var categorys = new Category() { Name = categoryname, Discription = categorydisc }; if (category.ToList().Count < 1) { context.Categories.Add(categorys); context.SaveChanges(); } } for (int y = 0; y < cl.Client[i].Category[j].Order.Count; y++) { string orderdisc = cl.Client[i].Category[j].Order[y].DiscriptionOrder; string orderdategive = cl.Client[i].Category[j].Order[y].DateGive; string orderdatetake = cl.Client[i].Category[j].Order[y].DateTake; string ordersumma = cl.Client[i].Category[j].Order[y].Summa; string ordercomission = cl.Client[i].Category[j].Order[y].Comission; using (var context = new LombardContext()) { int number = Convert.ToInt32(clientNumber); int seria = Convert.ToInt32(clientSeria); DateTime datePas = DateTime.Parse(clientDatePas); var categoryid = context.Categories.Where(x => x.Name == categoryname && x.Discription == categorydisc).Select(x => x.CategoryId).First(); var clientid = context.Clients.Where(x => x.Name == clientName && x.Surname == clientSurname && x.Patronimic == clientPatronimic && x.Number == number && x.Seria == seria && x.DatePas == datePas).Select(x => x.ClientId).First(); DateTime dateGive = DateTime.Parse(orderdategive); DateTime dateTake = DateTime.Parse(orderdatetake); decimal summa = Convert.ToDecimal(ordersumma); decimal comission = Convert.ToDecimal(ordercomission); var query = context.Orders.Where(x => x.CategoryId == categoryid && x.ClientId == clientid && x.DiscriptionOrder == orderdisc && x.DateGive == dateGive && x.DateTake == dateTake && x.Summa == summa && x.Comission == comission); var order = new Order() { CategoryId = categoryid, ClientId = clientid, DiscriptionOrder = orderdisc, DateGive = dateGive, DateTake = dateTake, Summa = summa, Comission = comission }; if (query.ToList().Count < 1) { context.Orders.Add(order); context.SaveChanges(); } } for (int m = 0; m < cl.Client[i].Category[j].Order[y].Journal.Count; m++) { using (var context = new LombardContext()) { int number = Convert.ToInt32(cl.Client[i].Number); int seria = Convert.ToInt32(cl.Client[i].Seria); DateTime dateGive = DateTime.Parse(cl.Client[i].Category[j].Order[y].DateGive); DateTime dateTake = DateTime.Parse(cl.Client[i].Category[j].Order[y].DateTake); decimal summa = Convert.ToDecimal(cl.Client[i].Category[j].Order[y].Summa); decimal summa2 = Convert.ToDecimal(cl.Client[i].Category[j].Order[y].Journal[m].Summa); decimal comission = Convert.ToDecimal(cl.Client[i].Category[j].Order[y].Comission); var getClientid = context.Clients.Where(x => x.Number == number && x.Seria == seria).Select(x => x.ClientId).First(); string categoryname2 = cl.Client[i].Category[j].Name; string discriptionname2 = cl.Client[i].Category[j].Discription; var getCategoryId = context.Categories.Where(x => x.Name == categoryname2 && x.Discription == discriptionname2).Select(x => x.CategoryId).First(); var getOrderId = context.Orders.Where(x => x.CategoryId == getCategoryId && x.ClientId == getClientid && x.DiscriptionOrder == orderdisc && x.DateGive == dateGive && x.DateTake == dateTake && x.Summa == summa && x.Comission == comission).Select(x => x.OrderId).First(); var journal = new Journal() { Order = getOrderId, Summa = summa2 }; context.Journals.Add(journal); context.SaveChanges(); } } } } } MessageBox.Show("Импорт завершён"); }
private void buttonUpdate_Click(object sender, EventArgs e) { int indexRow = dataGridViewAddOrder.CurrentCell.RowIndex; int id = Convert.ToInt32(dataGridViewAddOrder.Rows[indexRow].Cells[0].Value); Order order = db.Orders.Find(id); UpdateOrder editOrder = new UpdateOrder(); using (var context = new LombardContext()) { var allCat = from query in context.Categories select new { CategoryId = query.CategoryId, Name = query.Name, Discription = query.Discription }; foreach (var el in allCat.ToList()) { editOrder.comboBoxCategory.Items.Add(el.Name); } var orderGetName = context.Categories.Where(x => x.CategoryId == order.CategoryId); string name; foreach (var x in orderGetName.ToList()) { name = x.Name; editOrder.comboBoxCategory.Text = name.ToString(); } editOrder.clientid = order.ClientId; editOrder.textBoxDiscriptionOrder.Text = order.DiscriptionOrder; editOrder.dateTimePickerDateGive.Text = order.DateGive.ToString(); editOrder.dateTimePickerDateTake.Text = order.DateTake.ToString(); editOrder.textBoxSumma.Text = Convert.ToString(order.Summa); // что бы поля были видны в свойствах нужно было поменять private на internal editOrder.textBoxComission.Text = Convert.ToString(order.Comission); DialogResult result = editOrder.ShowDialog(this); // в свойствах DialogRisult надо указать ОК if (result == DialogResult.Cancel) { return; } var getId = context.Categories.Where(x => x.Name == editOrder.comboBoxCategory.SelectedItem.ToString()); foreach (var x in getId.ToList()) { order.CategoryId = x.CategoryId; } editOrder.textBoxSumma_TextChanged(editOrder.originalText, e); if (editOrder.textBoxSumma.Modified == true) { using (var context2 = new LombardContext()) { var journal = new Journal() { Order = order.OrderId, Summa = Convert.ToDecimal(editOrder.textBoxSumma.Text) }; context2.Journals.Add(journal); context2.SaveChanges(); } } order.ClientId = editOrder.clientid; order.DiscriptionOrder = editOrder.textBoxDiscriptionOrder.Text; order.DateGive = DateTime.Parse(editOrder.dateTimePickerDateGive.Text); order.DateTake = DateTime.Parse(editOrder.dateTimePickerDateTake.Text); order.Summa = Convert.ToDecimal(editOrder.textBoxSumma.Text); order.Comission = Convert.ToDecimal(editOrder.textBoxComission.Text); } db.SaveChanges(); updateDataGridView(); // обновляем грид MessageBox.Show("Объект изменён"); }