private List <QAQCRequisitionDetailProvider> requisitionDetailEntityList()
        {
            List <QAQCRequisitionDetailProvider> requisitionDetailProviderList = new List <QAQCRequisitionDetailProvider>();

            foreach (GridViewRow row in gvPurchaseForLSE.Rows)
            {
                QAQCRequisitionDetailProvider obj = new QAQCRequisitionDetailProvider();

                HiddenField hfRowProductID      = (HiddenField)row.FindControl("hfProductID");
                TextBox     txtRequiredQuantity = (TextBox)row.FindControl("txtRequiredQuantity");
                TextBox     txtRemarks          = (TextBox)row.FindControl("txtRemarks");
                TextBox     txtUsedForProduct   = (TextBox)row.FindControl("txtUsedForProduct");

                ImageButton btnAddOrDelete = (ImageButton)row.FindControl("btnDeleteSelectedRowLSE");

                Label lblProductName = (Label)row.FindControl("lblProduct");

                TextBox txtSentQuantity = (TextBox)row.FindControl("txtSentQuantity");

                obj.ProductID        = hfRowProductID.Value.Toint();
                obj.RequiredQuantity = txtRequiredQuantity.Text.ToDecimal();
                obj.SentQuantity     = txtSentQuantity.Text.ToDecimal();
                obj.Remarks          = txtRemarks.Text.ToString();
                obj.UsedForProduct   = txtUsedForProduct.Text.ToString();
                if (obj.RequiredQuantity <= 0)
                {
                    throw new Exception("Please input required quantity");
                }

                requisitionDetailProviderList.Add(obj);
            }
            return(requisitionDetailProviderList);
        }
        public bool Delete(QAQCRequisitionDetailProvider provider)
        {
            bool IsDelete = false;

            try
            {
                SqlCommand command = new SqlCommand();
                this.ConnectionOpen();
                command.Connection = Connection;
                this.BeginTransaction(true);
                command.Transaction = this.Transaction;
                command.CommandType = CommandType.StoredProcedure;
                command.CommandText = StoredProcedureNames.RequisitionDetailSet;
                command.Parameters.Add("@ID", SqlDbType.Int).Value     = provider.ID;
                command.Parameters.Add("@Option", SqlDbType.Int).Value = DBConstants.DataModificationOption.Delete;
                command.ExecuteNonQuery();
                this.CommitTransaction();
                this.ConnectionClosed();
                IsDelete = true;
            }
            catch (Exception exp)
            {
                this.RollbackTransaction();
                throw new Exception(exp.Message);
            }
            finally
            {
                this.ConnectionClosed();
            }
            return(IsDelete);
        }
        public bool Update(QAQCRequisitionDetailProvider provider)
        {
            bool IsUpdate = false;

            try
            {
                SqlCommand command = null;
                command = ProcedureFunction(provider);
                command.Parameters.Add("@ID", SqlDbType.Int).Value           = provider.ID;
                command.Parameters.Add("@UpdateUserID", SqlDbType.Int).Value = provider.UpdateUserID;
                command.Parameters.Add("@Option", SqlDbType.Int).Value       = DBConstants.DataModificationOption.Update;
                command.ExecuteNonQuery();
                this.CommitTransaction();
                this.ConnectionClosed();
                IsUpdate = true;
            }
            catch (Exception exp)
            {
                this.RollbackTransaction();
                throw new Exception(exp.Message);
            }
            finally
            {
                this.ConnectionClosed();
            }
            return(IsUpdate);
        }
        private SqlCommand ProcedureFunction(QAQCRequisitionDetailProvider provider)
        {
            SqlCommand command = new SqlCommand();

            this.ConnectionOpen();
            command.Connection = Connection;
            this.BeginTransaction(true);
            command.Transaction = this.Transaction;
            command.CommandType = CommandType.StoredProcedure;
            command.CommandText = StoredProcedureNames.RequisitionDetailSet;
            command.Parameters.Add("@ProductID", SqlDbType.Int).Value        = provider.ProductID;
            command.Parameters.Add("@Rate", SqlDbType.VarChar).Value         = provider.RawProductName;
            command.Parameters.Add("@RateInDollar", SqlDbType.Decimal).Value = provider.RequiredQuantity;
            command.Parameters.Add("@CurrencyRate", SqlDbType.Decimal).Value = provider.SentQuantity;
            command.Parameters.Add("@CurrencyRate", SqlDbType.VarChar).Value = provider.Remarks;
            return(command);
        }
        protected void btnDeleteSelectedRowLSE_Click(object sender, EventArgs e)
        {
            ImageButton btnDelete      = sender as ImageButton;
            GridViewRow selectedRow    = (GridViewRow)btnDelete.NamingContainer;
            HiddenField hfDeleteProdID = (HiddenField)selectedRow.FindControl("hfProductID");
            List <QAQCRequisitionDetailProvider> purchaseLedgerDetailsProviderList = new List <QAQCRequisitionDetailProvider>();

            foreach (GridViewRow row in gvPurchaseForLSE.Rows)
            {
                QAQCRequisitionDetailProvider obj = new QAQCRequisitionDetailProvider();

                HiddenField hfRowProductID      = (HiddenField)row.FindControl("hfProductID");
                Label       lblProductName      = (Label)row.FindControl("lblProduct");
                TextBox     txtRequiredQuantity = (TextBox)row.FindControl("txtRequiredQuantity");
                Label       lblTotalAmount      = (Label)row.FindControl("lblTotalAmount");
                ImageButton btnAddOrDelete      = (ImageButton)row.FindControl("btnDeleteSelectedRowLSE");

                TextBox txtSentQuantity  = (TextBox)row.FindControl("txtSentQuantity");
                Label   lblStockLocation = (Label)row.FindControl("lblStockLocation");
                TextBox txtUnit          = (TextBox)row.FindControl("txtUnit");
                TextBox txtPresentStock  = (TextBox)row.FindControl("txtPresentStock");
                TextBox txtRemarks       = (TextBox)row.FindControl("txtRemarks");

                if (hfRowProductID.Value != hfDeleteProdID.Value)
                {
                    obj.ProductID           = hfRowProductID.Value.Toint();
                    obj.RawProductName      = lblProductName.Text.ToString();
                    obj.RequiredQuantity    = txtRequiredQuantity.Text.ToDecimal();
                    obj.MeasurementUnitName = txtUnit.Text;
                    obj.SentQuantity        = txtSentQuantity.Text.ToDecimal();
                    obj.PresentStock        = txtPresentStock.Text.ToDecimal();
                    obj.StockLocation       = lblStockLocation.Text;
                    obj.Remarks             = txtRemarks.Text.ToString();

                    purchaseLedgerDetailsProviderList.Add(obj);
                }
            }
            gvPurchaseForLSE.DataSource = purchaseLedgerDetailsProviderList;
            gvPurchaseForLSE.DataBind();

            if (gvPurchaseForLSE.Rows.Count == 0)
            {
                ddlRequisitionDivision.Enabled = true;
            }
        }
        protected void btnAdd_OnClick(object sender, EventArgs e)
        {
            this.AlertNone(lblMsg);
            ProductProvider productProvider = new ProductProvider();

            AjaxControlToolkit.ComboBox ddlProductValidation = (AjaxControlToolkit.ComboBox)UC_ProductSearch1.FindControl("ddlProduct");
            if (ddlProductValidation.SelectedValue == "")
            {
                MessageHelper.ShowAlertMessage("Select Product!");
                lblMsg.Focus();
                return;
            }
            string measurementUnit = productProvider.GetMeasurementUnit(ddlProductValidation.SelectedValue.Toint());
            List <QAQCRequisitionDetailProvider> purchaseLedgerDetailsProviderList = new List <QAQCRequisitionDetailProvider>();

            foreach (GridViewRow row in gvPurchaseForLSE.Rows)
            {
                QAQCRequisitionDetailProvider obj = new QAQCRequisitionDetailProvider();

                HiddenField hfRowProductID      = (HiddenField)row.FindControl("hfProductID");
                Label       lblProductName      = (Label)row.FindControl("lblProduct");
                TextBox     txtRequiredQuantity = (TextBox)row.FindControl("txtRequiredQuantity");
                TextBox     txtUnit             = (TextBox)row.FindControl("txtUnit");

                TextBox     txtSentQuantity  = (TextBox)row.FindControl("txtSentQuantity");
                TextBox     txtPresentStock  = (TextBox)row.FindControl("txtPresentStock");
                Label       lblStockLocation = (Label)row.FindControl("lblStockLocation");
                TextBox     txtRemarks       = (TextBox)row.FindControl("txtRemarks");
                Label       lblTotalAmount   = (Label)row.FindControl("lblTotalAmount");
                ImageButton btnAddOrDelete   = (ImageButton)row.FindControl("btnDeleteSelectedRowLSE");

                if (hfRowProductID.Value == ddlProductValidation.SelectedValue)
                {
                    MessageHelper.ShowAlertMessage("This product already added!");
                    return;
                }
                if (txtRequiredQuantity.Text.ToDecimal() <= 0)
                {
                    MessageHelper.ShowAlertMessage("Enter Quantity!");
                    return;
                }
                obj.ProductID           = hfRowProductID.Value.Toint();
                obj.RawProductName      = lblProductName.Text.ToString();
                obj.PresentStock        = txtPresentStock.Text.ToDecimal();
                obj.StockLocation       = lblStockLocation.Text;
                obj.MeasurementUnitName = txtUnit.Text.ToString();
                obj.RequiredQuantity    = txtRequiredQuantity.Text.ToDecimal();
                obj.SentQuantity        = txtSentQuantity.Text.ToDecimal();
                obj.Remarks             = txtRemarks.Text.ToString();

                purchaseLedgerDetailsProviderList.Add(obj);
            }

            AjaxControlToolkit.ComboBox ddlProduct = (AjaxControlToolkit.ComboBox)UC_ProductSearch1.FindControl("ddlProduct");
            string productName = ddlProduct.SelectedItem.Text;
            int    productID   = ddlProduct.SelectedValue.Toint();

            QAQCRequisitionDetailProvider obj2 = new QAQCRequisitionDetailProvider();

            obj2.ProductID           = productID;
            obj2.RawProductName      = productName;
            obj2.MeasurementUnitName = measurementUnit;
            obj2.PresentStock        = productProvider.GetPresentStock(obj2.ProductID);
            obj2.StockLocation       = productProvider.GetStockLocation(obj2.ProductID);
            purchaseLedgerDetailsProviderList.Add(obj2);
            if (!divGridForLSE.Visible)
            {
                divGridForLSE.Visible = true;
            }
            gvPurchaseForLSE.DataSource = purchaseLedgerDetailsProviderList;
            gvPurchaseForLSE.DataBind();
        }