/// <summary> /// Thêm mới /// </summary> /// <param name="orderExport"></param> /// <returns></returns> public void Add(OrderExport orderExport) { _context.OrderExports.Add(orderExport); SaveChanges(); }
/// <summary> /// Cập nhật thông tin /// </summary> /// <param name="orderExport"></param> public void Update(OrderExport orderExport) { _context.OrderExports.Attach(orderExport); _context.Entry(orderExport).State = EntityState.Modified; SaveChanges(); }
/// <summary> /// Lưu /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnSave_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(gridLookUpEditEmployees.Text)) { gridLookUpEditEmployees.Properties.Appearance.BorderColor = System.Drawing.Color.Red; XtraMessageBox.Show("Vui lòng chọn Nhân viên!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); gridLookUpEditEmployees.Focus(); } else { string employeeSelect = gridLookUpEditEmployees.EditValue.ToString(); string employeeId = null; if (!string.IsNullOrEmpty(employeeSelect)) { employeeId = employeeSelect; } var orderExport = new OrderExport() { OrderExportID = txtOrderExportID.Text, EmployeeID = employeeId, ExportDate = dateEditExportDate.DateTime, Total = Convert.ToInt32(_total), //Price = Convert.ToInt32(_price), IsActive = true, }; try { _orderExportService.Add(orderExport); foreach (Cart cart in _order.Carts) { InsertOrderExportDetail(txtOrderExportID.Text, cart.ProductId, cart.Quantity, cart.Price, cart.Total); _inventoryService.InsertOrUpdateInventoryExport(cart.ProductId, cart.Quantity, txtOrderExportID.Text); } if (_order.Carts.Count > 0) { _order.Carts.Clear(); } XtraMessageBox.Show("Xuất kho thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); gridControlStockExport.DataSource = null; ResetProductControls(); ResetSupplierControls(); EnabledButtonSaveAndPrint(false); // Tạo tiếp ID txtOrderExportID.Text = _orderExportService.NextId(); } catch (SqlException ex) { XtraMessageBox.Show(string.Format("Lỗi! \n {0}", ex.Message), "Thông báo lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (Exception ex) { XtraMessageBox.Show(string.Format("Lỗi! \n {0}", ex.Message), "Thông báo lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }