private void PopupModelControl_Load(object sender, EventArgs e)
        {
            if (_dealer != null)
            {
                CB_PMC_SelectDealer.Text = _dealer.Code;
            }

            if (_dealerList != null)
            {
                LPMC_Title.Text = "ADD New Collection";
                BPMC_Add.Text   = "Add";

                _collection = new SalesAndCollectionModel
                {
                    Id               = Guid.NewGuid().ToString("N"),
                    Sl               = (SalesAndCollectionManager.GetAllSalesAndCollectionsCount() + 1).ToString(),
                    DealerName       = "",
                    Address          = "",
                    Contact          = "",
                    DealerCode       = "",
                    Date             = DTP_PMC_Date.Value.Date,
                    IC_NO            = "",
                    MR_NO            = "",
                    OpeningBalance   = null,
                    SalesAmount      = 0,
                    CollectionAmount = 0,
                    ClosingBalance   = null,
                    Remarks          = "",
                    SyncType         = "Collection"
                };
            }

            BindObjectDataToInterface();
        }
Beispiel #2
0
        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();
        }