Beispiel #1
0
 public static bool SaleUndoDelete(int SaleId)
 {
     try
     {
         using (SellingContext obj = new SellingContext())
         {
             Sale sale = obj.Sales.Single(n => n.SaleId == SaleId);
             sale.IsDeleted        = false;
             obj.Entry(sale).State = System.Data.Entity.EntityState.Modified;
             int RowChangedCount = obj.SaveChanges();
             if (RowChangedCount > 0)
             {
                 return(true);
             }
             else
             {
                 return(false);
             }
         }
     }
     catch (Exception ex)
     {
         BusinessModel.Log.Logger(ex);
         return(false);
     }
 }
Beispiel #2
0
 public static List <Sale> LoadDeletedSaleRecords(string customername, bool _customername, DateTime start, bool _start, DateTime end, bool _end)
 {
     try
     {
         using (SellingContext obj = new SellingContext())
         {
             if (_customername && !_start && !_end)
             {
                 return(obj.Sales.Include("Customer").Where(n => n.IsDeleted == true).OrderByDescending(n => n.Date).ToList().Where(n => n.customer.Name.Equals(customername)).ToList());
             }
             else if (!_customername && _start && _end)
             {
                 return(obj.Sales.Include("Customer").Where(n => n.IsDeleted == true).OrderByDescending(n => n.Date).ToList().Where(n => n.Date.Date >= start.Date && n.Date.Date <= end.Date).ToList());
             }
             else if (_customername && _start && _end)
             {
                 return(obj.Sales.Include("Customer").Where(n => n.IsDeleted == true).OrderByDescending(n => n.Date).ToList().Where(n => (n.Date.Date >= start.Date && n.Date.Date <= end.Date) && n.customer.Name.Equals(customername)).ToList());
             }
             else
             {
                 return(obj.Sales.Include("Customer").Where(n => n.IsDeleted == true).OrderByDescending(n => n.Date).ToList());
             }
         }
     }
     catch (Exception ex)
     {
         BusinessModel.Log.Logger(ex);
         return(null);
     }
 }
 private void frmProductAdd_Load(object sender, EventArgs e)
 {
     try
     {
         AutoCompleteStringCollection source = new AutoCompleteStringCollection();
         txtmaterialtype.AutoCompleteCustomSource = source;
         txtmaterialtype.AutoCompleteMode         = AutoCompleteMode.SuggestAppend;
         txtmaterialtype.AutoCompleteSource       = AutoCompleteSource.CustomSource;
         if (ProductId != -1)
         {
             using (SellingContext obj = new SellingContext())
             {
                 List <Product> products = obj.Products.Where(n => n.ProductId == ProductId).ToList();
                 txtcgst.Text         = products[0].CGST.ToString();
                 txtSGST.Text         = products[0].SGST.ToString();
                 txtIGST.Text         = products[0].IGST.ToString();
                 txtmaterialtype.Text = products[0].material;
                 txtname.Text         = products[0].Name;
                 txtrate.Text         = products[0].Rate.ToString();
             }
         }
     }
     catch (Exception ex)
     {
         BusinessModel.Log.Logger(ex);
     }
 }
Beispiel #4
0
 public static List <string> GetMaterials()
 {
     try
     {
         using (SellingContext obj = new SellingContext())
         {
             return(obj.Products.Select(n => n.material).Distinct().ToList());
         }
     }
     catch (Exception ex)
     {
         BusinessModel.Log.Logger(ex);
         return(null);
     }
 }
Beispiel #5
0
 public static Product GetProductDetails(int ProductId)
 {
     try
     {
         using (SellingContext obj = new SellingContext())
         {
             return(obj.Products.Single(n => n.ProductId == ProductId));
         }
     }
     catch (Exception ex)
     {
         BusinessModel.Log.Logger(ex);
         return(null);
     }
 }
Beispiel #6
0
 public static List <Sale> LoadPendingSaleRecords()
 {
     try
     {
         using (SellingContext obj = new SellingContext())
         {
             return(obj.Sales.Include("Customer").Where(n => n.IsDeleted == false && n.RemainingAmount > 0).OrderByDescending(n => n.Date).ToList());
         }
     }
     catch (Exception ex)
     {
         BusinessModel.Log.Logger(ex);
         return(null);
     }
 }
Beispiel #7
0
 public static Sale GetSaleRecord(int SaleId)
 {
     try
     {
         using (SellingContext obj = new SellingContext())
         {
             return(obj.Sales.Include("customer").Include("saledetails").Single(n => n.SaleId == SaleId));
         }
     }
     catch (Exception ex)
     {
         BusinessModel.Log.Logger(ex);
     }
     return(null);
 }
Beispiel #8
0
 public static List <Customer> LoadDeletedCustomers()
 {
     try
     {
         using (SellingContext obj = new SellingContext())
         {
             return(obj.Customers.Where(n => n.IsDeleted == true).ToList());
         }
     }
     catch (Exception ex)
     {
         BusinessModel.Log.Logger(ex);
     }
     return(null);
 }
Beispiel #9
0
 public static bool SaveProduct(Product product)
 {
     try
     {
         using (SellingContext obj = new SellingContext())
         {
             var            sameproducts = obj.Products.Where(n => n.Name.ToLower().Trim().Equals(product.Name.ToLower().Trim()) && n.IsDeleted == false).ToList();
             List <Product> products     = obj.Products.Where(n => n.ProductId == product.ProductId && n.IsDeleted == false).ToList();
             if (products.Count > 0)
             {
                 int count = sameproducts.Count(n => n.ProductId != product.ProductId);
                 if (count > 0)
                 {
                     MessageBox.Show("Product name is already present,Please enter different name", "Error");
                     return(false);
                 }
                 products[0].CGST     = product.CGST;
                 products[0].IGST     = product.IGST;
                 products[0].material = product.material;
                 products[0].Name     = product.Name;
                 products[0].Rate     = product.Rate;
                 products[0].SGST     = product.SGST;
             }
             if (products.Count == 0)
             {
                 if (sameproducts.Count > 0)
                 {
                     MessageBox.Show("Product name is already present,Please enter different name", "Error");
                     return(false);
                 }
                 obj.Products.Add(product);
                 int RowChangedCount = obj.SaveChanges();
                 return(RowChangedCount > 0 ? true : false);
             }
             else
             {
                 obj.Entry(products[0]).State = System.Data.Entity.EntityState.Modified;
                 int RowChangedCount = obj.SaveChanges();
                 return(RowChangedCount > 0 ? true : false);
             }
         }
     }
     catch (Exception ex)
     {
         BusinessModel.Log.Logger(ex);
         return(false);
     }
 }
Beispiel #10
0
 public static List <SaleDetail> AllMaterialWise(DateTime date1, DateTime date2)
 {
     try
     {
         using (SellingContext obj = new SellingContext())
         {
             var sales = obj.SaleDetails.Include("SaleId").Include("SaleId.customer").Where(nn => (nn.Date.Day >= date1.Day && nn.Date.Month >= date1.Month && nn.Date.Year >= date1.Year) && (nn.Date.Day <= date2.Day && nn.Date.Month <= date2.Month && nn.Date.Year <= date2.Year)).ToList();
             return(sales);
         }
     }
     catch (Exception ex)
     {
         BusinessModel.Log.Logger(ex);
         return(new List <SaleDetail>());
     }
 }
Beispiel #11
0
 public static List <Customer> LoadCustomers()
 {
     try
     {
         using (SellingContext obj = new SellingContext())
         {
             obj.Configuration.ProxyCreationEnabled = false;
             return(obj.Customers.Where(n => n.IsDeleted == false).ToList());
         }
     }
     catch (Exception ex)
     {
         BusinessModel.Log.Logger(ex);
     }
     return(null);
 }
Beispiel #12
0
 public static bool SaveCustomer(Customer customer)
 {
     try
     {
         using (SellingContext obj = new SellingContext())
         {
             List <Customer> Customers     = obj.Customers.Where(n => n.CustomerId == customer.CustomerId && n.IsDeleted == false).ToList();
             var             samecustomers = obj.Customers.Where(n => n.MobileNumber.ToLower().Trim().Equals(customer.MobileNumber.ToLower().Trim()) && n.IsDeleted == false).ToList();
             if (Customers.Count > 0)
             {
                 int count = samecustomers.Count(n => n.CustomerId != customer.CustomerId);
                 if (count > 0)
                 {
                     MessageBox.Show("Customer is already present,Please enter different Mobile", "Error");
                     return(false);
                 }
                 Customers[0].Address      = customer.Address;
                 Customers[0].CustomerId   = customer.CustomerId;
                 Customers[0].MobileNumber = customer.MobileNumber;
                 Customers[0].Name         = customer.Name;
                 Customers[0].GSTNumber    = customer.GSTNumber;
             }
             if (Customers.Count == 0)
             {
                 if (samecustomers.Count > 0)
                 {
                     MessageBox.Show("Customer is already present,Please enter different Mobile", "Error");
                     return(false);
                 }
                 obj.Customers.Add(customer);
                 int RowChangedCount = obj.SaveChanges();
                 return(RowChangedCount > 0 ? true : false);
             }
             else
             {
                 obj.Entry(Customers[0]).State = System.Data.Entity.EntityState.Modified;
                 int RowChangedCount = obj.SaveChanges();
                 return(RowChangedCount > 0 ? true : false);
             }
         }
     }
     catch (Exception ex)
     {
         BusinessModel.Log.Logger(ex);
         return(false);
     }
 }
 private void btnBackup_Click(object sender, EventArgs e)
 {
     try
     {
         using (SellingContext obj = new SellingContext())
         {
             string dbname     = obj.Database.Connection.Database;
             string sqlCommand = @"BACKUP DATABASE " + dbname + " TO DISK='" + txtFileLocation.Text + "'";
             obj.Database.ExecuteSqlCommand(System.Data.Entity.TransactionalBehavior.DoNotEnsureTransaction, string.Format(sqlCommand, "", ""));
         }
         MessageBox.Show("Database backup successfully.");
     }
     catch (Exception ex)
     {
         BusinessModel.Log.Logger(ex);
     }
 }
Beispiel #14
0
        public static bool UpdateSaleRecord(Sale sale)
        {
            try
            {
                using (SellingContext obj = new SellingContext())
                {
                    var samesale = obj.Sales.Where(n => n.Invoicenumber == sale.Invoicenumber && n.IsDeleted == false).ToList();

                    int count = samesale.Count(n => n.SaleId != sale.SaleId);
                    if (count > 0)
                    {
                        //MessageBox.Show("Invoice no is already present");
                        return(false);
                    }
                }
                List <SaleDetail> saledetails = sale.saledetails.ToList();
                using (SellingContext obj = new SellingContext())
                {
                    List <SaleDetail> temp = obj.SaleDetails.Include("SaleId").Where(n => n.SaleId.SaleId == sale.SaleId).ToList();
                    foreach (var saledetail in temp)
                    {
                        if (saledetail.SaleDetailId > 0)
                        {
                            var hhhh = obj.Entry(saledetail).State = System.Data.Entity.EntityState.Deleted;
                            int yy   = obj.SaveChanges();
                        }
                    }
                }
                using (SellingContext obj = new SellingContext())
                {
                    sale.saledetails = null;
                    sale.Customer_Id = sale.customer.CustomerId;
                    var ttt  = obj.Entry(sale).State = System.Data.Entity.EntityState.Modified;
                    int yy   = obj.SaveChanges();
                    var ttdt = obj.SaleDetails.AddRange(saledetails);
                    yy = obj.SaveChanges();
                }
                return(true);
            }
            catch (Exception ex)
            {
                BusinessModel.Log.Logger(ex);
                return(false);
            }
        }
 private void btnBackup_Click(object sender, EventArgs e)
 {
     try
     {
         using (SellingContext obj = new SellingContext())
         {
             string dbname     = "KetanShahaDatabase";
             string sqlCommand = @"USE master; RESTORE DATABASE " + dbname + " FROM DISK='" + txtFileLocation.Text + "'";
             obj.Database.ExecuteSqlCommand(System.Data.Entity.TransactionalBehavior.DoNotEnsureTransaction, string.Format(sqlCommand, "", ""));
         }
         MessageBox.Show("Database restored successfully.");
     }
     catch (Exception ex)
     {
         BusinessModel.Log.Logger(ex);
         MessageBox.Show("Error while restoring database");
     }
 }
Beispiel #16
0
 public static bool DeleteProduct(int productId)
 {
     try
     {
         using (SellingContext obj = new SellingContext())
         {
             Product product = obj.Products.Single(n => n.ProductId == productId);
             product.IsDeleted        = true;
             obj.Entry(product).State = System.Data.Entity.EntityState.Modified;
             int RowChangedCount = obj.SaveChanges();
             return(RowChangedCount > 0 ? true : false);
         }
     }
     catch (Exception ex)
     {
     }
     return(false);
 }
Beispiel #17
0
 public static bool DeleteCustomer(int customerId)
 {
     try
     {
         using (SellingContext obj = new SellingContext())
         {
             Customer customer = obj.Customers.Single(n => n.CustomerId == customerId);
             customer.IsDeleted        = true;
             obj.Entry(customer).State = System.Data.Entity.EntityState.Modified;
             int RowChangedCount = obj.SaveChanges();
             return(RowChangedCount > 0 ? true : false);
         }
     }
     catch (Exception ex)
     {
         BusinessModel.Log.Logger(ex);
     }
     return(false);
 }
Beispiel #18
0
 public static List <SaleDetail> MaterialWise(string Materialname, DateTime date1, DateTime date2)
 {
     try
     {
         using (SellingContext obj = new SellingContext())
         {
             var sales = obj.SaleDetails.Include("SaleId").Include("SaleId.customer").Where(nn => (nn.Date.Day >= date1.Day && nn.Date.Month >= date1.Month && nn.Date.Year >= date1.Year) && (nn.Date.Day <= date2.Day && nn.Date.Month <= date2.Month && nn.Date.Year <= date2.Year)).ToList();
             if (sales.Count > 0)
             {
                 var Saledetails = sales.Where(nn => BusinessModel.ProductOperations.GetProductDetails(nn.ProductId).material == Materialname).ToList();
                 return(Saledetails);
             }
             return(new List <SaleDetail>());
         }
     }
     catch (Exception ex)
     {
         BusinessModel.Log.Logger(ex);
         return(new List <SaleDetail>());
     }
 }
 private void frmCustomerAdd_Load(object sender, EventArgs e)
 {
     try
     {
         AutoCompleteStringCollection source = new AutoCompleteStringCollection();
         if (customerId != -1)
         {
             using (SellingContext obj = new SellingContext())
             {
                 List <Customer> Customers = obj.Customers.Where(n => n.CustomerId == customerId).ToList();
                 txtaddress.Text      = Customers[0].Address.ToString();
                 txtmobilenumber.Text = Customers[0].MobileNumber.ToString();
                 txtname.Text         = Customers[0].Name.ToString();
                 txtGSTNumber.Text    = Customers[0].GSTNumber.ToString();
             }
         }
     }
     catch (Exception ex)
     {
         BusinessModel.Log.Logger(ex);
     }
 }
Beispiel #20
0
 public static Product GetProductDetails(string ProductName)
 {
     try
     {
         using (SellingContext obj = new SellingContext())
         {
             var Products = obj.Products.Where(n => n.Name.Equals(ProductName)).ToList();
             if (Products.Count > 0)
             {
                 return(Products[0]);
             }
             else
             {
                 return(null);
             }
         }
     }
     catch (Exception ex)
     {
         BusinessModel.Log.Logger(ex);
         return(null);
     }
 }
Beispiel #21
0
        public static bool SaveSaleRecord(Sale sale, out int BillNo)
        {
            try
            {
                using (SellingContext obj = new SellingContext())
                {
                    var         samesale = obj.Sales.Where(n => n.Invoicenumber == sale.Invoicenumber && n.IsDeleted == false).ToList();
                    Customer    cust     = obj.Customers.Single(n => n.CustomerId == sale.customer.CustomerId);
                    List <Sale> salelst  = obj.Sales.Include("saledetails").Where(n => n.SaleId == sale.SaleId).ToList();
                    sale.customer = cust;
                    if (salelst.Count > 0)
                    {
                        int count = samesale.Count(n => n.SaleId != sale.SaleId);
                        if (count > 0)
                        {
                            MessageBox.Show("Invoice no is already present");
                            BillNo = -1;
                            return(false);
                        }
                        salelst[0].CGST               = sale.CGST;
                        salelst[0].customer           = sale.customer;
                        salelst[0].Date               = sale.Date;
                        salelst[0].FinalTotal         = sale.FinalTotal;
                        salelst[0].IGST               = sale.IGST;
                        salelst[0].IsDeleted          = sale.IsDeleted;
                        salelst[0].PaidAmount         = sale.PaidAmount;
                        salelst[0].PaymentMode        = sale.PaymentMode;
                        salelst[0].PaymentModeDetails = sale.PaymentModeDetails;
                        salelst[0].RemainingAmount    = sale.RemainingAmount;

                        foreach (SaleDetail saled in sale.saledetails)
                        {
                            if (saled.SaleDetailId > 0)
                            {
                                obj.Entry(saled).State = System.Data.Entity.EntityState.Modified;
                                int yy = obj.SaveChanges();
                            }
                        }
                        salelst[0].SGST             = sale.SGST;
                        salelst[0].Total            = sale.Total;
                        salelst[0].TotalTax         = sale.TotalTax;
                        obj.Entry(salelst[0]).State = System.Data.Entity.EntityState.Modified;
                        int RowChangedCount = obj.SaveChanges();


                        List <int> saleid = salelst[0].saledetails.Select(n => n.SaleDetailId).ToList();
                        foreach (int id in saleid)
                        {
                            var temp = obj.SaleDetails.Single(n => n.SaleDetailId == id);
                            obj.Entry(temp).State = System.Data.Entity.EntityState.Deleted;
                        }

                        int ii = obj.SaveChanges();
                        foreach (SaleDetail saled in sale.saledetails)
                        {
                            obj.SaleDetails.Add(saled);
                        }
                        int o = obj.SaveChanges();
                        BillNo = sale.SaleId;
                        return(RowChangedCount > 0 ? true : false);
                    }
                    else
                    {
                        if (obj.Sales.Count(n => n.Invoicenumber == sale.Invoicenumber) != 0)
                        {
                            MessageBox.Show("Invoice number is already present");
                            BillNo = -1;
                            return(false);
                        }
                        sale = obj.Sales.Add(sale);
                        int RowChangedCount = obj.SaveChanges();
                        BillNo = sale.SaleId;
                        return(RowChangedCount > 0 ? true : false);
                    }
                }
            }
            catch (Exception ex)
            {
                BusinessModel.Log.Logger(ex);
                BillNo = 0;
                return(false);
            }
        }