private void Search()
    {
        SqlInt32    BranchID      = SqlInt32.Null;
        SqlString   CustomerName  = SqlString.Null;
        SqlInt32    DistributorID = SqlInt32.Null;
        SqlInt32    ProductID     = SqlInt32.Null;
        SqlDateTime FromDate      = SqlDateTime.Null;
        SqlDateTime ToDate        = SqlDateTime.Null;


        if (ddlBranchID.SelectedIndex > 0)
        {
            BranchID = Convert.ToInt32(ddlBranchID.SelectedValue);
        }

        if (ddlCustomerID.Text.Trim() != "")
        {
            CustomerName = Convert.ToString(ddlCustomerID.Text.Trim());
        }

        if (ddlDistributorID.SelectedIndex > 0)
        {
            DistributorID = Convert.ToInt32(ddlDistributorID.SelectedValue);
        }

        if (ddlProductID.SelectedIndex > 0)
        {
            ProductID = Convert.ToInt32(ddlProductID.SelectedValue);
        }

        if (txtfromdate.Text.Trim() != "")
        {
            FromDate = DateTime.Parse(txtfromdate.Text.Trim());
        }

        if (txttodate.Text.Trim() != "")
        {
            ToDate = DateTime.Parse(txttodate.Text.Trim());
        }

        OccasionallyOrderBAL balOccasionallyOrder = new OccasionallyOrderBAL();
        DataTable            dtOccasionallyOrder  = balOccasionallyOrder.OccasionallyOrderSelectSearch(BranchID, CustomerName, DistributorID, ProductID, FromDate, ToDate);

        if (dtOccasionallyOrder != null && dtOccasionallyOrder.Rows.Count > 0)
        {
            gvOccasionallyOrder.DataSource = dtOccasionallyOrder;
            gvOccasionallyOrder.DataBind();
        }
        else
        {
            gvOccasionallyOrder.DataSource = null;
            gvOccasionallyOrder.DataBind();
        }
    }
 private void FillOccasionallyOrderGridView()
 {
     if (Session["UserID"] != null)
     {
         OccasionallyOrderBAL balOccasionallyOrder = new OccasionallyOrderBAL();
         DataTable            dtOccasionallyOrder  = balOccasionallyOrder.SelectAll();
         if (dtOccasionallyOrder != null && dtOccasionallyOrder.Rows.Count > 0)
         {
             gvOccasionallyOrder.DataSource = dtOccasionallyOrder;
             gvOccasionallyOrder.DataBind();
         }
     }
 }
 protected void gvOccasionallyOrder_RowCommand(object sender, GridViewCommandEventArgs e)
 {
     try
     {
         if (e.CommandName == "DeleteRecord" && e.CommandArgument != null)
         {
             OccasionallyOrderBAL balOccasionallyOrder = new OccasionallyOrderBAL();
             if (balOccasionallyOrder.Delete(Convert.ToInt32(e.CommandArgument)))
             {
                 FillOccasionallyOrderGridView();
             }
             else
             {
                 lblMessage.Text = balOccasionallyOrder.Message;
             }
         }
     }
     catch (Exception ex)
     {
         lblMessage.Text = ex.Message.ToString();
     }
 }
    private void LoadControls(SqlInt32 OccasionallyOrderID)
    {
        OccasionallyOrderENT entOccasionallyOrder = new OccasionallyOrderENT();
        OccasionallyOrderBAL balOccasionallyOrder = new OccasionallyOrderBAL();

        entOccasionallyOrder = balOccasionallyOrder.SelectByPK(OccasionallyOrderID);

        if (!entOccasionallyOrder.CustomerName.IsNull)
        {
            txtCustomerName.Text = entOccasionallyOrder.CustomerName.Value.ToString();
        }

        if (!entOccasionallyOrder.MobileNo.IsNull)
        {
            txtMobileNo.Text = entOccasionallyOrder.MobileNo.Value.ToString();
        }

        if (!entOccasionallyOrder.Address.IsNull)
        {
            txtCustomerAddress.Text = entOccasionallyOrder.Address.Value.ToString();
        }

        if (!entOccasionallyOrder.BranchID.IsNull)
        {
            ddlBranchID.SelectedValue = entOccasionallyOrder.BranchID.Value.ToString();
        }

        if (!entOccasionallyOrder.DistributorID.IsNull)
        {
            ddlDistributorID.SelectedValue = entOccasionallyOrder.DistributorID.Value.ToString();
        }

        if (!entOccasionallyOrder.ProductID.IsNull)
        {
            ddlProductID.SelectedValue = entOccasionallyOrder.ProductID.Value.ToString();
        }

        if (!entOccasionallyOrder.Quantity.IsNull)
        {
            txtQuantity.Text = entOccasionallyOrder.Quantity.Value.ToString();
        }

        if (!entOccasionallyOrder.TotalAmount.IsNull)
        {
            txtTotalAmount.Text = entOccasionallyOrder.TotalAmount.Value.ToString();
        }

        if (!entOccasionallyOrder.OrderDate.IsNull)
        {
            txtOrderDate.Text = entOccasionallyOrder.OrderDate.Value.ToString("yyyy-MM-dd");
        }

        if (!entOccasionallyOrder.BottleIn.IsNull)
        {
            txtBottleIn.Text = entOccasionallyOrder.BottleIn.Value.ToString();
        }

        if (!entOccasionallyOrder.Status.IsNull)
        {
            ckbStatus.Checked = entOccasionallyOrder.Status.Value;
        }
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        try
        {
            #region Server Side Validation

            String strError = String.Empty;

            if (txtCustomerName.Text.Trim() == String.Empty)
            {
                strError += "- Enter Customer Name<br />";
            }

            if (txtMobileNo.Text.Trim() == String.Empty)
            {
                strError += "- Enter Mobile No<br />";
            }

            if (txtCustomerAddress.Text.Trim() == String.Empty)
            {
                strError += "- Enter Customer Address<br />";
            }

            if (ddlBranchID.SelectedIndex == 0)
            {
                strError += "- Select Branch<br />";
            }

            if (ddlDistributorID.SelectedIndex == 0)
            {
                strError += "- Select Distributor<br />";
            }

            if (ddlProductID.SelectedIndex == 0)
            {
                strError += "- Select Product<br />";
            }

            if (txtQuantity.Text.Trim() == String.Empty)
            {
                strError += "- Enter Quantity<br />";
            }

            if (txtTotalAmount.Text.Trim() == String.Empty)
            {
                strError += "- Enter Total Amount<br />";
            }

            if (txtOrderDate.Text.Trim() == String.Empty)
            {
                strError += "- Enter Order Date<br />";
            }

            if (txtBottleIn.Text.Trim() == String.Empty)
            {
                strError += "- Enter In Bottle<br />";
            }

            #endregion Server Side Validation


            OccasionallyOrderENT entOccasionallyOrder = new OccasionallyOrderENT();
            OccasionallyOrderBAL balOccasionallyOrder = new OccasionallyOrderBAL();

            #region Gather Data

            if (txtCustomerName.Text.Trim() != String.Empty)
            {
                entOccasionallyOrder.CustomerName = txtCustomerName.Text.Trim();
            }

            if (txtMobileNo.Text.Trim() != String.Empty)
            {
                entOccasionallyOrder.MobileNo = txtMobileNo.Text.Trim();
            }

            if (txtCustomerAddress.Text.Trim() != String.Empty)
            {
                entOccasionallyOrder.Address = txtCustomerAddress.Text.Trim();
            }

            if (ddlBranchID.SelectedIndex > 0)
            {
                entOccasionallyOrder.BranchID = Convert.ToInt32(ddlBranchID.SelectedValue);
            }

            if (ddlDistributorID.SelectedIndex > 0)
            {
                entOccasionallyOrder.DistributorID = Convert.ToInt32(ddlDistributorID.SelectedValue);
            }

            if (ddlProductID.SelectedIndex > 0)
            {
                entOccasionallyOrder.ProductID = Convert.ToInt32(ddlProductID.SelectedValue);
            }

            if (txtQuantity.Text.Trim() != String.Empty)
            {
                entOccasionallyOrder.Quantity = Convert.ToInt32(txtQuantity.Text.Trim());
            }

            if (txtTotalAmount.Text.Trim() != String.Empty)
            {
                entOccasionallyOrder.TotalAmount = Convert.ToDecimal(txtTotalAmount.Text.Trim());
            }

            if (txtOrderDate.Text.Trim() != String.Empty)
            {
                entOccasionallyOrder.OrderDate = Convert.ToDateTime(txtOrderDate.Text.Trim());
            }

            if (txtBottleIn.Text.Trim() != String.Empty)
            {
                entOccasionallyOrder.BottleIn = Convert.ToInt32(txtBottleIn.Text.Trim());
            }

            entOccasionallyOrder.Status = Convert.ToBoolean(ckbStatus.Checked);

            entOccasionallyOrder.UserID = Convert.ToInt32(Session["UserID"]);

            if (Request.QueryString["OccasionallyOrderID"] == null)
            {
                balOccasionallyOrder.Insert(entOccasionallyOrder);
                lblMessage.Text = "Data Inserted Successfully";
                ClearControls();
            }
            else
            {
                entOccasionallyOrder.OccasionallyOrderID = Convert.ToInt32(Request.QueryString["OccasionallyOrderID"]);
                balOccasionallyOrder.Update(entOccasionallyOrder);
                Response.Redirect("~/AdminPanel/OccasionallyOrder/OccasionallyOrderList.aspx");
            }

            #endregion Gather Data
        }
        catch (Exception ex)
        {
            lblErrorMessage.Text = ex.Message.ToString();
        }
    }