Example #1
0
        public static List <SalesAndCollectionModel> LoadAllSalesAndCollections()
        {
            FileSystemUtility.CopyFile(Environment.CurrentDirectory + salesAndCollectionFilePath, Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\Invoiceasy" + salesAndCollectionFilePath, false);

            SalesAndCollectionData = CsvHelperUtility.ReadDataFromFile <SalesAndCollectionModel, SalesAndCollectionModelMap>(salesAndCollectionFilePath);
            SalesAndCollectionData = SalesAndCollectionData.OrderBy(x => x.Date).ToList();
            return(SalesAndCollectionData);
        }
Example #2
0
 public static bool AddNewCollection(SalesAndCollectionModel collection)
 {
     if (CsvHelperUtility.InsertOneNewDataToFile(false, salesAndCollectionFilePath, ",", collection))
     {
         LoadAllSalesAndCollections();
         CalculateOpeningAndClosingBalance(collection.DealerCode);
         return(true);
     }
     else
     {
         return(false);
     }
 }
Example #3
0
        private static void SaveChange()
        {
            SalesAndCollectionData.RemoveAll(item => item == null);
            SalesAndCollectionData = SalesAndCollectionData.OrderBy(x => x.Date).ToList();

            int count = 1;

            foreach (var each in SalesAndCollectionData)
            {
                each.Sl = (count++).ToString();
            }

            CsvHelperUtility.WriteDataToFile <SalesAndCollectionModel>(false, salesAndCollectionFilePath, ",", SalesAndCollectionData);
            LoadAllSalesAndCollections();
        }
Example #4
0
        public static bool AddManyCollections(List <SalesAndCollectionModel> collections)
        {
            if (CsvHelperUtility.InsertManyNewDataToFile(true, salesAndCollectionFilePath, ",", collections))
            {
                LoadAllSalesAndCollections();

                foreach (var collection in collections)
                {
                    CalculateOpeningAndClosingBalance(collection.DealerCode);
                }

                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #5
0
 private static void SaveChange()
 {
     DealerList.RemoveAll(item => item == null);
     CsvHelperUtility.WriteDataToFile <DealerModel>(false, dealerFilePath, ",", DealerList);
     LoadAllDealers();
 }
Example #6
0
 public static List <DealerModel> LoadAllDealers()
 {
     DealerList = CsvHelperUtility.ReadDataFromFile <DealerModel, DealerModelMap>(dealerFilePath);
     return(DealerList);
 }
Example #7
0
 private static void SaveChange()
 {
     ProductList.RemoveAll(item => item == null);
     CsvHelperUtility.WriteDataToFile <ProductModel>(false, productFilePath, ",", ProductList);
     LoadAllProducts();
 }
Example #8
0
 public static List <ProductModel> LoadAllProducts()
 {
     ProductList = CsvHelperUtility.ReadDataFromFile <ProductModel, ProductModelMap>(productFilePath);
     return(ProductList);
 }
Example #9
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();
        }