protected void Page_Load(object sender, EventArgs e)
 {
     if (!Page.IsPostBack)
     {
         Load_Data_Grid();
         load_dropdown();
         SaleInvoice    s            = new SaleInvoice();
         tblSaleInvoice salesinvoice = new tblSaleInvoice();
         int            maxid        = s.GetId();
         lblInvoiceNo.Text = (maxid + 1).ToString();
     }
 }
 public bool Add(tblSaleInvoice obj)
 {
     try
     {
         repository.tblSaleInvoices.Add(obj);
         repository.SaveChanges();
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
 public bool Delete(int id)
 {
     try
     {
         tblSaleInvoice result = Get(id);
         if (result != null)
         {
             result.Deleted = true;
             repository.SaveChanges();
             return(true);
         }
         return(false);
     }
     catch (Exception)
     {
         return(false);
     }
 }
 public bool Update(tblSaleInvoice obj)
 {
     try
     {
         tblSaleInvoice result = Get(obj.InvoiceId);
         if (result != null)
         {
             repository.Entry(result).CurrentValues.SetValues(obj);
             repository.SaveChanges();
             return(true);
         }
         return(false);
     }
     catch (Exception)
     {
         return(false);
     }
 }
        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (DropDownList1.SelectedValue == "0")
            {
                this.ShowErrorNotification("Please select proper id");
            }
            else
           {
            Load_Data_Grid();
            lblCustName.Visible = true;
            gridProduct1.Visible = true;
            lblTotal1.Visible = true; 
            txtDiscount1.Visible = true;
            txtTax1.Visible = true;
            lblNetTotal1.Visible = true;
            SaleInvoice repository = new SaleInvoice();
            tblSaleInvoice saleInvoice = repository.Get(Convert.ToInt32(DropDownList1.SelectedValue));
            Customer c = new Customer();
            tblCustomer cust = c.Get(saleInvoice.CustomerId);
            lblCustName.Text = cust.Firstname + " " +cust.Lastname;
            lblTotal1.Text= saleInvoice.TotalSale.ToString();
            txtTax1.Text= saleInvoice.Tax.ToString();
            txtDiscount1.Text=saleInvoice.Discount.ToString();
            lblNetTotal1.Text=saleInvoice.NetSale.ToString();

            SaleInvoiceDetail repo = new SaleInvoiceDetail();
            tblSaleInvoiceDetail sid = new tblSaleInvoiceDetail();
            
IEnumerable<tblSaleInvoiceDetail> enume= repo.GetOnInvoiceId(Convert.ToInt32(saleInvoice.InvoiceId));
            var enumer= enume.GetEnumerator();
            while (enumer.MoveNext())
            {
                int rowindex = enumer.Current.ProductId - 1;
                CheckBox cb = (CheckBox)gridProduct1.Rows[rowindex].FindControl("chkbox1");
                cb.Checked = true;
                
                TextBox txt = (TextBox)gridProduct1.Rows[rowindex].FindControl("txtQuantity");
                txt.Visible = true;
                txt.Text = enumer.Current.Quantity.ToString();

            }
            total = Convert.ToDouble(lblTotal1.Text);
           }
        }
        public bool Bulk_Insert(tblSaleInvoice order, List <tblSaleInvoiceDetail> orderDetails)
        {
            try
            {
                foreach (var item in orderDetails)
                {
                    order.tblSaleInvoiceDetails.Add(item);
                }

                repository.tblSaleInvoices.Add(order);
                repository.SaveChanges();

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Exemplo n.º 7
0
        public SavingResult SaveRecord(SaleInvoiceViewModel ViewModel)
        {
            SavingResult res = new SavingResult();

            using (dbUltraCoralEntities db = new dbUltraCoralEntities())
            {
                if (ViewModel.SaleInvoiceID != 0 && CheckDuplicate(ViewModel.SaleInvoiceID, ViewModel.InvoiceNo))
                {
                    res.ExecutionResult = eExecutionResult.ValidationError;
                    res.ValidationError = "Can not accept duplicate values. The Cultivation Type name is already exists.";
                    return(res);
                }
                else
                {
                    //var x = from p in db.tblProducts
                    //        join ps in db.tblProductSizes on p.SizeID equals ps.ProductSizeID
                    //        join vm in ViewModel.Products on p.ProductID equals vm.ProductID
                    //        where (ps.QuanReq ?? false) == true && vm.Qty == 0
                    //        select new { count = 1 };
                    if (ViewModel.Products.Count(r => r.IsQtyReq && r.Qty == 0) > 0)
                    {
                        res.ExecutionResult = eExecutionResult.ValidationError;
                        res.ValidationError = "Please enter quantity in per plyp and per head size products.";
                        return(res);
                    }
                }

                tblSaleInvoice SaveModel = null;
                if (ViewModel.SaleInvoiceID == 0)
                {
                    SaveModel = new tblSaleInvoice()
                    {
                        InvoiceNo = GenerateNextInvoiceNo(db),
                        rcdt      = DateTime.Now,
                        rcuid     = Common.Props.LoginUser.UserID
                    };
                    db.tblSaleInvoices.Add(SaveModel);

                    //if((ViewModel.SaleOrderID ?? 0) != 0)
                    //{
                    //    tblSaleOrder SaleOrder = db.tblSaleOrders.Find(ViewModel.SaleOrderID);
                    //    SaleOrder.tblSaleInvoice = SaveModel;
                    //    db.tblSaleOrders.Attach(SaleOrder);
                    //    db.Entry(SaleOrder).State = System.Data.Entity.EntityState.Modified;
                    //}
                }
                else
                {
                    SaveModel = db.tblSaleInvoices.FirstOrDefault(r => r.SaleInvoiceID == ViewModel.SaleInvoiceID);
                    if (SaveModel == null)
                    {
                        res.ExecutionResult = eExecutionResult.ValidationError;
                        res.ValidationError = "Selected user has been deleted over network. Can not find user's details. Please retry.";
                        return(res);
                    }

                    SaveModel.redt  = DateTime.Now;
                    SaveModel.reuid = Common.Props.LoginUser.UserID;

                    db.tblSaleInvoices.Attach(SaveModel);
                    db.Entry(SaveModel).State = System.Data.Entity.EntityState.Modified;

                    foreach (tblSaleInvoiceProductDetail SIPD in SaveModel.tblSaleInvoiceProductDetails)
                    {
                        tblProduct Product = db.tblProducts.Find(SIPD.ProductID);
                        if (Product != null)
                        {
                            Product.CurrentStock += SIPD.Quan;
                            db.tblProducts.Attach(Product);
                            db.Entry(Product).State = System.Data.Entity.EntityState.Modified;
                        }
                    }
                    db.tblSaleInvoiceProductDetails.RemoveRange(db.tblSaleInvoiceProductDetails.Where(r => r.SaleInvoiceID == ViewModel.SaleInvoiceID));
                }

                //SaveModel.SaleOrderID = ViewModel.SaleOrderID;
                SaveModel.InvoiceDate         = ViewModel.InvoiceDate;
                SaveModel.InvoiceNo           = ViewModel.InvoiceNo;
                SaveModel.SaleInvoiceStatusID = ViewModel.SaleInvoiceStatusID;
                SaveModel.CustomerID          = ViewModel.CustomerID;
                SaveModel.BusinessName        = ViewModel.BusinessName;
                SaveModel.ContactName         = ViewModel.ContactName;
                SaveModel.Address             = ViewModel.Address;
                SaveModel.City                = ViewModel.City;
                SaveModel.Postcode            = ViewModel.Postcode;
                SaveModel.Country             = ViewModel.Country;
                SaveModel.IntPhoneNo          = ViewModel.IntPhoneNo;
                SaveModel.EmailContact        = ViewModel.EMailContact;
                SaveModel.AirportDestCity     = ViewModel.AirportDestCity;
                SaveModel.ShippingDate        = ViewModel.ShippingDate;
                SaveModel.ArrivalDate         = ViewModel.ArrivalDate;
                SaveModel.DomesticFlight      = ViewModel.DomesticFlight;
                SaveModel.InternationalFlight = ViewModel.InternationalFlight;
                //SaveModel.EstDelDate = ViewModel.EstDelDate;
                //SaveModel.FreightAWBNo = ViewModel.AWBNo;
                //SaveModel.FreightAWBNo = ViewModel.AWBNo ?? "";
                //SaveModel.FreightFlight1 = ViewModel.Flight1 ?? "";
                //SaveModel.FreightFlight2 = ViewModel.Flight2 ?? "";
                SaveModel.TotalQuan = (ViewModel.Products.Sum(r => (decimal?)r.Qty) ?? 0);
                SaveModel.TotalGAmt = (ViewModel.Products.Sum(r => (decimal?)r.Amt) ?? 0);

                SaveModel.EstBoxes               = ViewModel.EstBoxes;
                SaveModel.BoxCharges             = ViewModel.BoxCharges;
                SaveModel.DomesticFreightCharges = ViewModel.DomesticFreightCharges;
                SaveModel.IntFreightCharges      = ViewModel.IntFreightCharges;
                SaveModel.TTFee           = ViewModel.TTFee;
                SaveModel.TotalFreight    = ViewModel.TotalFreight;
                SaveModel.PreviousCredit  = ViewModel.PreviousCredit;
                SaveModel.TotalPayableAmt = ViewModel.TotalPayableAmt;


                foreach (SaleInvoiceProducDetailViewModel rp in ViewModel.Products.Where(r => r.Qty != 0))
                {
                    SaveModel.tblSaleInvoiceProductDetails.Add(new tblSaleInvoiceProductDetail()
                    {
                        //tblSaleInvoice = SaveModel,
                        ProductID = rp.ProductID,
                        Rate      = rp.Rate,
                        Quan      = rp.Qty,
                        Amt       = rp.Amt
                    });

                    tblProduct Product = db.tblProducts.Find(rp.ProductID);
                    if (Product != null)
                    {
                        Product.CurrentStock -= rp.Qty;
                        db.tblProducts.Attach(Product);
                        db.Entry(Product).State = System.Data.Entity.EntityState.Modified;
                    }
                }

                //--
                try
                {
                    db.SaveChanges();
                    res.PrimeKeyValue   = SaveModel.SaleInvoiceID;
                    res.ExecutionResult = eExecutionResult.CommitedSucessfuly;
                }
                catch (Exception ex)
                {
                    ex = Common.Functions.FindFinalError(ex);

                    res.ExecutionResult = eExecutionResult.ErrorWhileExecuting;
                    res.Exception       = ex;
                }
            }
            return(res);
        }