private void BindInterfaceDataToObject() { var selectedDealer = _dealerList.Where(x => x.Code.Equals(CB_PMC_SelectDealer.Text)).FirstOrDefault(); _collection.DealerName = selectedDealer.DealerName; _collection.DealerCode = selectedDealer.Code; _collection.Address = selectedDealer.Address; _collection.Contact = selectedDealer.Contact; _collection.MR_NO = TB_PMC_MR_No.Text; _collection.IC_NO = TB_PMC_IC_No.Text; _collection.CollectionAmount = Convert.ToInt32(TB_PMC_CollectionAmount.Text); _collection.Remarks = TB_PMC_Remark.Text; _collection.Date = DTP_PMC_Date.Value.Date; if (_collection.CollectionAmount <= 0 //|| _collection.MR_NO.Equals("") //|| _collection.IC_NO.Equals("") ) { MessageBox.Show("Make sure Collection amount is not 0 "); } else { ConfirmChange(); } void ConfirmChange() { DialogResult dialogResult = MessageBox.Show(BPMC_Add.Text + " Collection? ", "Confirm Change?", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { if (_collection != null) { if (BPMC_Add.Text.Equals("Add")) { if (SalesAndCollectionManager.AddNewSale(_collection)) { MessageBox.Show("Collection Added successfully!"); ReloadDealerControl(); } else { MessageBox.Show("Error! Something went wrong!!"); } } } else { } } else if (dialogResult == DialogResult.No) { //do something else } void ReloadDealerControl() { _hPanel.Controls.Clear(); _salesAndCollectionControl = new SalesAndCollectionControl(_hPanel, _vPanel); _hPanel.Controls.Add(_salesAndCollectionControl); _salesAndCollectionControl.Dock = DockStyle.Fill; _salesAndCollectionControl.Show(); _popUpForm.Close(); } } }
private void BackgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { IC_ProgressPanel.Visible = false; InvoiceProgressBar.Visible = false; _vPanel.Enabled = true; _hPanel.Enabled = true; void UpdateProductStock() { foreach (var item in _invoicePage.AllProducts) { var product = _productList.Where(x => x.ProductCode.Equals(item.ProductCode)).FirstOrDefault(); if (product != null) { if (_itemList != null) { var previousItem = _itemList.Where(x => x.ProductCode.Equals(item.ProductCode)).FirstOrDefault(); product.StockAvailable += previousItem.Quantity; } product.StockAvailable -= item.Quantity; } } ProductManager.UpdateAllProducts(_productList); } void SaveInvoiceLogFile() { if (!string.IsNullOrEmpty(_invoicePage.CurrentLogFile)) { _invoicePage.PreviousLogFile = _invoicePage.CurrentLogFile; FileSystemUtility.DeleteFile(_invoicePage.CurrentLogFile); } Files invoiceLog = new Files(); invoiceLog.FileLocation = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\Invoiceasy\InvoiceLog"; invoiceLog.FileName = "InvoiceLog-" + _invoicePage.No + "_" + DTP_IC_Date.Value.ToString("dd MMMM yyyy") + " " + DateTime.Now.ToString("HH-mm-ss") + ".txt"; _invoicePage.CurrentLogFile = invoiceLog.FileLocation + @"\" + invoiceLog.FileName; invoiceLog.FileText = JsonConvert.SerializeObject(_invoicePage); FileSystemUtility.DeleteFile(_invoicePage.CurrentLogFile); FileSystemUtility.Initialize(true, invoiceLog); FileSystemUtility.WriteFile(); var logFilePath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\Invoiceasy" + @"\InvoiceItems\" + "Invoice-" + _invoicePage.No + "_" + "ItemList_" + DTP_IC_Date.Value.ToString("dd MMMM yyyy HH-mm-ss") + ".txt"; FileSystemUtility.CreateFolder(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\Invoiceasy" + @"\InvoiceItems"); CsvHelperUtility.WriteDataToFile <ItemModel>(true, logFilePath, ",", _invoicePage.AllProducts); } void AddSale() { var sale = new SalesAndCollectionModel { Id = Guid.NewGuid().ToString("N"), Sl = (SalesAndCollectionManager.GetAllSalesAndCollectionsCount() + 1).ToString(), DealerName = _invoicePage.Dealer.DealerName, Address = _invoicePage.Dealer.Address, Contact = _invoicePage.Dealer.Contact, DealerCode = _invoicePage.Dealer.Code, Date = DTP_IC_Date.Value, IC_NO = _invoicePage.No, MR_NO = "", OpeningBalance = null, SalesAmount = _invoicePage.PayableAmount, CollectionAmount = 0, ClosingBalance = null, Remarks = "", SyncType = "Sales" }; if (_invoicePage.sale == null) { _invoicePage.sale = sale; SalesAndCollectionManager.AddNewSale(sale); } else { SalesAndCollectionManager.UpdateSale(_invoicePage.sale, sale); } } BindInterfaceDataToObject(); UpdateProductStock(); AddSale(); SaveInvoiceLogFile(); if (_isSuccess) { MessageBox.Show("Invoice file has been saved successfully"); } else { MessageBox.Show("Error! Something Went Wrong while saving the file"); } LoadChallanForm(); }