private void dgv_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex > -1) { DataGridViewRow row = this.dgv.Rows[e.RowIndex]; updateID = Convert.ToInt32(row.Cells[0].Value.ToString()); using (ShopDBEntities _context = new ShopDBEntities()) { if (cbCat.DataSource == null) { PopulateDropDown(); } var item = _context.Items.SingleOrDefault(c => c.ItemID == updateID); tbName.Text = item.Name; tbDesc.Text = item.Description; cbCat.SelectedValue = item.CatID; txtPPrice.Text = item.PurchasePrice.ToString(); txtSPrice.Text = item.Saleprice.ToString(); numQty.Value = item.Qty; numDPercent.Value = Convert.ToDecimal(item.DiscountPercent); } } }
public ActionResult EditQuest([Bind(Include = "Id,key")] Quest quest) { // Lets first check if the Model is valid or not if (ModelState.IsValid) { using (ShopDBEntities entities = new ShopDBEntities()) { int Id = quest.Id; string key = quest.key; bool QuestValid = entities.Quest.Any(u => u.Id == Id && u.key == key && u.State != 2); // User found in the database if (QuestValid) { Session["QuestID"] = Id; return(RedirectToAction("Quest", "UserAction")); } else { ModelState.AddModelError("", "Извините но подобного заказа нету."); } } } // If we got this far, something failed, redisplay form return(View()); }
private void brnProcess_Click(object sender, EventArgs e) { try { int CompleteOStatusID = Convert.ToInt32(Properties.Settings.Default["CompleteOStatusID"]); int PendingOStatusID = Convert.ToInt32(Properties.Settings.Default["PendingOStatusID"]); using (ShopDBEntities db = new ShopDBEntities()) { string prderNo = txtOrderNo.Text; var toUpdate = db.Orders.SingleOrDefault(c => c.OrderNo == prderNo); toUpdate.TotalPayment = Convert.ToDecimal(txtTotalPayment.Text); toUpdate.PaymentDue = Convert.ToDecimal(txtPaymentDue.Text); if (Convert.ToDecimal(txtPaymentDue.Text) == 0) { toUpdate.OrderStatusID = CompleteOStatusID; } else { toUpdate.OrderStatusID = PendingOStatusID; } db.Entry(toUpdate).State = EntityState.Modified; db.SaveChanges(); MessageBox.Show("Updated successfully", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } } catch (Exception ex) { MessageBox.Show("Error.\nDetails: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; txtOrderNo.Focus(); } }
public OrderViewModel GetOrderById(int id) { using (ShopDBEntities db = new ShopDBEntities()) { Order order = db.Orders.Find(id); var customerName = db.Customers.Find(order.CustomerId); var orderItem = db.OrderItems.Where(o => o.OrderId.Equals(id)).ToList(); OrderViewModel orderView = new OrderViewModel(); orderView.Id = order.Id; orderView.OrderNumber = order.OrderNumber; orderView.OrderDate = order.OrderDate; orderView.CustomerId = order.CustomerId; orderView.TotalAmount = order.TotalAmount; orderView.CustomerName = customerName.FirstName + " " + customerName.LastName; List <OrderItemViewModel> listOrderItem = new List <OrderItemViewModel>(); foreach (var item in orderItem) { OrderItemViewModel orderItemViewModel = new OrderItemViewModel(); orderItemViewModel.Id = item.Id; var productName = db.Products.Find(item.ProductId); orderItemViewModel.OrderId = item.OrderId; orderItemViewModel.ProductId = item.ProductId; orderItemViewModel.Quantity = item.Quantity; orderItemViewModel.UnitPrice = item.UnitPrice; orderItemViewModel.ProductName = productName.ProductName; listOrderItem.Add(orderItemViewModel); } orderView.Detail = listOrderItem; return(orderView); } }
public OrderViewModel GetOrderById(int id) { using (ShopDBEntities db = new ShopDBEntities()) { Order item = db.Order.Find(id); OrderViewModel order = new OrderViewModel(); order.Id = item.Id; order.OrderDate = item.OrderDate; order.OrderNumber = item.OrderNumber; order.CustomerId = item.CustomerId; order.TotalAmount = item.TotalAmount; order.CustomerId = item.CustomerId; order.CustomerName = item.Customer.FirstName; order.orderItem = (from x in db.OrderItem.Include(p => p.Product) where x.OrderId == id select new OrderItemViewModel { Id = x.Id, OrderId = x.OrderId, ProductId = x.ProductId, UnitPrice = x.UnitPrice, Quantity = x.Quantity, TotalAmount = x.UnitPrice * x.Quantity, ProductName = x.Product.ProductName }).ToList(); return(order); } }
public OrderViewModel temporaryList(OrderItemViewModel orderitemVM, List <OrderItemViewModel> ListItem) { using (ShopDBEntities db = new ShopDBEntities()) { Product produk = db.Product.Find(orderitemVM.ProductId); OrderViewModel order = new OrderViewModel(); order.OrderItem = ListItem; foreach (var item in order.OrderItem) { if (item.ProductId == orderitemVM.ProductId) { item.Quantity += orderitemVM.Quantity; item.TotalAmount = item.Quantity * item.UnitPrice; return(order); } } decimal harga = produk.UnitPrice.HasValue ? produk.UnitPrice.Value : 0; int Id = (db.Order.ToList().Count != 0) ? (from o in db.Order orderby o.Id descending select o.Id).First() + 1 : 1; orderitemVM.ProductName = produk.ProductName; orderitemVM.OrderId = Id; orderitemVM.UnitPrice = harga; orderitemVM.TotalAmount = orderitemVM.Quantity * orderitemVM.UnitPrice; int idItem = (order.OrderItem.Count != 0) ? (from o in order.OrderItem orderby o.Id descending select o.Id).First() + 1 : 1; orderitemVM.Id = idItem; order.OrderItem.Add(orderitemVM); return(order); } }
public void AddNewOrder(OrderViewModel order) { using (ShopDBEntities db = new ShopDBEntities()) { string[] formats = { "dd/MM/yyyy" }; DateTime oDate = DateTime.ParseExact(order.OrderDate, formats, new CultureInfo("en-US"), DateTimeStyles.None); Order model = new Order(); model.CustomerId = order.CustomerId; model.OrderDate = oDate; model.OrderNumber = order.OrderNumber; model.TotalAmount = order.TotalAmount; db.Order.Add(model); db.SaveChanges(); foreach (var item in order.ListOrderItem) { OrderItem modelItem = new OrderItem(); modelItem.OrderId = model.Id; modelItem.ProductId = item.ProductId; modelItem.Quantity = item.Quantity; modelItem.UnitPrice = item.UnitPrice; db.OrderItem.Add(modelItem); db.SaveChanges(); } } }
private void metroButton3_Click(object sender, EventArgs e) { if (id == 0) { MetroMessageBox.Show(this, "Validation Error. Please check for emty fields.", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } try { using (ShopDBEntities db = new ShopDBEntities()) { var user = db.Users.SingleOrDefault(c => c.UserID == id); db.Users.Remove(user); db.Entry(user).State = EntityState.Deleted; db.SaveChanges(); } id = 0; Notifications.Notfication("Account Deleted", "Account " + tbCreateName.Text + " deleted from the system.", Color.Red); initiate(); } catch (System.Data.Entity.Infrastructure.DbUpdateException) { MetroMessageBox.Show(this, "Please remove data from child tables first. ", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } }
private void btnProcessUpdate_Click(object sender, EventArgs e) { try { //UPDADE ORDER TABLE using (ShopDBEntities db = new ShopDBEntities()) { string orderNo = txtUpdateOrderNo.Text; var updateOrder = db.Orders.SingleOrDefault(c => c.OrderNo == orderNo); updateOrder.TotalPayment = Convert.ToDecimal(txtTotalPayment.Text); if (txtPaymentDue.Text.Trim() == "0.00" || Convert.ToDecimal(txtPaymentDue.Text) == 0) { updateOrder.OrderStatusID = 1; } else { updateOrder.OrderStatusID = 2; } db.Entry(updateOrder).State = EntityState.Modified; db.SaveChanges(); DialogResult result = MessageBox.Show("Print Slip?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { InvoiceType = "Update Order"; PrintPreviewDialog.Document = PrintDocument; PrintPreviewDialog.Show(); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void btnSave_Click(object sender, EventArgs e) { //if (validateInput(numStock.Value, numAddStock.Value)) //{ try { using (ShopDBEntities db = new ShopDBEntities()) { int id = Convert.ToInt32(txtID.Text); var item = db.Items.SingleOrDefault(c => c.ItemID == id); item.Qty = item.Qty + Convert.ToInt32(numAddStock.Value); db.Entry(item).State = EntityState.Modified; db.SaveChanges(); Notifications.Notfication("Item Updated Successfully!", txtName.Text + " quantity updated successfully", Color.Green); initiate(); } } catch (Exception ex) { MessageBox.Show("Error\n:" + ex.Message); } //} //else //{ // MessageBox.Show("Error"); //} }
public SupplierViewModel GetSupplierById(int id) { using (ShopDBEntities db = new ShopDBEntities()) { SupplierViewModel supply = new SupplierViewModel(); Supplier supplier = db.Supplier.Find(id); supply.Id = supplier.Id; supply.CompanyName = supplier.CompanyName; supply.ContactName = supplier.ContactName; supply.ContactTitle = supplier.ContactTitle; supply.City = supplier.City; supply.Country = supplier.Country; supply.Phone = supplier.Phone; supply.Fax = supplier.Fax; supply.Produk = (from x in db.Product where x.SupplierId == id select new ProductViewModel { ProductName = x.ProductName, UnitPrice = x.UnitPrice, Package = x.Package, IsDiscontinued = x.IsDiscontinued }).ToList(); return(supply); } }
//public void EditCustomer(OrderViewModel order) //{ // using (ShopDBEntities db = new ShopDBEntities()) // { // OrderViewModel model = new OrderViewModel(); // model.CustomerId = order.CustomerId; // model.OrderDate = order.OrderDate.ToString(); // model.OrderNumber = order.OrderNumber; // model.TotalAmount = order.TotalAmount; // db.Entry(model).State = EntityState.Modified; // db.SaveChanges(); // } //} //public void DeleteCustomer(int id) //{ // using (ShopDBEntities db = new ShopDBEntities()) // { // Order order = db.Order.Find(id); // db.Order.Remove(order); // db.SaveChanges(); // } //} public List <OrderViewModel> SearchOrder(string ordrNumb, string Date, string cust) { using (ShopDBEntities db = new ShopDBEntities()) { var list = db.Order.ToList(); List <OrderViewModel> ListVM = new List <OrderViewModel>(); DateTime ordDate = new DateTime(); if (!string.IsNullOrEmpty(Date)) { ordDate = DateTime.Parse(Date.Replace("-", "/")).Date; } foreach (var item in list) { if ( (item.OrderNumber.Contains(ordrNumb) || string.IsNullOrEmpty(ordrNumb) || string.IsNullOrWhiteSpace(ordrNumb)) && (string.IsNullOrWhiteSpace(Date) || string.IsNullOrEmpty(Date) || item.OrderDate == ordDate) && (string.IsNullOrEmpty(cust) || string.IsNullOrWhiteSpace(cust) || item.CustomerId == int.Parse(cust)) ) { OrderViewModel viewModel = new OrderViewModel(); viewModel.Id = item.Id; viewModel.OrderNumber = item.OrderNumber; viewModel.CustomerId = item.CustomerId; viewModel.CustomerName = item.Customer.FirstName + " " + item.Customer.LastName; viewModel.OrderDate = item.OrderDate; viewModel.TotalAmount = item.TotalAmount; ListVM.Add(viewModel); } } return(ListVM); } }
private void metroButton3_Click(object sender, EventArgs e) { try { using (ShopDBEntities _context = new ShopDBEntities()) { var item = _context.Items.SingleOrDefault(c => c.ItemID == updateID); _context.Items.Remove(item); _context.Entry(item).State = EntityState.Deleted; try { _context.SaveChanges(); } catch (Exception ex) { MessageBox.Show(ex.Message); return; } Notifications.Notfication("Deleted successfully!", tbName.Text + " deleted successfully.", Color.Green); initiate(); } } catch (NullReferenceException) { MessageBox.Show("Please select Item to update and try again.", "No Selection", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } }
private void metroButton2_Click(object sender, EventArgs e) { try { using (ShopDBEntities _context = new ShopDBEntities()) { var item = _context.Items.SingleOrDefault(c => c.ItemID == updateID); item.Name = tbName.Text; item.Description = tbDesc.Text; item.CatID = Convert.ToInt32(cbCat.SelectedValue); item.PurchasePrice = Convert.ToDecimal(txtPPrice.Text); item.Saleprice = Convert.ToDecimal(txtSPrice.Text); item.DiscountPercent = Convert.ToInt32(numDPercent.Value); item.Qty = Convert.ToInt32(numQty.Value); item.UserID = 5; item.DateUpdated = DateTime.Now; _context.Entry(item).State = EntityState.Modified; _context.SaveChanges(); Notifications.Notfication("Item Updated successfully!", tbName.Text + " updated successfully", Color.Green); initiate(); //MessageBox.Show("updated"); } } catch (NullReferenceException ex) { MessageBox.Show("Please select Item to update and try again.", "No Selection", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } }
private void SetUserRating(float val) { string userID = Request.Form["userID"]; string voterID = Request.Form["voterID"]; using (ShopDBEntities db = new ShopDBEntities()) { if (db.UserRaiting.Any(m => m.UserID == userID && m.VoterID == voterID)) { var userRaiting = db.UserRaiting.First(m => m.UserID == userID && m.VoterID == voterID); if (userRaiting.Rating != val) { Response.Write("raiting changed"); userRaiting.Rating = val; } else { Response.Write("nothing changed"); } } else { Response.Write("new raiting"); db.UserRaiting.Add(new UserRaiting() { UserID = userID, VoterID = voterID, Rating = val }); } db.SaveChanges(); } }
public static void Task5(ShopDBEntities db) { Console.WriteLine(" --- Task 5 ---"); var query = from product in db.Products where product.UnitPrice >= (db.Products.OrderByDescending(p => p.UnitPrice).FirstOrDefault()).UnitPrice select product; var query2 = (from product in db.Products group product.ProductName by product.UnitPrice into p orderby p.Key descending select p).Take(1); Console.WriteLine(" - query1 "); foreach (var row in query) { Console.WriteLine($" {row.ProductName} - {row.UnitPrice}"); } Console.WriteLine(" - query2 "); foreach (var row in query2)// .SelectMany(p => p)) { foreach (var name in row.Select(p => p)) { Console.WriteLine("" + name + " - " + row.Key); } } }
private void btnLogin_Click(object sender, EventArgs e) { //MessageBox.Show(cboUser.SelectedValue.ToString() + " " + txtPass.Text); using (ShopDBEntities db = new ShopDBEntities()) { int userid = Convert.ToInt32(cboUser.SelectedValue); var user = db.Users.SingleOrDefault(u => u.UserID == userid); string pass = security.Decrypt(user.Password, true); //MessageBox.Show("Password: "******"Authorization OK!", "Welcome " + cboUser.Text, System.Drawing.Color.Green); this.Hide(); frMain f = new frMain(); f.Show(); } else { MessageBox.Show("Password error. please try again with valid password.", "Error Password", MessageBoxButtons.OK, MessageBoxIcon.Error); return; txtPass.Clear(); txtPass.Focus(); } } }
public static void Task3(ShopDBEntities db) { Console.WriteLine(" --- Task 3 ---"); var endTime = DateTime.Now; var startTime = new DateTime(endTime.Year, endTime.Month, 1).AddMonths(-1); Console.WriteLine("" + startTime + " - " + endTime); var query = from detail in db.OrderDetails where startTime <= detail.Order.OrderDate && detail.Order.OrderDate <= endTime select new { price = detail.Quantity * detail.Product.UnitPrice, date = detail.Order.OrderDate, id = detail.OrderId }; //).Sum(o => o.price); //var query = (from detail in db.OrderDetails // where startTime <= detail.Order.OrderDate && detail.Order.OrderDate <= endTime // group detail.Product.UnitPrice * detail.Quantity by detail.OrderId into o // select new { orderId = o.Key, sum = o.Sum() }).Sum(p => p.sum); //Console.WriteLine("Orders sum: " + query.Value ?? "null (no orders?)"); foreach (var rowInfo in query) { Console.WriteLine("Orders: " + rowInfo.id + " (" + rowInfo.date + ") " + "sum: " + rowInfo.price); } Console.WriteLine("Total sum: " + query.Sum(p => p.price).Value); }
// Select * from Customer public List <OrderViewModel> GetAllOrder() { using (ShopDBEntities db = new ShopDBEntities()) { var order = db.Order.Include(o => o.Customer); List <OrderViewModel> orderVM = new List <OrderViewModel>(); foreach (var item in order) { OrderViewModel model = new OrderViewModel(); model.Id = item.Id; model.OrderDate = item.OrderDate.ToShortDateString(); model.OrderDateFormat = item.OrderDate; model.OrderNumber = item.OrderNumber; model.CustomerName = item.Customer.FirstName + " " + item.Customer.LastName; model.CustomerId = item.CustomerId; model.TotalAmount = item.TotalAmount; orderVM.Add(model); } return(orderVM); } }
public void InsertUserInformation(UserInformation info) { ShopDBEntities db = new ShopDBEntities(); db.UserInformations.Add(info); db.SaveChanges(); }
public List <OrderViewModel> GetAllOrder() { using (ShopDBEntities db = new ShopDBEntities()) { List <OrderViewModel> listOrder = new List <OrderViewModel>(); var model = (from o in db.Orders join c in db.Customers on o.CustomerId equals c.Id select new OrderViewModel { CustomerId = o.CustomerId, CustomerName = c.FirstName + " " + c.LastName, Id = o.Id, OrderDate = o.OrderDate, OrderNumber = o.OrderNumber, TotalAmount = o.TotalAmount } ).ToList(); return(model); //foreach (var item in) //{ // OrderViewModel orderView = new OrderViewModel(); // orderView.Id = item.Id; // orderView.OrderDate = item.OrderDate; // orderView.OrderNumber = item.OrderNumber; // orderView.CustomerId = item.CustomerId; // orderView.TotalAmount = item.TotalAmount; // listOrder.Add(orderView); //} //return listOrder; } }
//searching public List <CustomerViewModels> SearchBy(string nama, string city, string email) { using (ShopDBEntities db = new ShopDBEntities()) { var list = db.Customer.ToList(); List <CustomerViewModels> listVM = new List <CustomerViewModels>(); foreach (var item in list) { if (item.Email == null) { item.Email = " "; } if (((item.FirstName.ToLower() + " " + item.LastName.ToLower()).Contains(nama.ToLower()) || string.IsNullOrEmpty(nama) || string.IsNullOrWhiteSpace(nama)) && (item.City.ToLower().Contains(city.ToLower()) || item.Country.ToLower().Contains(city.ToLower()) || string.IsNullOrEmpty(city) || string.IsNullOrWhiteSpace(city)) && (item.Email.ToLower().Contains(email.ToLower()) || string.IsNullOrEmpty(email) || string.IsNullOrWhiteSpace(email))) { CustomerViewModels viewModel = new CustomerViewModels(); viewModel.Id = item.Id; viewModel.FirstName = item.FirstName; viewModel.LastName = item.LastName; viewModel.City = item.City; viewModel.Country = item.Country; viewModel.Phone = item.Phone; viewModel.Email = item.Email; listVM.Add(viewModel); } } return(listVM); } }
public List <OrderViewModel> Search(string OrderNumber, string Date, string CustomerId) { using (ShopDBEntities db = new ShopDBEntities()) { List <OrderViewModel> orderan = new List <OrderViewModel>(); DateTime Date2 = new DateTime(); if (!string.IsNullOrEmpty(Date)) { Date2 = DateTime.Parse(Date).Date; } foreach (var item in db.Order.ToList()) { if ( (item.OrderNumber.ToLower().Contains(OrderNumber.ToLower()) || string.IsNullOrWhiteSpace(OrderNumber) || string.IsNullOrEmpty(OrderNumber)) && (string.IsNullOrEmpty(Date) || string.IsNullOrWhiteSpace(Date) || item.OrderDate == Date2) && (string.IsNullOrWhiteSpace(CustomerId) || string.IsNullOrEmpty(CustomerId) || item.CustomerId == int.Parse(CustomerId)) ) { OrderViewModel order = new OrderViewModel(); order.Id = item.Id; order.OrderDate = item.OrderDate; order.OrderNumber = item.OrderNumber; order.CustomerId = item.CustomerId; order.TotalAmount = item.TotalAmount; order.CustomerName = item.Customer.FirstName + " " + item.Customer.LastName; orderan.Add(order); } } return(orderan); } }
public void AddNewCustomer(CustomerViewModel customer) { using (ShopDBEntities db = new ShopDBEntities()) { using (var dbContextTransaction = db.Database.BeginTransaction()) { try { Customer model = new Customer(); model.FirstName = customer.FirstName; model.LastName = customer.LastName; model.City = customer.City; model.Country = customer.Country; model.Phone = customer.Phone; model.Email = customer.Email; db.Customer.Add(model); db.SaveChanges(); dbContextTransaction.Commit(); } catch (Exception) { dbContextTransaction.Rollback(); } } } }
public void CreateOrder(OrderViewModel item) { using (ShopDBEntities db = new ShopDBEntities()) { int Id = (db.Order.ToList().Count != 0) ? (from o in db.Order orderby o.Id descending select o.Id).First() + 1 : 1; Order order = new Order(); order.OrderDate = item.OrderDate; order.OrderNumber = item.OrderNumber; order.CustomerId = item.CustomerId; order.TotalAmount = item.TotalAmount; db.Order.Add(order); OrderItem orderitem = new OrderItem(); foreach (var things in item.orderItem) { orderitem.OrderId = Id; orderitem.ProductId = things.ProductId; orderitem.UnitPrice = things.UnitPrice; orderitem.Quantity = things.Quantity; db.OrderItem.Add(orderitem); db.SaveChanges(); } } }
//For search bar public List <CustomerViewModel> GetAllCustomerSearch(string name, string region, string mail) { using (ShopDBEntities db = new ShopDBEntities()) { List <CustomerViewModel> Pelanggan = new List <CustomerViewModel>(); foreach (var item in db.Customer.ToList()) { if (string.IsNullOrEmpty(item.Email)) { item.Email = " "; } if ( ((item.FirstName.ToLower() + " " + item.LastName.ToLower()).Contains(name.ToLower()) || string.IsNullOrWhiteSpace(name) || string.IsNullOrEmpty(name)) && (string.IsNullOrEmpty(region) || string.IsNullOrWhiteSpace(region) || (item.City.ToLower() + " " + item.Country.ToLower()).Contains(region.ToLower())) && (string.IsNullOrWhiteSpace(mail) || string.IsNullOrEmpty(mail) || item.Email.ToLower().Contains(mail.ToLower())) ) { CustomerViewModel customer = new CustomerViewModel(); customer.Id = item.Id; customer.FirstName = item.FirstName; customer.LastName = item.LastName; customer.City = item.City; customer.Country = item.Country; customer.Phone = item.Phone; customer.Email = item.Email; Pelanggan.Add(customer); } } return(Pelanggan); } }
public void CreateNewOrder(OrderViewModel model) { using (ShopDBEntities db = new ShopDBEntities()) { Order order = new Order(); order.OrderDate = model.OrderDate; order.OrderNumber = model.OrderNumber; order.CustomerId = model.CustomerId; order.TotalAmount = model.TotalAmount; db.Order.Add(order); db.SaveChanges(); foreach (var item in model.OrderItem) { OrderItem orderItem = new OrderItem(); orderItem.OrderId = (from p in db.Order orderby p.Id descending select p.Id).First(); orderItem.ProductId = item.ProductId; orderItem.UnitPrice = item.UnitPrice; orderItem.Quantity = item.Quantity; db.OrderItem.Add(orderItem); db.SaveChanges(); } } }
public List <CustomerViewModel> SearchCustomer(string nama, string cityCountry, string email) { using (ShopDBEntities db = new ShopDBEntities()) { var list = db.Customer.ToList(); List <CustomerViewModel> ListVM = new List <CustomerViewModel>(); foreach (var item in list) { if (string.IsNullOrEmpty(item.Email)) { item.Email = " "; } if ( (item.FirstName.ToLower().Contains(nama.ToLower()) || item.LastName.ToLower().Contains(nama.ToLower()) || (item.FirstName.ToLower() + " " + item.LastName.ToLower()).Contains(nama.ToLower()) || string.IsNullOrEmpty(nama) || string.IsNullOrWhiteSpace(nama)) && (item.City.ToLower().Contains(cityCountry.ToLower()) || item.Country.ToLower().Contains(cityCountry.ToLower()) || string.IsNullOrEmpty(cityCountry) || string.IsNullOrWhiteSpace(cityCountry) && (item.Email.ToLower().Contains(cityCountry.ToLower()) || string.IsNullOrEmpty(email) || string.IsNullOrWhiteSpace(email)) )) { CustomerViewModel viewModel = new CustomerViewModel(); viewModel.Id = item.Id; //klo di edit harus semuanya ada viewModel.FirstName = item.FirstName; viewModel.LastName = item.LastName; viewModel.City = item.City; viewModel.Country = item.Country; viewModel.Phone = item.Phone; viewModel.Email = item.Email; ListVM.Add(viewModel); } } return(ListVM); } }
public void AddNewOrder(OrderViewModels order) { using (ShopDBEntities db = new ShopDBEntities()) { //string[] formats = { "dd/MM/yyyy" }; //DateTime oDate = new DateTime();// //oDate = DateTime.Parse(order.OrderDate).Date; //.Pars e(order.OrderDate); Order model = new Order(); model.CustomerId = order.CustomerId; model.OrderDate = order.OrderDate; model.OrderNumber = order.OrderNumber; model.TotalAmount = order.TotalAmount; db.Order.Add(model); db.SaveChanges(); foreach (var item in order.ListOrderItem) { OrderItem modelItem = new OrderItem(); modelItem.OrderId = model.Id; modelItem.ProductId = item.ProductId; modelItem.Quantity = item.Quantity; modelItem.UnitPrice = item.UnitPrice; db.OrderItem.Add(modelItem); db.SaveChanges(); } } }
private void dgv_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex >= 0) { DataGridViewRow row = this.dgv.Rows[e.RowIndex]; ElectricStoreMetro.MainForm.Sale.frModifySales fr = new Sale.frModifySales(); fr.lblOrderNo.Text = row.Cells["OrderNo"].Value.ToString(); fr.lblTotalAmount.Text = row.Cells["TotalAmount"].Value.ToString(); fr.lblSalesTax.Text = row.Cells["SalesTax"].Value.ToString(); fr.lblTotalPayment.Text = row.Cells["TotalPayment"].Value.ToString(); fr.lblDiscount.Text = row.Cells["Discount"].Value.ToString(); fr.lblTotalToPay.Text = row.Cells["TotalToPay"].Value.ToString(); fr.lblPaymentDue.Text = row.Cells["PaymentDue"].Value.ToString(); fr.lblStatus.Text = row.Cells["Name"].Value.ToString(); DataSet ds = ElectricStoreMetro.MainForm.Sale.SelectProductClass.SelectProductsByOrderNo(row.Cells["OrderNo"].Value.ToString()); int custid = Convert.ToInt32(row.Cells["ClientID"].Value); using (ShopDBEntities db = new ShopDBEntities()) { var name = db.Customers.Where(c => c.CustID == custid).Select(c => c.Name).SingleOrDefault(); fr.lblCsutomerID.Text = custid.ToString(); fr.lblCustomerName.Text = name.ToString(); } fr.productDataset = ds; fr.ShowDialog(); } }