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 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 #3
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);
     }
 }
Beispiel #4
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);
            }
        }
Beispiel #5
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 #6
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 #7
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);
            }
        }