Example #1
0
 internal int DeleteReturn_Temp(int id)
 {
     try
     {
         Inv_Return_Temp buyCentralObj = _context.Inv_Return_Temp.First(x => x.Id == id);
         _context.Inv_Return_Temp.DeleteObject(buyCentralObj);
         _context.SaveChanges();
         return(1);
     }
     catch (Exception)
     {
         throw;
     }
 }
        protected void BtnSave_Click(object sender, EventArgs e)
        {
            try
            {
                List <Inv_Return_Temp> _Inv_Return_Temp = new List <Inv_Return_Temp>();
                //bool status = true;
                bool CheckStatus = false;

                foreach (GridViewRow gvRow in GridShow.Rows)
                {
                    CheckBox rowChkBox = ((CheckBox)gvRow.FindControl("rowLevelCheckBox"));

                    if (rowChkBox.Checked == true)
                    {
                        CheckStatus = true;
                    }
                }

                if (CheckStatus)
                {
                    Guid   user  = (((SessionUser)Session["SessionUser"]).UserId);
                    string Ocode = ((SessionUser)Session["SessionUser"]).OCode.ToString();
                    foreach (GridViewRow gvr in GridShow.Rows)
                    {
                        CheckBox rowChkBox = ((CheckBox)gvr.FindControl("rowLevelCheckBox"));


                        if (rowChkBox.Checked == true)
                        {
                            Inv_Return_Temp returnTemp           = new Inv_Return_Temp();
                            Label           lblproductName       = (Label)gvr.FindControl("lblproductName");
                            Label           lblBrand             = (Label)gvr.FindControl("lblBrand");
                            Label           lblStyleAndSize      = (Label)gvr.FindControl("lblStyleAndSize");
                            Label           lblSupplierReturnQty = (Label)gvr.FindControl("lblSupplierReturnQty");
                            // Label lblCompanyId = (Label)gvr.FindControl("lblCompanyId");
                            // Label lblCompanyName = (Label)gvr.FindControl("lblCompanyName");
                            Label   lblproductGroup    = (Label)gvr.FindControl("lblproductGroup");
                            Label   lblReceiveQuantity = (Label)gvr.FindControl("lblReceiveQuantity");
                            Label   lblCPU             = (Label)gvr.FindControl("lblCPU");
                            Label   lblDeliveryQty     = (Label)gvr.FindControl("lblDeliveryQty");
                            Label   lblOcode           = (Label)gvr.FindControl("lblOcode");
                            Label   lblCompanyCode     = (Label)gvr.FindControl("lblCompanyCode");
                            Label   lblPurchaseDate    = (Label)gvr.FindControl("lblPurchaseDate");
                            Label   lblBalanceQty      = (Label)gvr.FindControl("lblBalanceQty");
                            Label   lblChallanNo       = (Label)gvr.FindControl("lblChallanNo");
                            Label   lblBarCode         = (Label)gvr.FindControl("lblBarCode");
                            Label   lblUnitName        = (Label)gvr.FindControl("lblUnitName");
                            TextBox txtReturnQty       = (TextBox)gvr.FindControl("txtReturnQty");
                            TextBox txtRemarks         = (TextBox)gvr.FindControl("txtRemarks");
                            int     ReturnQty          = int.Parse(txtReturnQty.Text);


                            returnTemp.ChallanNo    = txtChalanNoReturn.Text;
                            returnTemp.Remarks      = txtRemarks.Text;
                            returnTemp.ChallanNo_To = lblChallanNo.Text;
                            if (lblBalanceQty.Text == "")
                            {
                                returnTemp.BalanceQuanity = 0;
                            }
                            else
                            {
                                returnTemp.BalanceQuanity = Convert.ToInt32(lblBalanceQty.Text);
                            }

                            returnTemp.BarCode = lblBarCode.Text;
                            returnTemp.Brand   = lblBrand.Text;
                            if (lblCPU.Text == "")
                            {
                                returnTemp.CPU = 0;
                            }
                            else
                            {
                                returnTemp.CPU = Convert.ToDecimal(lblCPU.Text);
                            }
                            returnTemp.CurrentCompanyCode = lblCompanyCode.Text;
                            if (lblDeliveryQty.Text == "")
                            {
                                returnTemp.DeliveryQty = 0;
                            }
                            else
                            {
                                returnTemp.DeliveryQty = Convert.ToDouble(lblDeliveryQty.Text);
                            }
                            returnTemp.DPT_CODE = "N/A";
                            returnTemp.EditDate = DateTime.Today;

                            returnTemp.EditUser       = user;
                            returnTemp.EID            = "N/A";
                            returnTemp.OCode          = Ocode;
                            returnTemp.OldCompanyCode = CentralCode.ToString();
                            returnTemp.ProductGroup   = lblproductGroup.Text;
                            returnTemp.ProductId      = Convert.ToInt32(lblBarCode.Text);
                            returnTemp.ProductName    = lblproductName.Text;

                            if (lblPurchaseDate.Text == "")
                            {
                                returnTemp.PurchaseDate = DateTime.Today;
                            }
                            else
                            {
                                returnTemp.PurchaseDate = Convert.ToDateTime(lblPurchaseDate.Text);
                            }
                            returnTemp.ProgramId = Convert.ToInt32(ddlProgram.SelectedValue);

                            if (lblReceiveQuantity.Text == "")
                            {
                                returnTemp.ReceiveQuantity = 0;
                            }
                            else
                            {
                                returnTemp.ReceiveQuantity = Convert.ToDouble(lblReceiveQuantity.Text);
                            }

                            //returnTemp.Store_Code = ddlStore.SelectedValue.ToString();
                            returnTemp.StyleSize         = lblStyleAndSize.Text;
                            returnTemp.SupplierCode      = "N/A";
                            returnTemp.SupplierReturnQty = 0;
                            returnTemp.ERetQty           = ReturnQty;
                            returnTemp.UnitName          = lblUnitName.Text;
                            returnTemp.Store_Code        = ddlStoreName.SelectedValue;

                            _context.Inv_Return_Temp.AddObject(returnTemp);
                        }
                    }
                    _context.SaveChanges();


                    ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "text", "func('Return Process Temporary successfully')", true);
                    GridShow.DataSource = null;
                    GridShow.DataBind();
                    List <productsDetails> details = _BuyCentral.GetAllProduct_ReturnTemp_ChallanNo_DPT(user, Ocode).ToList();
                    if (details.Count > 0)
                    {
                        grdTransfer.DataSource = details;
                        grdTransfer.DataBind();
                    }
                    else
                    {
                        grdTransfer.DataSource = null;
                        grdTransfer.DataBind();
                    }
                }
                else
                {
                    ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "text", "func('No Item Selected!')", true);
                }
            }
            catch (Exception ex)
            {
                ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "text", "func('" + ex.Message + "')", true);
            }
        }
        protected void BtnSave_Click(object sender, EventArgs e)
        {
            try
            {
                List <Inv_Return_Temp> _Inv_Return_Temp = new List <Inv_Return_Temp>();
                Guid   user  = (((SessionUser)Session["SessionUser"]).UserId);
                string Ocode = ((SessionUser)Session["SessionUser"]).OCode.ToString();
                //bool status = true;
                bool CheckStatus = false;

                foreach (GridViewRow gvRow in GridShow.Rows)
                {
                    CheckBox rowChkBox = ((CheckBox)gvRow.FindControl("rowLevelCheckBox"));

                    if (rowChkBox.Checked == true)
                    {
                        CheckStatus = true;
                    }
                }

                if (CheckStatus)
                {
                    foreach (GridViewRow gvr in GridShow.Rows)
                    {
                        CheckBox rowChkBox = ((CheckBox)gvr.FindControl("rowLevelCheckBox"));


                        if (rowChkBox.Checked == true)
                        {
                            Inv_Return_Temp returnTemp           = new Inv_Return_Temp();
                            Label           lblproductName       = (Label)gvr.FindControl("lblproductName");
                            Label           lblBrand             = (Label)gvr.FindControl("lblBrand");
                            Label           lblStyleAndSize      = (Label)gvr.FindControl("lblStyleAndSize");
                            Label           lblSupplierReturnQty = (Label)gvr.FindControl("lblSupplierReturnQty");
                            Label           lblCompanyId         = (Label)gvr.FindControl("lblCompanyId");
                            Label           lblCompanyName       = (Label)gvr.FindControl("lblCompanyName");
                            Label           lblproductGroup      = (Label)gvr.FindControl("lblproductGroup");
                            Label           lblReceiveQuantity   = (Label)gvr.FindControl("lblReceiveQuantity");
                            Label           lblCPU          = (Label)gvr.FindControl("lblCPU");
                            Label           lblDeliveryQty  = (Label)gvr.FindControl("lblDeliveryQty");
                            Label           lblOcode        = (Label)gvr.FindControl("lblOcode");
                            Label           lblCompanyCode  = (Label)gvr.FindControl("lblCompanyCode");
                            Label           lblPurchaseDate = (Label)gvr.FindControl("lblPurchaseDate");
                            Label           lblBalanceQty   = (Label)gvr.FindControl("lblBalanceQty");
                            Label           lblChallanNo    = (Label)gvr.FindControl("lblChallanNo");
                            Label           lblBarCode      = (Label)gvr.FindControl("lblBarCode");
                            Label           lblUnitName     = (Label)gvr.FindControl("lblUnitName");
                            TextBox         txtReturnQty    = (TextBox)gvr.FindControl("txtReturnQty");
                            TextBox         txtRemarks      = (TextBox)gvr.FindControl("txtRemarks");
                            int             ReturnQty       = int.Parse(txtReturnQty.Text);


                            returnTemp.ChallanNo    = txtChalanNoReturn.Text;
                            returnTemp.Remarks      = txtRemarks.Text;
                            returnTemp.ChallanNo_To = lblChallanNo.Text;
                            if (lblBalanceQty.Text == "")
                            {
                                returnTemp.BalanceQuanity = 0;
                            }
                            else
                            {
                                returnTemp.BalanceQuanity = Convert.ToInt32(lblBalanceQty.Text);
                            }

                            returnTemp.BarCode = lblBarCode.Text;
                            returnTemp.Brand   = lblBrand.Text;
                            if (lblCPU.Text == "")
                            {
                                returnTemp.CPU = 0;
                            }
                            else
                            {
                                returnTemp.CPU = Convert.ToDecimal(lblCPU.Text);
                            }
                            returnTemp.CurrentCompanyCode = lblCompanyCode.Text;
                            if (lblDeliveryQty.Text == "")
                            {
                                returnTemp.DeliveryQty = 0;
                            }
                            else
                            {
                                returnTemp.DeliveryQty = Convert.ToDouble(lblDeliveryQty.Text);
                            }
                            returnTemp.DPT_CODE = "N/A";
                            returnTemp.EditDate = DateTime.Today;
                            // Guid user = (((SessionUser)Session["SessionUser"]).UserId);
                            returnTemp.EditUser       = user;
                            returnTemp.EID            = "N/A";
                            returnTemp.OCode          = Ocode;
                            returnTemp.OldCompanyCode = CentralCode.ToString();
                            returnTemp.ProductGroup   = lblproductGroup.Text;
                            returnTemp.ProductId      = Convert.ToInt32(lblBarCode.Text);
                            returnTemp.ProductName    = lblproductName.Text;
                            returnTemp.PurchaseDate   = Convert.ToDateTime(lblPurchaseDate.Text);
                            if (lblReceiveQuantity.Text == "")
                            {
                                returnTemp.ReceiveQuantity = 0;
                            }
                            else
                            {
                                returnTemp.ReceiveQuantity = Convert.ToDouble(lblReceiveQuantity.Text);
                            }

                            returnTemp.Store_Code        = ddlStore.SelectedValue.ToString();
                            returnTemp.StyleSize         = lblStyleAndSize.Text;
                            returnTemp.SupplierCode      = ddlSupplierTo.SelectedValue.ToString();
                            returnTemp.SupplierReturnQty = ReturnQty;
                            returnTemp.UnitName          = lblUnitName.Text;
                            returnTemp.ProgramId         = 0;

                            _context.Inv_Return_Temp.AddObject(returnTemp);
                        }
                    }
                    _context.SaveChanges();


                    ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "text", "func('Return Process Temporary successfully')", true);
                    GridShow.DataSource = null;
                    GridShow.DataBind();
                    List <productsDetails> details = _BuyCentral.GetAllProduct_ReturnTemp_ChallanNo_DPT(user, Ocode).ToList();
                    if (details.Count > 0)
                    {
                        grdTransfer.DataSource = details;
                        grdTransfer.DataBind();
                    }
                    else
                    {
                        grdTransfer.DataSource = null;
                        grdTransfer.DataBind();
                    }
                }
                else
                {
                    ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "text", "func('No Item Selected!')", true);
                }
            }
            catch (Exception ex)
            {
                ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "text", "func('" + ex.Message + "')", true);
            }
            //try
            //{

            //    string BarCode = hdnBarCode.Value.ToString();
            //    if (BarCode == string.Empty || txtBalanceQty.Text == string.Empty || ddlSupplierTo.SelectedValue == "0" || ddlStore.SelectedValue == "0" || txtReturnQty.Text == "0")
            //    {
            //        //lblMessage.Text = "<font color='red'>Invalid data. Please be correct and try again!</font>";
            //        ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "text", "func('Invalid data. Please be correct and try again!')", true);
            //        return;
            //    }
            //    if (double.Parse(txtReturnQty.Text) > double.Parse(txtBalanceQty.Text))
            //    {
            //        // lblMessage.Text = "<font color='red'>Sorry! You cannot return more then you have. Please be correct and try again!</font>";
            //        ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "text", "func('Sorry! You cannot return more then you have. Please be correct and try again!')", true);
            //        return;
            //    }

            //    Hashtable ht = new Hashtable();
            //    ht.Add("ReturnType", "SupplierReturn"); //SupplierReturn
            //    ht.Add("BarCode", BarCode);
            //    ht.Add("ChallanNo", txtChalanNo.Text);
            //    ht.Add("ReturnChallanNo", txtChalanNoReturn.Text);
            //    ht.Add("ReturnQty", txtReturnQty.Text);
            //    ht.Add("ReturnDate", txtDate.Text);
            //    ht.Add("DPT_CODE", "NA");
            //    ht.Add("EID", "NA");
            //    ht.Add("SupplierCode", ddlSupplierTo.SelectedValue.ToString());
            //    ht.Add("CenterCode", "NA");
            //    ht.Add("StoreCode", ddlStore.SelectedValue.ToString());
            //    ht.Add("OCode", ((SessionUser)Session["SessionUser"]).OCode.ToString());
            //    ht.Add("CompanyCode", CentralCode.ToString());
            //    ht.Add("BalanceQuanity", txtRemainingQty.Text);
            //    ht.Add("EditUser", ((SessionUser)Session["SessionUser"]).UserId);

            //    //ht.Add("OCode", "8989");
            //    DataTable dt = ic.ReturnProductStoreWise(ht);
            //    // lblMessage.Text = "<font color='green'>Product has been returned successfully!</font>";
            //    ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "text", "func('Item Returned Successfully')", true);
            //    grdTransfer.DataSource = dt;
            //    grdTransfer.DataBind();
            //    //txtBalQty.Text = txtRemainQty.Text;
            //    ClearForm();
            //}
            //catch (Exception ex)
            //{
            //    ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "text", "func('" + ex.Message + "')", true);
            //}
        }