private void btnInput_Click(object sender, EventArgs e) { if(GoodsSaleController.PurchaseOrder == null) { btnAdd_Click(null,e); } string deptId = string.Format("{0:000}", CurrentDepartment.Get().DepartmentId); GoodsSaleEventArgs eventArgs = new GoodsSaleEventArgs(); PurchaseOrder searchRetPurchaseOrder = new PurchaseOrder(); searchRetPurchaseOrder.PurchaseOrderPK = new PurchaseOrderPK { PurchaseOrderId = txtRefPurchaseOrder.Text, DepartmentId = CurrentDepartment.Get().DepartmentId }; // if purchase order id is UNDEFINED if (!string.IsNullOrEmpty(txtRefPurchaseOrder.Text) && txtRefPurchaseOrder.Text.Trim().Equals("000")) { if (string.IsNullOrEmpty(txtRetProductName.Text) // product id is notavailable && string.IsNullOrEmpty(txtRetBarCode.Text)) // bar code is not available { MessageBox.Show( "Nếu muốn trả hàng không đối chứng, xin nhập hoá đơn là 000 và chọn một mã vạch phù hợp."); return; } //searchRetPurchaseOrder.PurchaseOrderPK.PurchaseOrderId = deptId + "UNDEF"; } eventArgs.RefPurchaseOrder = searchRetPurchaseOrder; EventUtility.fireEvent(FindRefPurchaseOrder,this,eventArgs); PurchaseOrder retPurchaseOrder = eventArgs.RefPurchaseOrder; PurchaseOrderDetail retOrderDetail = null; if (retPurchaseOrder != null) { foreach (PurchaseOrderDetail orderDetail in retPurchaseOrder.PurchaseOrderDetails) { if (orderDetail.Product.ProductId == txtRetBarCode.Text) { retOrderDetail = orderDetail; break; } } } if (retOrderDetail != null) { retOrderDetail.Quantity = Int64.Parse(txtRetQuantity.Text); retOrderDetail.Price = 0 - retOrderDetail.Price; pODList.Add(retOrderDetail); bdsBill.EndEdit(); dgvBill.Refresh(); dgvBill.Invalidate(); GoodsSaleController.PurchaseOrder.PurchasePrice = CalculateTotalPrice(pODList); txtTotalAmount.Text = GoodsSaleController.PurchaseOrder.PurchasePrice.ToString(); CreateRowNumbers(); CalculateCharge(); RemoveEmptyRowFromList(pODList); ClearReturnInput(); ClearInput(); txtBarcode.Focus(); } else // in case undefined order { // if it's UNDEFINED purchase order if(!string.IsNullOrEmpty(txtRefPurchaseOrder.Text) && txtRefPurchaseOrder.Text.Trim().Equals("000")) { // create new undefined order PurchaseOrder undefPurchaseOrder = new PurchaseOrder(); undefPurchaseOrder.PurchaseOrderPK = new PurchaseOrderPK { PurchaseOrderId = txtRefPurchaseOrder.Text.Trim(), DepartmentId = CurrentDepartment.Get().DepartmentId }; ReturnPurchaseOrder = undefPurchaseOrder; // if defined barcode /*if(!string.IsNullOrEmpty(txtRetProductName.Text)) {*/ PurchaseOrderDetail specialDetail = new PurchaseOrderDetail { Product = new Product()}; specialDetail.Product.ProductId = txtRetBarCode.Text; if (!string.IsNullOrEmpty(specialDetail.Product.ProductId) && specialDetail.Product.ProductId.Equals(CommonConstants.UNDEFINED_BARCODE_MARK)) { specialDetail.Product.ProductId = string.Format("{0:000000000000}", 0); if(CheckUtility.IsNullOrEmpty(txtRetPrice.Text)) { /*MessageBox.Show("Xin hãy nhập giá của sản phẩm không có mã vạch"); return;*/ } specialDetail.Price = Int64.Parse(txtRetPrice.Text); } try // if null , will go to exception { GoodsSaleEventArgs goodsSaleEventArgs = new GoodsSaleEventArgs(); goodsSaleEventArgs.SelectedPurchaseOrderDetail = specialDetail; goodsSaleEventArgs.NotAvailableInStock = true; EventUtility.fireEvent(LoadGoodsEvent, this, goodsSaleEventArgs); txtRetProductName.Text = goodsSaleEventArgs.SelectedPurchaseOrderDetail.Product.ProductMaster.ProductName; txtRetPrice.Text = goodsSaleEventArgs.SelectedPurchaseOrderDetail.Price.ToString(); specialDetail = goodsSaleEventArgs.SelectedPurchaseOrderDetail; specialDetail.PurchaseOrder = ReturnPurchaseOrder; specialDetail.PurchaseOrderDetailPK = new PurchaseOrderDetailPK { DepartmentId = CurrentDepartment.Get().DepartmentId, PurchaseOrderId = ReturnPurchaseOrder.PurchaseOrderPK.PurchaseOrderId }; specialDetail.Quantity = 1; specialDetail.Price = 0 - specialDetail.Price; pODList.Add(specialDetail); bdsBill.EndEdit(); dgvBill.Refresh(); dgvBill.Invalidate(); } catch (Exception ex) { // do nothing MessageBox.Show("Không có mã vạch này"); } finally { GoodsSaleController.PurchaseOrder.PurchasePrice = CalculateTotalPrice(pODList); txtTotalAmount.Text = GoodsSaleController.PurchaseOrder.PurchasePrice.ToString(); CreateRowNumbers(); CalculateCharge(); RemoveEmptyRowFromList(pODList); ClearReturnInput(); ClearInput(); txtBarcode.Focus(); } //} } } }
// ĐANG SỬA LẠI private void txtBarcode_TextChanged(object sender, EventArgs e) { if (!string.IsNullOrEmpty(txtBarcode.Text) && txtBarcode.Text.Length == CommonConstants.PRODUCT_ID_LENGTH) { try { GoodsSaleEventArgs goodsSaleEventArgs = new GoodsSaleEventArgs(); /*int selectedIndex = dgvBill.CurrentCell.OwningRow.Index; goodsSaleEventArgs.SelectedIndex = selectedIndex;*/ btnAdd_Click(this, null); goodsSaleEventArgs.SelectedPurchaseOrderDetail = pODList[pODList.Count - 1] as PurchaseOrderDetail; goodsSaleEventArgs.SelectedPurchaseOrderDetail.Product.ProductId = txtBarcode.Text; // don ma goodsSaleEventArgs.NotAvailableInStock = true; EventUtility.fireEvent(LoadGoodsEvent, this, goodsSaleEventArgs); // event has been modified pODList[pODList.Count-1] = goodsSaleEventArgs.SelectedPurchaseOrderDetail; int totalNumber = 1; Int32.TryParse(txtQuantity.Text, out totalNumber); if(totalNumber <= 0 ) { pODList[pODList.Count - 1].Quantity = 1; } else { pODList[pODList.Count - 1].Quantity = totalNumber; } if(GoodsSaleController.PurchaseOrder== null) { GoodsSaleController.PurchaseOrder = new PurchaseOrder(); } GoodsSaleController.PurchaseOrder.PurchasePrice = CalculateTotalPrice(pODList); txtTotalAmount.Text = GoodsSaleController.PurchaseOrder.PurchasePrice.ToString(); bdsBill.EndEdit(); } catch (Exception ex) { //throw new BusinessException("Mã vạch không hợp lệ hoặc hàng không tồn tại"); pODList.RemoveAt(pODList.Count - 1); } finally { CreateRowNumbers(); CalculateCharge(); RemoveEmptyRowFromList(pODList); ClearInput(); txtBarcode.Focus(); } } }
private void txtRetBarCode_TextChanged(object sender, EventArgs e) { if (!string.IsNullOrEmpty(txtRetBarCode.Text)) { if (txtRetBarCode.Text.Length == CommonConstants.PRODUCT_ID_LENGTH) { txtRetProductName.Text = ""; string returnBarcode = txtRetBarCode.Text.Trim(); try { GoodsSaleEventArgs goodsSaleEventArgs = new GoodsSaleEventArgs(); goodsSaleEventArgs.SelectedPurchaseOrderDetail = new PurchaseOrderDetail {Product = new Product()}; goodsSaleEventArgs.SelectedPurchaseOrderDetail.Product.ProductId = returnBarcode; goodsSaleEventArgs.NotAvailableInStock = true; // load even it do not available in stock EventUtility.fireEvent(LoadGoodsEvent, this, goodsSaleEventArgs); txtRetProductName.Text = goodsSaleEventArgs.SelectedPurchaseOrderDetail.Product.ProductMaster.ProductName; txtRetPrice.Text = goodsSaleEventArgs.SelectedPurchaseOrderDetail.Price.ToString(); } catch (Exception ex) { throw new BusinessException("Mã vạch không hợp lệ hoặc hàng không tồn tại"); //pODList.RemoveAt(pODList.Count - 1); } finally { //ClearReturnInput(); } } } }
private void btnPrint_Click(object sender, EventArgs e) { if (!CheckErrorOnForm()) { return; } if(GoodsSaleController.PurchaseOrder == null || pODList.Count == 0) { MessageBox.Show(" Không có hàng để lưu hóa đơn"); return; } RemoveEmptyProductMasterIdRow(); FormToModel(); if(!string.IsNullOrEmpty(txtCustomer.Text)) { GoodsSaleController.PurchaseOrder.Customer = new Customer{CustomerName = txtCustomer.Text}; } Receipt receipt = new Receipt(); receipt.PurchaseOrder = GoodsSaleController.PurchaseOrder; receipt.ReceiptPK = new ReceiptPK{ DepartmentId = CurrentDepartment.Get().DepartmentId}; receipt.CreateDate = DateTime.Now; receipt.UpdateDate = DateTime.Now; receipt.UpdateId = ClientInfo.getInstance().LoggedUser.Name; receipt.CreateId = ClientInfo.getInstance().LoggedUser.Name; receipt.ReceiptName = "HDBH"; receipt.ReceiptNumber = GoodsSaleController.PurchaseOrder.PurchaseOrderPK.PurchaseOrderId; receipt.TotalAmount = Int64.Parse(string.IsNullOrEmpty(txtTotalAmount.Text)?"0":txtTotalAmount.Text); receipt.CustomerPayment = Int64.Parse(string.IsNullOrEmpty(txtPayment.Text)?"0":txtPayment.Text); receipt.Charge = Int64.Parse(string.IsNullOrEmpty(txtCharge.Text)?"0":txtCharge.Text); GoodsSaleController.PurchaseOrder.Receipts = new ArrayList(); GoodsSaleController.PurchaseOrder.Receipts.Add(receipt); GoodsSaleEventArgs eventArgs = new GoodsSaleEventArgs(); if(ReturnPurchaseOrder!=null) { eventArgs.RefPurchaseOrder = ReturnPurchaseOrder; } EventUtility.fireEvent(SavePurchaseOrderEvent, this, eventArgs); if (eventArgs.HasErrors) { MessageBox.Show("Có lỗi khi lưu hoá đơn"); return; } IList returnDetails = new ArrayList(); IList purchaseDetails = GoodsSaleController.PurchaseOrder.PurchaseOrderDetails; int maxIndex = GoodsSaleController.PurchaseOrder.PurchaseOrderDetails.Count-1; PurchaseOrder purchaseOrder = GoodsSaleController.PurchaseOrder; while(maxIndex >= 0) { PurchaseOrderDetail detail = (PurchaseOrderDetail)purchaseDetails[maxIndex]; if (detail.PurchaseOrder != null && detail.PurchaseOrder.PurchaseOrderPK != null && !string.IsNullOrEmpty(detail.PurchaseOrder.PurchaseOrderPK.PurchaseOrderId) && !detail.PurchaseOrder.PurchaseOrderPK.PurchaseOrderId.Equals(purchaseOrder.PurchaseOrderPK.PurchaseOrderId) ) { if(detail.Price < 0 ) { detail.Price = 0 - detail.Price; } returnDetails.Add(detail); purchaseDetails.RemoveAt(maxIndex); } maxIndex -= 1; } /*printForm = new GoodsSalePrintForm(); printForm.FillForm(GoodsSaleController.PurchaseOrder); printForm.Show(); printForm.Shown += new EventHandler(printForm_Shown);*/ /*reportPurchaseOrder.LocalReport.DataSources.Add(new ReportDataSource("Department",CurrentDepartment.Get())); reportPurchaseOrder.LocalReport.DataSources.Add(new ReportDataSource("PurchaseOrder",GoodsSaleController.PurchaseOrder)); reportPurchaseOrder.LocalReport.DataSources.Add(new ReportDataSource("PurchaseOrderDetail", pODList));*/ PurchaseOrderBill = new LocalReport(); bool isReturnOrder = false; if(returnDetails.Count > 0 ) { PurchaseOrderBill.ReportEmbeddedResource = "AppFrameClient.Report.ReturnPurchaseOrder.rdlc"; receipt.ReceiptName = "HDDTH"; if (purchaseDetails.Count == 0) { receipt.ReceiptNumber = receipt.ReceiptNumber + "RET"; } isReturnOrder = true; } else { receipt.ReceiptName = "HDBH"; PurchaseOrderBill.ReportEmbeddedResource = "AppFrameClient.Report.PurchaseOrder.rdlc"; } this.PurchaseOrderBindingSource.DataSource = goodsSaleController.PurchaseOrder; PurchaseOrderDetailCollection printPOD = new PurchaseOrderDetailCollection(); foreach (PurchaseOrderDetail detail in purchaseDetails) { printPOD.Add(detail); } this.PurchaseOrderDetailCollectionBindingSource.DataSource = CreateNonDuplicate(printPOD); this.ReceiptBindingSource.DataSource = receipt; this.DepartmentBindingSource.DataSource = CurrentDepartment.Get(); PurchaseOrderDetailBindingSource.DataSource = ObjectConverter.ConvertGenericList<PurchaseOrderDetail>(returnDetails); ReportDataSource PODataRDS = new ReportDataSource("AppFrame_Model_PurchaseOrder"); PODataRDS.Value = PurchaseOrderBindingSource; PurchaseOrderBill.DataSources.Add(PODataRDS); ReportDataSource PODetRDS = new ReportDataSource("AppFrame_Collection_PurchaseOrderDetailCollection"); PODetRDS.Value = PurchaseOrderDetailCollectionBindingSource; PurchaseOrderBill.DataSources.Add(PODetRDS); ReportDataSource DepartmentRDS = new ReportDataSource("AppFrame_Model_Department"); DepartmentRDS.Value = DepartmentBindingSource; PurchaseOrderBill.DataSources.Add(DepartmentRDS); ReportDataSource ReceiptRDS = new ReportDataSource("AppFrame_Model_Receipt"); ReceiptRDS.Value = ReceiptBindingSource; PurchaseOrderBill.DataSources.Add(ReceiptRDS); ReportDataSource POReturnDetRDS = new ReportDataSource("AppFrame_Model_PurchaseOrderDetail"); POReturnDetRDS.Value = PurchaseOrderDetailBindingSource; PurchaseOrderBill.DataSources.Add(POReturnDetRDS); /*this.PurchaseOrderDetailBindingSource.DataSource = ObjectConverter.ConvertGenericList<PurchaseOrderDetail>(args.ReturnPurchaseOrderDetails); this.PurchaseOrderDetailCollectionBindingSource.DataSource = pODNewList; this.DepartmentBindingSource.DataSource = CurrentDepartment.Get(); this.PurchaseOrderBindingSource.DataSource = goodsSaleController.PurchaseOrder; this.PurchaseOrderDetailCollectionBindingSource.DataSource = CreateNonDuplicate(pODList); this.ReceiptBindingSource.DataSource = receipt;*/ /*string deviceInfo = "<DeviceInfo>" + " <OutputFormat>EMF</OutputFormat>" + " <PageWidth>3.145in</PageWidth>" + " <PageHeight>5.3in</PageHeight>" + " <MarginTop>0.0in</MarginTop>" + " <MarginLeft>0.0in</MarginLeft>" + " <MarginRight>0.0in</MarginRight>" + " <MarginBottom>0.0in</MarginBottom>" + "</DeviceInfo>"; Warning[] warnings;*/ this.reportPurchaseOrder.LocalReport.Refresh(); PrintDirectlyToPrinter(); ClearGoodsSaleForm(); ClearReturnInput(); ClearInput(); }
void goodsSaleController_CompletedSavePurchaseOrderEvent(object sender, GoodsSaleEventArgs e) { MessageBox.Show("Lưu đơn hàng thành công!"); ClearGoodsSaleForm(); }
void form_SelectProductEvent(object sender, AppFrame.Presenter.GoodsIO.ProductMasterSearchDepartmentEventArgs e) { pODReturnList[dgvBill.CurrentCell.OwningRow.Index].Product = e.ReturnProduct; GoodsSaleEventArgs goodsSaleEventArgs = new GoodsSaleEventArgs(); int selectedIndex = dgvBill.CurrentCell.OwningRow.Index; goodsSaleEventArgs.SelectedIndex = selectedIndex; goodsSaleEventArgs.SelectedPurchaseOrderDetail = bdsBill[selectedIndex] as PurchaseOrderDetail; /*goodsSaleEventArgs.SelectedPurchaseOrderDetail.Product.ProductId = dgvBill.CurrentCell.Value as string;*/ EventUtility.fireEvent(LoadGoodsEvent, this, goodsSaleEventArgs); // event has been modified pODReturnList[selectedIndex] = goodsSaleEventArgs.SelectedPurchaseOrderDetail; bdsReturnBill.EndEdit(); if (form != null) { form.SelectProductEvent -= new EventHandler<AppFrame.Presenter.GoodsIO.ProductMasterSearchDepartmentEventArgs>(form_SelectProductEvent); form.Close(); } }
void goodsSaleReturnView_LoadGoodsEvent(object sender, GoodsSaleEventArgs e) { PurchaseOrderDetail detail = e.SelectedPurchaseOrderDetail; /*ProductMaster prodMaster = ProductMasterLogic.FindById(e.SelectedPurchaseOrderDetail.ProductMaster.ProductMasterId); if (prodMaster == null) { return; }*/ //Product product = ProductLogic.FindById(e.SelectedPurchaseOrderDetail.Product.ProductId); ObjectCriteria objectCriteria = new ObjectCriteria(); objectCriteria.AddEqCriteria("DepartmentStockPK.ProductId", e.SelectedPurchaseOrderDetail.Product.ProductId); objectCriteria.AddEqCriteria("DepartmentStockPK.DepartmentId", CurrentDepartment.Get().DepartmentId); objectCriteria.AddGreaterCriteria("GoodQuantity", (long)0); IList result = DepartmentStockLogic.FindAll(objectCriteria); if (result == null) { throw new BusinessException("Mặt hàng này không tồn tại trong kho !"); } DepartmentStock stock = (DepartmentStock)result[0]; Product product = stock.Product; detail.Product = product; detail.ProductMaster = product.ProductMaster; DepartmentPrice price = DepartmentPriceLogic.FindById(new DepartmentPricePK { DepartmentId = 0, ProductMasterId = detail.ProductMaster.ProductMasterId }); if (price == null) { return; } detail.Price = price.Price; e.SelectedPurchaseOrderDetail = detail; }
void goodsSaleView_LoadGoodsEvent(object sender, GoodsSaleEventArgs e) { PurchaseOrderDetail detail = e.SelectedPurchaseOrderDetail; bool NotAvailableInStock = e.NotAvailableInStock; /*ProductMaster prodMaster = ProductMasterLogic.FindById(e.SelectedPurchaseOrderDetail.ProductMaster.ProductMasterId); if (prodMaster == null) { return; }*/ //Product product = ProductLogic.FindProduct(e.SelectedPurchaseOrderDetail.Product.ProductId,CurrentDepartment.Get().DepartmentId); // TEMP FIXING //NotAvailableInStock = false; ObjectCriteria objectCriteria = new ObjectCriteria(); objectCriteria.AddEqCriteria("DepartmentStockPK.ProductId", e.SelectedPurchaseOrderDetail.Product.ProductId); objectCriteria.AddEqCriteria("DepartmentStockPK.DepartmentId", CurrentDepartment.Get().DepartmentId); if(!NotAvailableInStock) { objectCriteria.AddGreaterCriteria("GoodQuantity", (long) 0); } IList result = DepartmentStockLogic.FindAll(objectCriteria) ; if(!NotAvailableInStock) { if ((result == null || result.Count == 0)) { throw new BusinessException("Mặt hàng này không tồn tại hoặc đã hết !"); } } if ((result == null || result.Count == 0)) { throw new BusinessException("Mặt hàng này không tồn tại !"); } Product product = null; bool NeedSwitchPrdId = false; if (result.Count == 1) { DepartmentStock stock = (DepartmentStock) result[0]; product = stock.Product; if(stock.GoodQuantity <= 0) { NeedSwitchPrdId = true; } } // START ---- don ma /*if (product != null && NeedSwitchPrdId) { ObjectCriteria prdCrit = new ObjectCriteria(); prdCrit.AddEqCriteria("ProductMaster.ProductName", product.ProductMaster.ProductName); IList productIdsList = ProductLogic.FindAll(prdCrit); if (productIdsList != null && productIdsList.Count > 0) { IList productIds = new ArrayList(); foreach (Product prd in productIdsList) { productIds.Add(prd.ProductId); } prdCrit = new ObjectCriteria(); prdCrit.AddSearchInCriteria("DepartmentStockPK.ProductId", productIds); prdCrit.AddEqCriteria("DepartmentStockPK.DepartmentId", CurrentDepartment.Get().DepartmentId); IList allStocks = DepartmentStockLogic.FindAll(prdCrit); if(allStocks != null && allStocks.Count > 0) { SortByGoodQuantity(allStocks); } } }*/ // END ---- don ma /*else { if(CommonConstants.UNDEFINED_BARCODE.Equals(e.SelectedPurchaseOrderDetail.Product.ProductId)) { Product undefProduct = ProductLogic.FindById(e.SelectedPurchaseOrderDetail.Product.ProductId); product = undefProduct; } }*/ detail.Product = product; detail.ProductMaster = product.ProductMaster; DepartmentPrice price = DepartmentPriceLogic.FindById(new DepartmentPricePK { DepartmentId = 0,ProductMasterId = detail.ProductMaster.ProductMasterId} ); if (price == null || price.Price == 0 ) { throw new BusinessException("Giá của mặt hàng " + product.ProductMaster.ProductName + " không có hoặc là 0. Xin kiểm tra lại."); } detail.Price = price.Price; e.SelectedPurchaseOrderDetail = detail; }
void goodsSaleView_NextRecordEvent(object sender, GoodsSaleEventArgs e) { throw new NotImplementedException(); }
void goodsSaleView_FillProductToComboEvent(object sender, GoodsSaleEventArgs e) { ComboBox comboBox = (ComboBox) sender; string originalText = comboBox.Text; Console.WriteLine(this.PurchaseOrder); if (e.IsFillComboBox) { IList result = ProductLogic.FindProductById( e.SelectedPurchaseOrderDetail.Product.ProductId, 20,false); BindingList<Product> products = new BindingList<Product>(); if (result != null) { foreach (Product product in result) { products.Add(product); } } BindingSource bindingSource = new BindingSource(); bindingSource.DataSource = products; comboBox.DataSource = bindingSource; comboBox.DisplayMember = "ProductFullName"; comboBox.ValueMember = e.ComboBoxDisplayMember; comboBox.DropDownWidth = 600; comboBox.DropDownHeight = 200; // keep the original text comboBox.Text = originalText; //comboBox.SelectedIndex = -1; //comboBox.SelectionStart = comboBox.Text.Length; comboBox.DroppedDown = true; comboBox.MaxDropDownItems = 8; comboBox.DropDownWidth = 600; } }
void goodsSaleView_FindRefPurchaseOrder(object sender, GoodsSaleEventArgs e) { PurchaseOrderPK pk = new PurchaseOrderPK { DepartmentId = CurrentDepartment.Get().DepartmentId, PurchaseOrderId = e.RefPurchaseOrder.PurchaseOrderPK.PurchaseOrderId }; PurchaseOrder purchaseOrder = PurchaseOrderLogic.FindById(pk); e.RefPurchaseOrder = purchaseOrder; }
void goodsSaleView_DeleteGoodsEvent(object sender, GoodsSaleEventArgs e) { throw new NotImplementedException(); }
void goodsSaleView_CloseFormEvent(object sender, GoodsSaleEventArgs e) { }
private void txtBarcode_TextChanged(object sender, EventArgs e) { if (!string.IsNullOrEmpty(txtBarcode.Text) && txtBarcode.Text.Length == CommonConstants.PRODUCT_ID_LENGTH) { try { GoodsSaleEventArgs goodsSaleEventArgs = new GoodsSaleEventArgs(); /*int selectedIndex = dgvBill.CurrentCell.OwningRow.Index; goodsSaleEventArgs.SelectedIndex = selectedIndex;*/ btnNewOrderNewRow_Click(this, null); goodsSaleEventArgs.SelectedPurchaseOrderDetail = pODNewList[pODNewList.Count - 1] as PurchaseOrderDetail; goodsSaleEventArgs.SelectedPurchaseOrderDetail.Product.ProductId = txtBarcode.Text; EventUtility.fireEvent(LoadGoodsEvent, this, goodsSaleEventArgs); // event has been modified pODList[pODList.Count - 1] = goodsSaleEventArgs.SelectedPurchaseOrderDetail; int totalNumber = 1; GoodsSaleReturnController.NextPurchaseOrder.PurchasePrice = CalculateTotalPrice(pODNewList); bdsBill.EndEdit(); } catch (Exception ex) { //throw new BusinessException("Mã vạch không hợp lệ hoặc hàng không tồn tại"); pODList.RemoveAt(pODNewList.Count - 1); } finally { txtTotalAmount.Text = CalculateTotalPrice(pODNewList).ToString(); CalculateCharge(); RemoveEmptyAndDuplicateRowFromList(pODNewList); ClearInput(); txtBarcode.Focus(); } } }
private void btnPrint_Click(object sender, EventArgs e) { if (!CheckErrorOnForm()) { return; } if(GoodsSaleController.PurchaseOrder == null || pODList.Count == 0) { MessageBox.Show(" Không có hàng để lưu hóa đơn"); return; } RemoveEmptyProductMasterIdRow(); FormToModel(); if(!string.IsNullOrEmpty(txtCustomer.Text)) { GoodsSaleController.PurchaseOrder.Customer = new Customer{CustomerName = txtCustomer.Text}; } Receipt receipt = new Receipt(); receipt.PurchaseOrder = GoodsSaleController.PurchaseOrder; receipt.ReceiptPK = new ReceiptPK{ DepartmentId = CurrentDepartment.Get().DepartmentId}; receipt.CreateDate = DateTime.Now; receipt.UpdateDate = DateTime.Now; receipt.UpdateId = ClientInfo.getInstance().LoggedUser.Name; receipt.CreateId = ClientInfo.getInstance().LoggedUser.Name; receipt.ReceiptName = "HDBH"; receipt.ReceiptNumber = GoodsSaleController.PurchaseOrder.PurchaseOrderPK.PurchaseOrderId; receipt.TotalAmount = Int64.Parse(string.IsNullOrEmpty(txtTotalAmount.Text)?"0":txtTotalAmount.Text); receipt.CustomerPayment = Int64.Parse(string.IsNullOrEmpty(txtPayment.Text)?"0":txtPayment.Text); receipt.Charge = Int64.Parse(string.IsNullOrEmpty(txtCharge.Text)?"0":txtCharge.Text); GoodsSaleController.PurchaseOrder.Receipts = new ArrayList(); GoodsSaleController.PurchaseOrder.Receipts.Add(receipt); if (GlobalCache.Instance().Session.ContainsKey("EmployeeId")) { string employeeId = GlobalCache.Instance().Session["EmployeeId"] as string; if(!string.IsNullOrEmpty(employeeId)) { GoodsSaleController.PurchaseOrder.CreateId = employeeId; GoodsSaleController.PurchaseOrder.UpdateId = employeeId; foreach (PurchaseOrderDetail purchaseOrderDetail in GoodsSaleController.PurchaseOrder.PurchaseOrderDetails) { purchaseOrderDetail.CreateId = employeeId; purchaseOrderDetail.UpdateId = employeeId; } } } GoodsSaleEventArgs eventArgs = new GoodsSaleEventArgs(); if(ReturnPurchaseOrder!=null) { eventArgs.RefPurchaseOrder = ReturnPurchaseOrder; } EventUtility.fireEvent(SavePurchaseOrderEvent, this, eventArgs); if (eventArgs.HasErrors) { MessageBox.Show("Có lỗi khi lưu hoá đơn"); return; } IList returnDetails = new ArrayList(); IList purchaseDetails = GoodsSaleController.PurchaseOrder.PurchaseOrderDetails; int maxIndex = GoodsSaleController.PurchaseOrder.PurchaseOrderDetails.Count-1; PurchaseOrder purchaseOrder = GoodsSaleController.PurchaseOrder; while(maxIndex >= 0) { PurchaseOrderDetail detail = (PurchaseOrderDetail)purchaseDetails[maxIndex]; if (detail.PurchaseOrder != null && detail.PurchaseOrder.PurchaseOrderPK != null && !string.IsNullOrEmpty(detail.PurchaseOrder.PurchaseOrderPK.PurchaseOrderId) && !detail.PurchaseOrder.PurchaseOrderPK.PurchaseOrderId.Equals(purchaseOrder.PurchaseOrderPK.PurchaseOrderId) ) { if(detail.Price < 0 ) { detail.Price = 0 - detail.Price; } returnDetails.Add(detail); purchaseDetails.RemoveAt(maxIndex); } maxIndex -= 1; } PurchaseOrderBill = new LocalReport(); bool isReturnOrder = false; if(returnDetails.Count > 0 ) { PurchaseOrderBill.ReportEmbeddedResource = "AppFrameClient.Report.ReturnPurchaseOrder.rdlc"; receipt.ReceiptName = "HDDTH"; if (purchaseDetails.Count == 0) { receipt.ReceiptNumber = receipt.ReceiptNumber + "RET"; } isReturnOrder = true; } else { receipt.ReceiptName = "HDBH"; PurchaseOrderBill.ReportEmbeddedResource = "AppFrameClient.Report.PurchaseOrder.rdlc"; } this.PurchaseOrderBindingSource.DataSource = goodsSaleController.PurchaseOrder; PurchaseOrderDetailCollection printPOD = new PurchaseOrderDetailCollection(); foreach (PurchaseOrderDetail detail in purchaseDetails) { printPOD.Add(detail); } this.PurchaseOrderDetailCollectionBindingSource.DataSource = CreateNonDuplicate(printPOD); this.ReceiptBindingSource.DataSource = receipt; this.DepartmentBindingSource.DataSource = CurrentDepartment.Get(); PurchaseOrderDetailBindingSource.DataSource = ObjectConverter.ConvertGenericList<PurchaseOrderDetail>(returnDetails); ReportDataSource PODataRDS = new ReportDataSource("AppFrame_Model_PurchaseOrder"); PODataRDS.Value = PurchaseOrderBindingSource; PurchaseOrderBill.DataSources.Add(PODataRDS); ReportDataSource PODetRDS = new ReportDataSource("AppFrame_Collection_PurchaseOrderDetailCollection"); PODetRDS.Value = PurchaseOrderDetailCollectionBindingSource; PurchaseOrderBill.DataSources.Add(PODetRDS); ReportDataSource DepartmentRDS = new ReportDataSource("AppFrame_Model_Department"); DepartmentRDS.Value = DepartmentBindingSource; PurchaseOrderBill.DataSources.Add(DepartmentRDS); ReportDataSource ReceiptRDS = new ReportDataSource("AppFrame_Model_Receipt"); ReceiptRDS.Value = ReceiptBindingSource; PurchaseOrderBill.DataSources.Add(ReceiptRDS); ReportDataSource POReturnDetRDS = new ReportDataSource("AppFrame_Model_PurchaseOrderDetail"); POReturnDetRDS.Value = PurchaseOrderDetailBindingSource; PurchaseOrderBill.DataSources.Add(POReturnDetRDS); this.reportPurchaseOrder.LocalReport.Refresh(); PrintDirectlyToPrinter(); ClearGoodsSaleForm(); ClearReturnInput(); ClearInput(); }
void goodsSaleView_SavePurchaseOrderEvent(object sender, GoodsSaleEventArgs e) { try { PurchaseOrderLogic.Add(this.PurchaseOrder); e.HasErrors = false; } catch (Exception exception) { e.HasErrors = true; throw exception; } }
private void btnSave_Click(object sender, EventArgs e) { if(!CheckErrorOnForm()) { return; } RemoveEmptyProductMasterIdRow(); FormToModel(); GoodsSaleEventArgs eventArgs = new GoodsSaleEventArgs(); EventUtility.fireEvent(SavePurchaseOrderEvent, this, eventArgs); // clear form and add new if (!eventArgs.HasErrors) { MessageBox.Show("Lưu đơn hàng thành công!"); ClearGoodsSaleForm(); } else { MessageBox.Show(" Có lỗi khi lưu hoá đơn "); } //btnAdd_Click(this, null); }
private void form_SelectNewProductEvent(object sender, ProductMasterSearchDepartmentEventArgs e) { pODNewList[dgvNewBill.CurrentCell.OwningRow.Index].Product = e.ReturnProduct; GoodsSaleEventArgs goodsSaleEventArgs = new GoodsSaleEventArgs(); int selectedIndex = dgvNewBill.CurrentCell.OwningRow.Index; goodsSaleEventArgs.SelectedIndex = selectedIndex; goodsSaleEventArgs.SelectedPurchaseOrderDetail = bdsNewBill[selectedIndex] as PurchaseOrderDetail; /*goodsSaleEventArgs.SelectedPurchaseOrderDetail.Product.ProductId = dgvBill.CurrentCell.Value as string;*/ EventUtility.fireEvent(LoadGoodsEvent, this, goodsSaleEventArgs); // event has been modified if (goodsSaleEventArgs.SelectedPurchaseOrderDetail != null) { pODNewList[selectedIndex] = goodsSaleEventArgs.SelectedPurchaseOrderDetail; bdsNewBill.EndEdit(); txtTotalAmount.Text = CalculateTotalPrice(pODNewList).ToString(); CalculateCharge(); } if (newForm != null) { newForm.SelectProductEvent -= new EventHandler<AppFrame.Presenter.GoodsIO.ProductMasterSearchDepartmentEventArgs>(form_SelectProductEvent); newForm.Close(); } }