private void bindgrid()
 {
     try
     {
         Entities.Finance.VoucherSettings Voucher = new Entities.Finance.VoucherSettings();
         DataSet ds = new DataSet();
         ds = Voucher.GetVoucherSetings(Convert.ToInt32(CPublic.GetCompanyID()), Convert.ToInt32(ddlVoucherType.SelectedValue), Convert.ToInt32(ddlgroupBy.SelectedValue));
         gvAccounts.DataSource = ds;
         gvAccounts.DataBind();
     }
     catch (Exception)
     {
     }
 }
        protected void btnSaveConfirmed_Click(object sender, EventArgs e)
        {
            try
            {
                Entities.Finance.VoucherSettings Voucher = new Entities.Finance.VoucherSettings();
                string ByGroup = "", TypeId = "", HeadID = "", AllowCr = "", AllowDr = "", CrPartial = "", DrPartial = "";
                string chkSelectDrIndex = "", chkSelectCrIndex = "", partialDr = "", partialCr = "";
                TypeId  = ddlVoucherType.SelectedValue;
                ByGroup = ddlgroupBy.SelectedValue;
                foreach (GridViewRow dgi in this.gvAccounts.Rows)
                {
                    if (HeadID == "")
                    {
                        HeadID = Convert.ToString(((Label)dgi.FindControl("lblId")).Text);
                    }
                    else
                    {
                        HeadID = HeadID + "|" + Convert.ToString(((Label)dgi.FindControl("lblId")).Text);
                    }

                    if (((HtmlInputCheckBox)dgi.FindControl("chkSelectDr")).Checked)
                    {
                        chkSelectDrIndex = "1";
                    }
                    //chkSelectDrIndex = chkSelectDrIndex + "," + ((HtmlInputCheckBox)dgi.FindControl("chkSelectDr")).Value;
                    else
                    {
                        chkSelectDrIndex = "0";
                    }

                    if (((HtmlInputCheckBox)dgi.FindControl("chkSelectCr")).Checked)
                    {
                        chkSelectCrIndex = "1";
                    }
                    //chkSelectCrIndex = chkSelectCrIndex + "," + ((HtmlInputCheckBox)dgi.FindControl("chkSelectCr")).Value;
                    else
                    {
                        chkSelectCrIndex = "0";
                    }

                    if (AllowCr == "")
                    {
                        AllowCr = chkSelectCrIndex;
                    }
                    else
                    {
                        AllowCr = AllowCr + "|" + chkSelectCrIndex;
                    }

                    if (AllowDr == "")
                    {
                        AllowDr = chkSelectDrIndex;
                    }
                    else
                    {
                        AllowDr = AllowDr + "|" + chkSelectDrIndex;
                    }

                    if (dgi.Cells[2].BackColor == System.Drawing.Color.DimGray && ((HtmlInputCheckBox)dgi.FindControl("chkSelectDr")).Checked == true)
                    {
                        partialDr = "1";
                    }
                    else
                    {
                        partialDr = "0";
                    }

                    if (dgi.Cells[3].BackColor == System.Drawing.Color.DimGray && ((HtmlInputCheckBox)dgi.FindControl("chkSelectCr")).Checked == true)
                    {
                        partialCr = "1";
                    }
                    else
                    {
                        partialCr = "0";
                    }

                    if (DrPartial == "")
                    {
                        DrPartial = partialDr;
                    }
                    else
                    {
                        DrPartial = DrPartial + "|" + partialDr;
                    }

                    if (CrPartial == "")
                    {
                        CrPartial = partialCr;
                    }
                    else
                    {
                        CrPartial = CrPartial + "|" + partialCr;
                    }
                }
                OutputMessage Result = null;
                Voucher.CreatedBy = CPublic.GetuserID();
                if (Voucher.ID == 0)
                {
                    Result = Voucher.Save(ByGroup, TypeId, HeadID, AllowDr, AllowCr, CrPartial, DrPartial);
                    if (Result.Success)
                    {
                        Reset();
                        ClientScript.RegisterStartupScript(this.GetType(), "message", "successAlert('" + Result.Message + "');", true);
                    }
                    else
                    {
                        ClientScript.RegisterStartupScript(this.GetType(), "message", "errorAlert('" + Result.Message + "')", true);
                    }
                }
                else
                {
                    Response.Write("<script>alert('')</script>");
                }
            }
            catch (Exception)
            {
            }
        }