protected void btnsubmit_Click(object sender, EventArgs e)
    {
        ViewState["trans1"] = string.Empty;
        ViewState["led1"] = string.Empty;
        string SQL = "SELECT PR.SRNO,P.RELATIONSHIPID,ASSOSIATEDFEILD,P.BRANCHNAME,AG.GROUPNAME" +
                     " FROM personaltable P  INNER JOIN personalrelation PR ON P.RELATIONSHIPID = PR.RELATIONSHIPID " +
                     " INNER JOIN ACCOUNTGROUP AG ON AG.GROUPID = PR.GROUPID WHERE PR.RELATIONSHIPID =" + hdnfirstledger.Value;
        Handler hdns = new Handler();
        DataTable dts = hdns.GetTable(SQL);
        if (dts.Rows.Count > 0)
        {
            ViewState["trans1"] = dts.Rows[0]["RELATIONSHIPID"].ToString();
            ViewState["led1"] = General.Parse<int>(dts.Rows[0]["SRNO"].ToString());
        }
        ViewState["trans2"] = string.Empty;
        ViewState["led2"] = string.Empty;
        string SQL1 = "SELECT PR.SRNO,P.RELATIONSHIPID,ASSOSIATEDFEILD,P.BRANCHNAME,AG.GROUPNAME" +
                     " FROM personaltable P  INNER JOIN personalrelation PR ON P.RELATIONSHIPID = PR.RELATIONSHIPID " +
                     " INNER JOIN ACCOUNTGROUP AG ON AG.GROUPID = PR.GROUPID WHERE PR.RELATIONSHIPID =" + hdnsecondledger.Value;
        Handler hdns1 = new Handler();
        DataTable dts1 = hdns1.GetTable(SQL1);
        if (dts.Rows.Count > 0)
        {
            ViewState["trans2"] = dts1.Rows[0]["RELATIONSHIPID"].ToString();
            ViewState["led2"] = General.Parse<int>(dts1.Rows[0]["SRNO"].ToString());
        }

        transactiontable trans = new transactiontable(HttpContext.Current.Server.MapPath("~/XML/database.xml"));
        trans.transactiontable_SRNO = -1;
        trans.transactiontable_LEDGER1 = General.Parse<int>(ViewState["led1"].ToString());
        trans.transactiontable_RELATIONID1 = General.Parse<int>(ViewState["trans1"].ToString());
        trans.transactiontable_LEDGER2 = General.Parse<int>(ViewState["led2"].ToString());
        trans.transactiontable_RELATIONID2 = General.Parse<int>(ViewState["trans2"].ToString());
        if (ddlType.SelectedItem.Text == "credit")
        {
            trans.transactiontable_LTRNTYPE1 = "CR";
            trans.transactiontable_LTRNTYPE2 = "DR";
        }
        else
        {
            trans.transactiontable_LTRNTYPE1 = "DR";
            trans.transactiontable_LTRNTYPE2 = "CR";
        }
        trans.transactiontable_AMOUNT = General.Parse<double>(txtamount.Text);
        trans.transactiontable_NARRATION = txtnarration.Text;
        trans.transactiontable_TRANSDATE = txtdate.Text;
        trans.transactiontable_TRANSACTIONTYPE = General.Parse<int>(ddlType.SelectedValue);
        trans.transactiontable_VOUCHERTYPE = ddlvouchertype.SelectedItem.Text;
        trans.transactiontable_BRANCHID = General.Parse<int>(Session["branchid"].ToString()); 
        trans.transactiontable_STATUS = 0;

        if (trans.Insert(true, "transactiontable"))
        {
            string sqltransaction = "SELECT MAX(TT.SRNO) AS SRNO FROM transactiontable TT WHERE LEDGER1=" + General.Parse<int>(ViewState["led1"].ToString()) + " AND TT.LEDGER2=" + General.Parse<int>(ViewState["led2"].ToString()) + " AND STATUS=0";
            Handler hdntransaction = new Handler();
            DataTable dttransaction = hdntransaction.GetTable(sqltransaction);
            for (int i = 0; i < 2; i++)
            {
                TransactionDetailsC objtransactiondetails = new TransactionDetailsC(HttpContext.Current.Server.MapPath("~/XML/database.xml"));
                if (i == 0)
                {
                    objtransactiondetails.transactiondetails_LTRNTYPE = trans.transactiontable_LTRNTYPE1.ToString();
                    objtransactiondetails.transactiondetails_LEDGERID = General.Parse<int>(ViewState["led1"].ToString());
                    objtransactiondetails.transactiondetails_RELATIONID = General.Parse<int>(ViewState["trans1"].ToString());
                }
                else
                {
                    objtransactiondetails.transactiondetails_LTRNTYPE = trans.transactiontable_LTRNTYPE2.ToString();
                    objtransactiondetails.transactiondetails_LEDGERID = General.Parse<int>(ViewState["led2"].ToString());
                    objtransactiondetails.transactiondetails_RELATIONID = General.Parse<int>(ViewState["trans2"].ToString());
                }

                objtransactiondetails.transactiondetails_SRNO = -1;
                objtransactiondetails.transactiondetails_STATUS = 0;

                objtransactiondetails.transactiondetails_TRANSDATE = DateTime.Today.ToString("dd/MM/YYYY");
                objtransactiondetails.transactiondetails_NARRATION = txtnarration.Text;
                objtransactiondetails.transactiondetails_VOUCHERTYPE = ddlvouchertype.SelectedItem.Text;
                objtransactiondetails.transactiondetails_BRANCHID = General.Parse<int>(Session["branchid"].ToString()); //1;
                objtransactiondetails.transactiondetails_AMOUNT = General.Parse<double>(txtamount.Text); //General.Parse<double>(txtamt.Text.Trim().ToString());
                objtransactiondetails.transactiondetails_ASSOCIATELEDGER = General.Parse<int>(dttransaction.Rows[0]["SRNO"].ToString());
                if (objtransactiondetails.Insert(true, "transactiondetails"))
                {
                }
            }
            //objtransactiondetails.
        }
    }
    protected void btnsubmit_Click(object sender, EventArgs e)
    {
        int check = 0;
        personaltable objpersonal = new personaltable(HttpContext.Current.Server.MapPath("~/XML/database.xml"));
        objpersonal.personaltable_RELATIONSHIPID = -1;
        objpersonal.personaltable_FIRSTNAME = txtledgername.Text.Trim().ToString();
        objpersonal.personaltable_BRANCHID = General.Parse<int>(Session["branchid"].ToString());
        objpersonal.personaltable_BRANCHNAME = Session["branchname"].ToString();
        if (objpersonal.Insert(true, "personaltable"))
        {
            string sql = "SELECT MAX(PR.RELATIONSHIPID) AS RELATIONSHIPID FROM personaltable PR WHERE PR.BRANCHID=1 AND PR.FIRSTNAME='" + txtledgername.Text.Trim().ToString() + "'";
            Handler hdn = new Handler();
            DataTable dt = hdn.GetTable(sql);
            personalrelation objpersonalrelation = new personalrelation(HttpContext.Current.Server.MapPath("~/XML/database.xml"));
            objpersonalrelation.personalrelation_SRNO = -1;
            objpersonalrelation.personalrelation_RELATIONSHIPID = General.Parse<int>(dt.Rows[0][0].ToString());
            objpersonalrelation.personalrelation_ASSOSIATEDFEILD = txtfeild.Text.Trim().ToString();
            objpersonalrelation.personalrelation_ASSOSIATEDBRANCH = General.Parse<int>(Session["branchid"].ToString());
            objpersonalrelation.personalrelation_GROUPID = General.Parse<int>(ddlsubgroup.SelectedValue.ToString());
            objpersonalrelation.personalrelation_STATUS = 0;
            check = 1;
            if (objpersonalrelation.Insert(true, "personalrelation"))
            {
                string sqlperrelation = "SELECT MAX(PR.SRNO) AS SRNO FROM personalrelation PR WHERE PR.STATUS=0 AND PR.RELATIONSHIPID=" + dt.Rows[0][0].ToString() + " AND PR.ASSOSIATEDBRANCH=1";
                Handler hdn1 = new Handler();
                DataTable dt1 = hdn1.GetTable(sqlperrelation);

                Handler objopening = new Handler();
                DataTable dtopening = objopening.GetTable("SELECT SRNO,RELATIONSHIPID FROM PERSONALRELATION WHERE ASSOSIATEDBRANCH =1 and ASSOSIATEDFEILD = 'OPENING ACCOUNT'");

                transactiontable objtransaction = new transactiontable(HttpContext.Current.Server.MapPath("~/XML/database.xml"));
                objtransaction.transactiontable_SRNO = -1;
                objtransaction.transactiontable_LEDGER1 = General.Parse<int>(dt1.Rows[0]["SRNO"].ToString());
                objtransaction.transactiontable_RELATIONID1 = General.Parse<int>(dt.Rows[0]["RELATIONSHIPID"].ToString());

                objtransaction.transactiontable_LEDGER2 = General.Parse<int>(dtopening.Rows[0]["SRNO"].ToString());
                objtransaction.transactiontable_RELATIONID2 = General.Parse<int>(dtopening.Rows[0]["RELATIONSHIPID"].ToString());

                if (rdcredit.Checked)
                {
                    objtransaction.transactiontable_LTRNTYPE1 = "CR";
                    objtransaction.transactiontable_LTRNTYPE2 = "DR";
                }
                else
                {
                    objtransaction.transactiontable_LTRNTYPE1 = "DR";
                    objtransaction.transactiontable_LTRNTYPE2 = "CR";
                }
                objtransaction.transactiontable_AMOUNT = General.Parse<double>(txtamt.Text.Trim().ToString());
                objtransaction.transactiontable_BRANCHID = General.Parse<int>(Session["branchid"].ToString());
                objtransaction.transactiontable_TRANSDATE = DateTime.Today.ToString("dd/MM/YYYY");
                objtransaction.transactiontable_VOUCHERNO = "1";
                objtransaction.transactiontable_VOUCHERTYPE = "OPENING AMOUNT";
                objtransaction.transactiontable_TRANSACTIONTYPE = 7; //type for opening amount 
                objtransaction.transactiontable_NARRATION = "OPENING AMOUNT";
                objtransaction.transactiontable_STATUS = 0;
                if (objtransaction.Insert(true, "transactiontable"))
                {
                    string sqltransaction = "SELECT MAX(TT.SRNO) AS SRNO FROM transactiontable TT WHERE LEDGER1=" + dt1.Rows[0]["SRNO"].ToString() + " AND TT.LEDGER2=" + dtopening.Rows[0]["SRNO"].ToString() + " AND STATUS=0";
                    Handler hdntransaction = new Handler();
                    DataTable dttransaction = hdntransaction.GetTable(sqltransaction);
                    for(int i=0;i<2;i++)
                    {
                        TransactionDetailsC objtransactiondetails = new TransactionDetailsC(HttpContext.Current.Server.MapPath("~/XML/database.xml"));
                        if (i == 0)
                        {
                            objtransactiondetails.transactiondetails_LTRNTYPE = objtransaction.transactiontable_LTRNTYPE1.ToString();
                            objtransactiondetails.transactiondetails_LEDGERID = General.Parse<int>(dt1.Rows[0]["SRNO"].ToString());
                            objtransactiondetails.transactiondetails_RELATIONID = General.Parse<int>(dt.Rows[0]["RELATIONSHIPID"].ToString());
                        }
                        else
                        {
                            objtransactiondetails.transactiondetails_LTRNTYPE = objtransaction.transactiontable_LTRNTYPE2.ToString();
                            objtransactiondetails.transactiondetails_LEDGERID = General.Parse<int>(dtopening.Rows[0]["SRNO"].ToString());
                            objtransactiondetails.transactiondetails_RELATIONID = General.Parse<int>(dtopening.Rows[0]["RELATIONSHIPID"].ToString());
                        }
                        
                        objtransactiondetails.transactiondetails_SRNO = -1;
                        objtransactiondetails.transactiondetails_STATUS = 0;
                      
                        objtransactiondetails.transactiondetails_TRANSDATE = DateTime.Today.ToString("dd/MM/YYYY");
                        objtransactiondetails.transactiondetails_NARRATION = "OPENING AMOUNT";
                        objtransactiondetails.transactiondetails_VOUCHERTYPE = "OPENING AMOUNT";
                        objtransactiondetails.transactiondetails_BRANCHID = General.Parse<int>(Session["branchid"].ToString()); //1;
                        objtransactiondetails.transactiondetails_AMOUNT = General.Parse<double>(txtamt.Text.Trim().ToString());
                        objtransactiondetails.transactiondetails_ASSOCIATELEDGER = General.Parse<int>(dttransaction.Rows[0]["SRNO"].ToString());
                        if (objtransactiondetails.Insert(true, "transactiondetails"))
                        {
                        }
                    }
                    //objtransactiondetails.
                }
            }
        }
        if (check == 1)
        {
            Response.Redirect("ledgerdetails.aspx?id=1");
        }
        else
        {
            MessageBox("Please Enter Proper Value");
        }
    }
    public void btnsubmit_Click(object sender, EventArgs e)
    {
        string[] ids;
        transactiontable trans = new transactiontable(HttpContext.Current.Server.MapPath("~/XML/database.xml"));
        trans.transactiontable_SRNO = -1;
        string id = ddlbank.SelectedValue.Replace("$", " ");
        ids = id.Split(' ');
        trans.transactiontable_LEDGER1 = General.Parse<int>(ids[0]);
        trans.transactiontable_RELATIONID1 = General.Parse<int>(ids[1]);
        trans.transactiontable_LEDGER2 = General.Parse<int>(ViewState["led2"].ToString());
        trans.transactiontable_RELATIONID2 = General.Parse<int>(ViewState["trans2"].ToString());
        if (ddlType.SelectedItem.Text == "credit")
        {
            trans.transactiontable_LTRNTYPE1 = "CR";
            trans.transactiontable_LTRNTYPE2 = "DR";
        }
        else
        {
            trans.transactiontable_LTRNTYPE1 = "DR";
            trans.transactiontable_LTRNTYPE2 = "CR";
        }
        trans.transactiontable_AMOUNT = General.Parse<double>(txtamount.Text);
        trans.transactiontable_NARRATION = txtnarration.Text;
        trans.transactiontable_TRANSDATE = txtdate.Text;
        trans.transactiontable_TRANSACTIONTYPE = General.Parse<int>(ddlvouchertype.SelectedValue);
        trans.transactiontable_VOUCHERTYPE = ddlvouchertype.SelectedItem.Text;
        trans.transactiontable_BRANCHID = General.Parse<int>(Session["branchid"].ToString());
        trans.transactiontable_STATUS = 0;

        if (trans.Insert(true, "transactiontable"))
        {
            string sqltransaction = "SELECT MAX(TT.SRNO) AS SRNO FROM transactiontable TT WHERE LEDGER1=" + ids[0] + " AND TT.LEDGER2=" + General.Parse<int>(ViewState["led2"].ToString()) + " AND STATUS=0";
            Handler hdntransaction = new Handler();
            DataTable dttransaction = hdntransaction.GetTable(sqltransaction);
            for (int i = 0; i < 2; i++)
            {
                TransactionDetailsC objtransactiondetails = new TransactionDetailsC(HttpContext.Current.Server.MapPath("~/XML/database.xml"));
                if (i == 0)
                {
                    objtransactiondetails.transactiondetails_LTRNTYPE = trans.transactiontable_LTRNTYPE1.ToString();
                    objtransactiondetails.transactiondetails_LEDGERID = General.Parse<int>(ids[0]);
                    objtransactiondetails.transactiondetails_RELATIONID = General.Parse<int>(ids[1]);
                }
                else
                {
                    objtransactiondetails.transactiondetails_LTRNTYPE = trans.transactiontable_LTRNTYPE2.ToString();
                    objtransactiondetails.transactiondetails_LEDGERID = General.Parse<int>(ViewState["led2"].ToString());
                    objtransactiondetails.transactiondetails_RELATIONID = General.Parse<int>(ViewState["trans2"].ToString());
                }

                objtransactiondetails.transactiondetails_SRNO = -1;
                objtransactiondetails.transactiondetails_STATUS = 0;

                objtransactiondetails.transactiondetails_TRANSDATE = DateTime.Today.ToString("dd/MM/YYYY");
                objtransactiondetails.transactiondetails_NARRATION = txtnarration.Text;
                objtransactiondetails.transactiondetails_VOUCHERTYPE = ddlvouchertype.SelectedItem.Text;
                objtransactiondetails.transactiondetails_BRANCHID = General.Parse<int>(Session["branchid"].ToString()); //1;
                objtransactiondetails.transactiondetails_AMOUNT = General.Parse<double>(txtamount.Text); //General.Parse<double>(txtamt.Text.Trim().ToString());
                objtransactiondetails.transactiondetails_ASSOCIATELEDGER = General.Parse<int>(dttransaction.Rows[0]["SRNO"].ToString());
                if (objtransactiondetails.Insert(true, "transactiondetails"))
                {
                }
            }
            //objtransactiondetails.
        }

    }