protected void Page_Load(object sender, EventArgs e)
    {
        if (string.IsNullOrEmpty((string)Session["CompanyId"]) && string.IsNullOrEmpty((string)Session["Username"]))
        {
            Response.Redirect("~/Default.aspx", false);
        }
        else
        {
            if (!IsPostBack)
            {
                ViewState["mlCode"]          = mlCode;
                ViewState["Index"]           = Index;
                ViewState["ItemUpdateIndex"] = ItemUpdateIndex;
                ViewState["dt2"]             = dt2;
                ((DataTable)ViewState["dt2"]).Rows.Clear();
                str = "";
                ViewState["str"] = str;

                DataTable dtRights = CommonClasses.Execute("select UR_RIGHTS from USER_RIGHT where UR_IS_DELETE=0 AND UR_UM_CODE='" + Convert.ToInt32(Session["UserCode"]) + "' and UR_SM_CODE='132'");
                right = dtRights.Rows.Count == 0 ? "00000000" : dtRights.Rows[0][0].ToString();
                try
                {
                    if (Request.QueryString[0].Equals("VIEW"))
                    {
                        BL_RecieptEntry     = new RecieptEntry_BL();
                        ViewState["mlCode"] = Convert.ToInt32(Request.QueryString[1].ToString());

                        ViewRec("VIEW");
                        CtlDisable();
                    }
                    else if (Request.QueryString[0].Equals("MODIFY"))
                    {
                        BL_RecieptEntry     = new RecieptEntry_BL();
                        ViewState["mlCode"] = Convert.ToInt32(Request.QueryString[1].ToString());
                        ViewRec("MOD");
                    }
                    else if (Request.QueryString[0].Equals("INSERT"))
                    {
                        //txtRCPDate.Text = System.DateTime.Now.ToString("dd MMM yyyy");
                        //txtChequeDate.Text = System.DateTime.Now.ToString("dd MMM yyyy");
                        txtRCPDate.Text    = CommonClasses.GetCurrentTime().ToString("dd MMM yyyy");
                        txtChequeDate.Text = CommonClasses.GetCurrentTime().ToString("dd MMM yyyy");

                        BlankGrid();
                        LoadCombos();
                        //LoadCurr();
                        dtFilter.Rows.Clear();

                        //txtRCPDate.Attributes.Add("readonly", "readonly");
                        //txtChequeDate.Attributes.Add("readonly", "readonly");
                    }
                    ddlCustomer.Focus();
                }
                catch (Exception ex)
                {
                    CommonClasses.SendError("Reciept Entry", "PageLoad", ex.Message);
                }
            }
        }
    }
    bool SaveRec()
    {
        bool result = false;

        try
        {
            #region INSERT
            if (Request.QueryString[0].Equals("INSERT"))
            {
                BL_RecieptEntry = new RecieptEntry_BL();
                txtRCPno.Text   = Numbering();
                if (Setvalues())
                {
                    if (BL_RecieptEntry.Save(dgInwardMaster))
                    {
                        string Code = CommonClasses.GetMaxId("Select Max(RCP_CODE) from RECIEPT_MASTER");
                        CommonClasses.WriteLog("Reciept Entry ", "Insert", "Reciept Entry", Code, Convert.ToInt32(Code), Convert.ToInt32(Session["CompanyId"]), Convert.ToInt32(Session["CompanyCode"]), (Session["Username"].ToString()), Convert.ToInt32(Session["UserCode"]));
                        result = true;
                        Response.Redirect(redirect, false);
                    }
                    else
                    {
                        if (BL_RecieptEntry.Msg != "")
                        {
                            ShowMessage("#Avisos", BL_RecieptEntry.Msg.ToString(), CommonClasses.MSG_Warning);
                            ScriptManager.RegisterStartupScript(this, GetType(), "displayalertmessage", "Showalert1();", true);
                            BL_RecieptEntry.Msg = "";
                        }
                        ddlCustomer.Focus();
                    }
                }
            }
            #endregion

            #region MODIFY
            else if (Request.QueryString[0].Equals("MODIFY"))
            {
                BL_RecieptEntry = new RecieptEntry_BL(Convert.ToInt32(ViewState["mlCode"].ToString()));

                if (Setvalues())
                {
                    if (BL_RecieptEntry.Update(dgInwardMaster))
                    {
                        CommonClasses.RemoveModifyLock("RECIEPT_MASTER", "MODIFY", "RCP_CODE", Convert.ToInt32(ViewState["mlCode"].ToString()));
                        // CommonClasses.WriteLog("Reciept Entry ", "Update", "Reciept Entry",  Convert.ToInt32(ViewState["mlCode"].ToString()) , Convert.ToInt32(mlCode), Convert.ToInt32(Session["CompanyId"]), (Session["Username"].ToString()), Convert.ToInt32(Session["UserCode"]));
                        CommonClasses.WriteLog("Reciept Entry ", "Update", "Reciept Entry", Convert.ToInt32(ViewState["mlCode"].ToString()).ToString(), Convert.ToInt32(ViewState["mlCode"].ToString()), Convert.ToInt32(Session["CompanyId"]), Convert.ToInt32(Session["CompanyCode"]), (Session["Username"].ToString()), Convert.ToInt32(Session["UserCode"]));
                        result = true;
                        Response.Redirect(redirect, false);
                    }
                    else
                    {
                        if (BL_RecieptEntry.Msg != "")
                        {
                            ShowMessage("#Avisos", BL_RecieptEntry.Msg.ToString(), CommonClasses.MSG_Warning);
                            ScriptManager.RegisterStartupScript(this, GetType(), "displayalertmessage", "Showalert1();", true);
                            BL_RecieptEntry.Msg = "";
                        }
                        ddlCustomer.Focus();
                    }
                }
            }
            #endregion
        }
        catch (Exception ex)
        {
            CommonClasses.SendError("Reciept Entry", "SaveRec", ex.Message);
        }
        return(result);
    }