using System;
using System.Collections.Generic;
using System.Linq;
using System.Collections;
using System.Web;
using System.IO;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Text;
using System.Configuration;
using MySql.Data.MySqlClient;
using MySql.Data;
using CLS_BL;
using CLS_DL;
using CLS_PL;
using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.html;
using iTextSharp.text.html.simpleparser;
using System.Web.UI.DataVisualization.Charting;
using System.Web.Services;

namespace SUNWEB
{
    public partial class JournalReport : System.Web.UI.Page
    {
        BL_SELECT ObjSel = new BL_SELECT();
        BLCompany ObjBL = new BLCompany();
        PLCOMMON ObjPL = new PLCOMMON();
        BL_USER ObjUserBL = new BL_USER(); //This Object for All User and Page Related fuctions included 
        PLCUSTOMER ObjCustPL = new PLCUSTOMER();
        Int32 K = 0;
        Int32 L = 0;
        Int32 S = 0;
        string ConStr = ConfigurationManager.ConnectionStrings["ConMysql"].ConnectionString;
        string ConStr_Rds = ConfigurationManager.ConnectionStrings["ConRDS"].ConnectionString;
        string Curr_Date = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
        string Curr_DateOnly = System.DateTime.Now.ToString("yyyy-MM-dd");
        DateTime MonthstartDt;
        DataSet ds = new DataSet();
        MYSQLDB ObjMain = new MYSQLDB();
        DataTable DT = new DataTable();
        DataTable Dt1 = new DataTable();
        DataTable Dt2 = new DataTable();
        DataTable Dt3 = new DataTable();
        DataTable DtP = new DataTable();
        DataTable DTTax = new DataTable();
        DataTable DtLicense = new DataTable();
        DataTable DtSuperAdmin = new DataTable();
        DataTable DtMultiBranch = new DataTable();
        DataTable DtNormalUser = new DataTable();
        DataTable DTProductSale = new DataTable();
        MySqlCommand Cmdv = new MySqlCommand();
        string UserId = string.Empty;
        string UserName = string.Empty;
        string PortalTypeId = string.Empty;
        string cd_Id = string.Empty;
        string Datapath = string.Empty;
        string cd_BranchAlias = string.Empty;
        string IsMultiBranch = string.Empty;
        string IsSuperAdmin = string.Empty;
        string ActiveCallvalue = string.Empty;
        string PID = string.Empty;   // License Variables ..
        string Page_Acess = string.Empty;
        string Read_Acess = string.Empty;
        string Write_Acess = string.Empty;
        string Isdowld_Acess = string.Empty;
        string Rcd_id = string.Empty;
        string RPortalid = string.Empty;
        string Useridvalue = string.Empty;
        string QueryCurr_Select = string.Empty;
        string L_MaxUserCnt = string.Empty;
        string L_RetailDashboard = string.Empty;
        string L_SummarySales = string.Empty;
        string L_ItemSales = string.Empty;
        string L_TaxAnalysis = string.Empty;
        string L_TopSale = string.Empty;
        string L_MothlySales = string.Empty;
        string L_HourlySales = string.Empty;
        string L_GroupSale = string.Empty;
        string L_Journal = string.Empty;
        string BranchFullName = string.Empty;
        string Curr_BranchFullName = string.Empty;
        string Cmb_BranchName = string.Empty;
        string Branchidval = string.Empty;
        string BraNam = "";
        string FDate = "";
        string TDate = "";
        string HQ = string.Empty;
        string Cm_id = string.Empty;
        string ISHQ = string.Empty;
        string caseSwitch = string.Empty;
        string Tax1Name = string.Empty;
        string Tax2Name = string.Empty;

        string sSelQry = "";
        string sCondQry = "";
        string sCmd = "";

        protected void Page_Load(object sender, EventArgs e)
        {
            PID = "17";                      // This is For Journal Report
            MySqlConnection Cn = new MySqlConnection(ConStr_Rds);
            Cn.Open();
            if (!IsPostBack)
            {
                txtFromDt.Text = Curr_DateOnly;
                txtToDt.Text = Curr_DateOnly;
            }
            if (Session["UserName"] == null)
            {
                Response.Redirect("Login.aspx");
            }
            MonthstartDt = new DateTime(System.DateTime.Now.Year, System.DateTime.Now.Month, 1);

            //GridView1.Columns[10].HeaderText = "SVG";
            //GridView1.Columns[11].HeaderText = "GST";

            if (((Convert.ToBoolean(Session["IsSuperAdmin"])) == true) && (Session["PortalTypeId"].ToString() == "") && ((Convert.ToBoolean(Session["IsMultiBranch"])) == true))
            {
                if (!IsPostBack)
                {
                    LoadBranchName4SuperAdmin();

                    string QueryCal = "select ActiveValue from portaldb.usermaster  where Userid=" + Session["UserId"].ToString() + " ";
                    ActiveCallvalue = ObjMain.ExecuteScalar(QueryCal);
                    if (ActiveCallvalue != " " || ActiveCallvalue != "Select Branch")
                    {
                        ActiveCall();
                    }
                }
            }
            else if (((Convert.ToBoolean(Session["IsSuperAdmin"])) == true) && (Session["PortalTypeId"].ToString() == ""))
            {
                if (!IsPostBack)
                {
                    LoadBranchName4SuperAdmin();
                }
                cd_BranchAlias = cmbBranches.SelectedItem.Text;
                BraNam = cd_BranchAlias;
                FDate = txtFromDt.Text;
                TDate = txtToDt.Text;
                LoadJournalMainQuery(cd_BranchAlias, txtFromDt.Text, txtToDt.Text);
                loadpaymenttype(cd_BranchAlias);
            }
            else if (((Convert.ToBoolean(Session["IsMultiBranch"])) == true) && (Session["PortalTypeId"].ToString() == ""))
            {
                if (!IsPostBack)
                {
                    LoadBranchName();
                    ActiveCall();
                }
            }
            else if (((Session["PortalTypeId"].ToString() != "") || (Convert.ToBoolean(Session["IsSuperAdmin"])) == false) && ((Convert.ToBoolean(Session["IsMultiBranch"])) == false))
            {
                cmbBranches.Enabled = false;
                cmbBranches.Visible = false;

                Cm_id = ObjSel.GETcmid(Session["Cd_Id"].ToString());  // Get cm_id
                HQ = ObjSel.Get_HQ(Cm_id);     // Get the HQ Value
                Curr_BranchFullName = ObjSel.GetBranchFullName(HQ, Session["Branch_HQ"].ToString());
                lblBranchAliasName.ForeColor = System.Drawing.Color.DodgerBlue;
                lblBranchAliasName.Text = "&nbsp;" + "-" + "&nbsp;" + Curr_BranchFullName + "&nbsp; ";
                cd_BranchAlias = Session["Branch_HQ"].ToString();
                Datapath = Session["DataPath"].ToString();
                PortalTypeId = Session["PortalTypeId"].ToString();
                PID = "17"; //  This is for Journal
                DT = ObjUserBL.GetPageRightsDetailsPid(Session["UserId"].ToString(), PID);
                if (DT.Rows.Count > 0)
                {
                    Page_Acess = DT.Rows[0]["Acess_status"].ToString();
                    Read_Acess = DT.Rows[0]["Read_Access"].ToString();
                    Write_Acess = DT.Rows[0]["Write_Access"].ToString();
                    Isdowld_Acess = DT.Rows[0]["IDwld_Access"].ToString();
                    Session["Page_Acess"] = Page_Acess;
                    Session["Read_Acess"] = Read_Acess;
                    Session["Write_Acess"] = Write_Acess;
                    Session["Isdowld_Acess"] = Isdowld_Acess;
                }
                if ((Session["L_Journal"].ToString() == "N") || (Session["Page_Acess"].ToString() == "N"))
                {
                    Response.Redirect("DeniedPage.aspx", false);
                }
                else
                {
                    // XSS - Attack Prevention 
                    string StartDT = Microsoft.Security.Application.Encoder.HtmlEncode(txtFromDt.Text.Trim());
                    string EndDt = Microsoft.Security.Application.Encoder.HtmlEncode(txtToDt.Text.Trim());



                    lblMsgTotalSelection.Text = "Search Result - from" + "&nbsp;&nbsp;" + StartDT + "&nbsp;&nbsp to &nbsp;&nbsp;" + EndDt;
                    idGenReport.Attributes.Add("style", "background-color: #4c4c4c; color: White;font-size:14px;");
                    if (!IsPostBack)
                    {
                        if (Session["Isdowld_Acess"].ToString() == "N")
                        {
                            // btnExcel.Enabled = false;
                            Response.Write(@"<script language='javascript'>alert('No Access To download.')</script>");
                        }
                        else
                        {
                            btnGenerate.Visible = true;
                            //btnExcel.Enabled = true;
                            if (cmbBranches.Visible == false)
                            {

                                LoadJournalMainQuery(Session["Branch_HQ"].ToString(), StartDT, EndDt);
                            }

                        }
                    }
                }
            }
            else
            {

            }
        }

        public void LoadBranchName4SuperAdmin()
        {
            DtSuperAdmin = ObjUserBL.GetBranchOnSuperAdmin8(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), Session["CM_ID"].ToString());
            if (DtSuperAdmin.Rows.Count > 0)
            {
                cmbBranches.DataSource = DtSuperAdmin;
                cmbBranches.DataTextField = "branchfullname";
                cmbBranches.DataValueField = "Branchid";
                cmbBranches.DataBind();
                cmbBranches.Items.Insert(0, "Select Branch");
            }
        }

        public void LoadBranchName()
        {
            DtNormalUser = ObjUserBL.GetBranchOnLoginValues8(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), Session["CM_ID"].ToString());
            if (DtNormalUser.Rows.Count > 0)
            {
                cmbBranches.DataSource = DtNormalUser;
                cmbBranches.DataTextField = "branchfullname";
                cmbBranches.DataValueField = "Branchid";
                cmbBranches.DataBind();
                cmbBranches.Items.Insert(0, "Select Branch");

            }
        }

        public void ActiveCall()
        {
            string QueryCal = "select ActiveValue from portaldb.usermaster  where Userid=" + Session["UserId"].ToString() + " ";
            ActiveCallvalue = ObjMain.ExecuteScalar(QueryCal);
            if (ActiveCallvalue == "")
            {
                ActiveCallvalue = ObjSel.GetFirstBranch7(Session["Branch_HQ"].ToString(), Session["UserId"].ToString());
            }


            ISHQ = ObjMain.ExecuteScalar("select BranchName from " + ActiveCallvalue + ".branches where Branchname='" + ActiveCallvalue + "' and branchID=1;");  //now 

            if (ISHQ != "")
            {
                ActiveCallvalue = ObjSel.GetFirstBranch7(Session["Branch_HQ"].ToString(), Session["UserId"].ToString());
                UPDATEBRANCH(ActiveCallvalue);
            }

            cd_BranchAlias = ActiveCallvalue;
            Curr_BranchFullName = ObjUserBL.GetBranchCurr_BranchVal(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), cd_BranchAlias);
            Cmb_BranchName = ObjUserBL.GetBranchRealValue(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), Curr_BranchFullName);  // This will Return BranchName( Actual Database Name )
            cmbBranches.Items.FindByText(Curr_BranchFullName).Selected = true;
            Branchidval = ObjUserBL.GetBranchIDbyName(ActiveCallvalue, ActiveCallvalue);
            if (Branchidval != "")
            {
                DT = ObjUserBL.GetPageRightsDetailsPIDNew(Session["UserId"].ToString(), PID, Branchidval);
            }
            else
            {
                DT = ObjUserBL.GetPageRightsDetailsPIDNew(Session["UserId"].ToString(), PID, Session["Fistbranch"].ToString());

            }


            if (DT.Rows.Count > 0)
            {
                Page_Acess = DT.Rows[0]["Acess_status"].ToString();
                Read_Acess = DT.Rows[0]["Read_Access"].ToString();
                Write_Acess = DT.Rows[0]["Write_Access"].ToString();
                Isdowld_Acess = DT.Rows[0]["IDwld_Access"].ToString();

                Session["Page_Acess"] = Page_Acess;
                Session["Read_Acess"] = Read_Acess;
                Session["Write_Acess"] = Write_Acess;
                Session["Isdowld_Acess"] = Isdowld_Acess;
            }

            Rcd_id = ObjMain.ExecuteScalar("select cd_id from portaldb.companydetails where cd_branchid=" + cmbBranches.SelectedItem.Value + " and cd_branchalias='" + ActiveCallvalue + "';");
            RPortalid = ObjMain.ExecuteScalar("select portaltypeid  from portaldb.invoicedetails where cd_id=" + Rcd_id + ";");
            DtLicense = ObjUserBL.GetLicenseDetails(RPortalid);

            if (DtLicense.Rows.Count > 0)
            {
                L_MaxUserCnt = DtLicense.Rows[0]["UserCnt"].ToString();
                L_RetailDashboard = DtLicense.Rows[0]["RETAILDASHBOARD"].ToString();
                L_SummarySales = DtLicense.Rows[0]["SUMMARYSALES"].ToString();
                L_ItemSales = DtLicense.Rows[0]["ITEMSALE"].ToString();
                L_TaxAnalysis = DtLicense.Rows[0]["TAXANALYSIS"].ToString();
                L_TopSale = DtLicense.Rows[0]["TOPSALE"].ToString();
                L_MothlySales = DtLicense.Rows[0]["MONTHLYSALE"].ToString();
                L_HourlySales = DtLicense.Rows[0]["HOURLYSALE"].ToString();
                L_GroupSale = DtLicense.Rows[0]["GROUPSALE"].ToString();
                L_Journal = DtLicense.Rows[0]["JOURNALREPORT"].ToString();
                // Create Session for License Variables 
                Session["L_MaxUserCnt"] = L_MaxUserCnt;
                Session["L_RetailDashboard"] = L_RetailDashboard;
                Session["L_SummarySales"] = L_SummarySales;
                Session["L_ItemSales"] = L_ItemSales;
                Session["L_TaxAnalysis"] = L_TaxAnalysis;
                Session["L_TopSale"] = L_TopSale;
                Session["L_MothlySales"] = L_MothlySales;
                Session["L_HourlySales"] = L_HourlySales;
                Session["L_GroupSale"] = L_GroupSale;
                Session["L_Journal"] = L_Journal;
            }
            if (Session["L_Journal"].ToString() == "N" || Session["Page_Acess"].ToString() == "N")
            {
                Response.Redirect("DeniedPage.aspx", false);
            }
            else
            {
                // XSS - Attack Prevention 
                string StartDT = Microsoft.Security.Application.Encoder.HtmlEncode(txtFromDt.Text.Trim());
                string EndDt = Microsoft.Security.Application.Encoder.HtmlEncode(txtToDt.Text.Trim());

                //btnExcel.Enabled = true;
                //lblMsgTotalSelection.Text = "Search Result - Journal Report Between" + "&nbsp;&nbsp;&nbsp;" + txtFromDt.Text + "&nbsp;&nbsp;&nbsp;  And &nbsp;&nbsp;&nbsp;" + txtToDt.Text;
                lblMsgTotalSelection.Text = "Search Result - from" + "&nbsp;&nbsp;" + StartDT + "&nbsp;&nbsp to &nbsp;&nbsp;" + EndDt;
                idGenReport.Attributes.Add("style", "background-color: #4c4c4c; color: White;font-size:14px");
                BraNam = cd_BranchAlias;
                FDate = txtFromDt.Text;
                TDate = txtToDt.Text;
                LoadJournalMainQuery(cd_BranchAlias, StartDT, EndDt);
                loadpaymenttype(cd_BranchAlias);
                //BindGridview(ActiveCallvalue, txtStartDt.Text, txtEndDt.Text);
                System.Threading.Thread.Sleep(2000);
            }
            Session["selecteddb"] = ActiveCallvalue; //john added on 12-Dec-2024 for change paymenttype
        }

        protected void cmbBranches_SelectedIndexChanged(object sender, EventArgs e)
        {
            // XSS - Attack Prevention 
            string StartDT = Microsoft.Security.Application.Encoder.HtmlEncode(txtFromDt.Text.Trim());
            string EndDt = Microsoft.Security.Application.Encoder.HtmlEncode(txtToDt.Text.Trim());

            if (cmbBranches.SelectedIndex == 0)
            {
                Response.Redirect("JournalReport.aspx", false);
            }
            else
            {
                DT = ObjUserBL.GetPageRightsDetailsPIDNew(Session["UserId"].ToString(), PID, cmbBranches.SelectedItem.Value);
                if (DT.Rows.Count > 0)
                {
                    Page_Acess = DT.Rows[0]["Acess_status"].ToString();
                    Read_Acess = DT.Rows[0]["Read_Access"].ToString();
                    Write_Acess = DT.Rows[0]["Write_Access"].ToString();
                    Isdowld_Acess = DT.Rows[0]["IDwld_Access"].ToString();

                    Session["Page_Acess"] = Page_Acess;
                    Session["Read_Acess"] = Read_Acess;
                    Session["Write_Acess"] = Write_Acess;
                    Session["Isdowld_Acess"] = Isdowld_Acess;
                }

                ISHQ = ObjMain.ExecuteScalar("select BranchName from branches where Branchname='" + ActiveCallvalue + "' and branchID=1;");  //now 

                if (ISHQ != "")
                {
                    ActiveCallvalue = ObjSel.GetFirstBranch(Session["Branch_HQ"].ToString());
                    UPDATEBRANCH(ActiveCallvalue);
                }
                else
                {
                    BranchFullName = cmbBranches.SelectedItem.Text;    // This will Return Branch FullName 
                    Cmb_BranchName = ObjUserBL.GetBranchRealValue(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), BranchFullName);  // This will Return BranchName( Actual Database Name )
                    Rcd_id = ObjMain.ExecuteScalar("select cd_id from portaldb.companydetails where cd_branchid=" + cmbBranches.SelectedItem.Value + " and cd_branchalias='" + Cmb_BranchName + "';");
                    RPortalid = ObjMain.ExecuteScalar("select portaltypeid  from portaldb.invoicedetails where cd_id=" + Rcd_id + ";");
                    DtLicense = ObjUserBL.GetLicenseDetails(RPortalid);

                }


                if (DtLicense.Rows.Count > 0)
                {
                    L_MaxUserCnt = DtLicense.Rows[0]["UserCnt"].ToString();
                    L_RetailDashboard = DtLicense.Rows[0]["RETAILDASHBOARD"].ToString();
                    L_SummarySales = DtLicense.Rows[0]["SUMMARYSALES"].ToString();
                    L_ItemSales = DtLicense.Rows[0]["ITEMSALE"].ToString();
                    L_TaxAnalysis = DtLicense.Rows[0]["TAXANALYSIS"].ToString();
                    L_TopSale = DtLicense.Rows[0]["TOPSALE"].ToString();
                    L_MothlySales = DtLicense.Rows[0]["MONTHLYSALE"].ToString();
                    L_HourlySales = DtLicense.Rows[0]["HOURLYSALE"].ToString();
                    L_GroupSale = DtLicense.Rows[0]["GROUPSALE"].ToString();
                    L_Journal = DtLicense.Rows[0]["JOURNALREPORT"].ToString();
                    // Create Session for License Variables 
                    Session["L_MaxUserCnt"] = L_MaxUserCnt;
                    Session["L_RetailDashboard"] = L_RetailDashboard;
                    Session["L_SummarySales"] = L_SummarySales;
                    Session["L_ItemSales"] = L_ItemSales;
                    Session["L_TaxAnalysis"] = L_TaxAnalysis;
                    Session["L_TopSale"] = L_TopSale;
                    Session["L_MothlySales"] = L_MothlySales;
                    Session["L_HourlySales"] = L_HourlySales;
                    Session["L_GroupSale"] = L_GroupSale;
                    Session["L_Journal"] = L_Journal;
                }
                if (Session["L_Journal"].ToString() == "N" || Session["Page_Acess"].ToString() == "N")
                {
                    Response.Redirect("DeniedPage.aspx", false);
                }
                else
                {
                    //btnExcel.Enabled = true;
                    //lblMsgTotalSelection.Text = "Group Sales Report Between" + "&nbsp;&nbsp;&nbsp;" + txtFromDt.Text + "&nbsp;&nbsp;&nbsp;  And &nbsp;&nbsp;&nbsp;" + txtToDt.Text;
                    //lblMsgTotalSelection.Text = " Search Result - Journal Report Between" + "&nbsp;&nbsp;&nbsp;" + txtFromDt.Text + "&nbsp;&nbsp;&nbsp;  And &nbsp;&nbsp;&nbsp;" + txtToDt.Text;
                    lblMsgTotalSelection.Text = "Search Result - from" + "&nbsp;&nbsp;" + StartDT + "&nbsp;&nbsp to &nbsp;&nbsp;" + EndDt;
                    idGenReport.Attributes.Add("style", "background-color: #4c4c4c; color: White;font-size:14px");
                    cd_BranchAlias = Cmb_BranchName;
                    BraNam = cd_BranchAlias;
                    FDate = txtFromDt.Text;
                    TDate = txtToDt.Text;
                    LoadJournalMainQuery(cd_BranchAlias, StartDT, EndDt);
                    //BindGridview(cd_BranchAlias, txtStartDt.Text, txtEndDt.Text);
                }
            }
            UPDATEBRANCH(Cmb_BranchName);
            loadpaymenttype(cd_BranchAlias);
            Session["selecteddb"] = Cmb_BranchName; //john added on 12-Dec-2024 for change paymenttype
        }

        public void UPDATEBRANCH(string ActiveCallvalue)
        {
            if (!string.IsNullOrEmpty(Session["UserId"] as string))
            {
                Useridvalue = Session["UserId"].ToString();
                QueryCurr_Select = "Update portaldb.usermaster set ActiveValue='" + ActiveCallvalue + "' where Userid=" + Useridvalue + "";
                S = ObjMain.ExecuteNonQuery(QueryCurr_Select);
            }
            else
            {
                Response.Redirect("Login.aspx", false);
            }
        }

        //from here onwards report code begins
        protected void btnGenerate_Click(object sender, EventArgs e)
        {
            // XSS - Attack Prevention 
            string StartDT = Microsoft.Security.Application.Encoder.HtmlEncode(txtFromDt.Text.Trim());
            string EndDt = Microsoft.Security.Application.Encoder.HtmlEncode(txtToDt.Text.Trim());

            if (cmbBranches.Visible == false)
            {
                btnGenerate.Visible = true;
                //lblMsgTotalSelection.Text = "Search Result - Journal Report Between" + "&nbsp;&nbsp;&nbsp;" + txtFromDt.Text + "&nbsp;&nbsp;&nbsp;  And &nbsp;&nbsp;&nbsp;" + txtToDt.Text;
                lblMsgTotalSelection.Text = "Search Result - from" + "&nbsp;&nbsp;" + StartDT + "&nbsp;&nbsp to &nbsp;&nbsp;" + EndDt;
                idGenReport.Attributes.Add("style", "background-color: #4c4c4c; color: White;font-size:14px");
                LoadJournalMainQuery(Session["Branch_HQ"].ToString(), StartDT, EndDt);
                System.Threading.Thread.Sleep(1000);
            }
            else if (cmbBranches.Visible == true)
            {
                //lblMsgTotalSelection.Text = "Search Result - Journal Report Between" + "&nbsp;&nbsp;&nbsp;" + txtFromDt.Text + "&nbsp;&nbsp;&nbsp;  And &nbsp;&nbsp;&nbsp;" + txtToDt.Text;
                lblMsgTotalSelection.Text = "Search Result - from" + "&nbsp;&nbsp;" + StartDT + "&nbsp;&nbsp to &nbsp;&nbsp;" + EndDt;
                idGenReport.Attributes.Add("style", "background-color: #4c4c4c; color: White;font-size:14px");
                Curr_BranchFullName = cmbBranches.SelectedItem.Text;
                cd_BranchAlias = ObjUserBL.GetBranchRealValue(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), Curr_BranchFullName);  // This will Return BranchName( Actual Database Name )
                BraNam = cd_BranchAlias;
                FDate = txtFromDt.Text;
                TDate = txtToDt.Text;
                LoadJournalMainQuery(cd_BranchAlias, StartDT, EndDt);
            }

            //


            ScriptManager.RegisterStartupScript(this, this.GetType(), "Script", "collapse();", true); //john added on 12-Dec-2024 
        }

        protected void LoadJournalMainQuery(string BranchAlias, string D1, string D2)
        {

            // XSS - Attack Prevention 
            string StartDT = Microsoft.Security.Application.Encoder.HtmlEncode(txtFromDt.Text.Trim());
            string EndDt = Microsoft.Security.Application.Encoder.HtmlEncode(txtToDt.Text.Trim());

            if (cmbBranches.Visible == false)
            {
                BranchAlias = Session["Branch_HQ"].ToString();
            }
            else
            {
                BranchFullName = Microsoft.Security.Application.Encoder.HtmlEncode(cmbBranches.SelectedItem.Text);    // This will Return Branch FullName 
                BranchAlias = ObjUserBL.GetBranchRealValue(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), BranchFullName);  // This will Return BranchName( Actual Database Name )
            }


            System.Threading.Thread.Sleep(1000);

            string sCmd, sCmd1;


            // Prevents SQL Injection  : 01-09-21
            // Parameterized Approach 

            //for getting Tax Names
            sCmd = "Select TaxName From {0}.Tax Where TaxID =1";
            string command = string.Format(sCmd, BranchAlias);
            DTTax = ObjMain.GetData_DT(command);

            foreach (DataRow dr in DTTax.Rows)
            {
                GridView1.Columns[11].HeaderText = Convert.ToString(dr["TaxName"]);
            }
            DTTax.Clear();

            sCmd1 = "Select TaxName From {0}.Tax Where TaxID =2";
            string command1 = string.Format(sCmd1, BranchAlias);
            DTTax = ObjMain.GetData_DT(command1);

            foreach (DataRow dr in DTTax.Rows)
            {
                GridView1.Columns[12].HeaderText = Convert.ToString(dr["TaxName"]);
            }
            DTTax.Clear();

            sCmd = " Select T.TransID as TransID, T.TransNo as TransNo, T.TransStatus as TStatus, DATE_FORMAT(T.TransDate,'%Y-%m-%d') as TDate, T.LastDate as LDate, T.CashierName as CName, T.SalesPersonName as SPName,T.CustomerNumber as CNo," +
                " Format(T.SubTotal,2) as SubTotal, Format((T.DiscAmount+T.MemberDiscAmount+T.BirthDayDiscAmount),2) as Disc, Format(T.TaxAmount1,2) as Tax1, Format(T.TaxAmount2,2) as Tax2, Format(T.Total,2) as Total " +
                " From {0}.Trans T " +
                " " +
                " Where T.BusinessDate Between  @StartDT  and  @EndDt  ";

            string Command = string.Format(sCmd, BranchAlias);


            MySqlParameter[] parameters =
                  {
                     new MySqlParameter("@StartDT",StartDT),
                     new MySqlParameter("@EndDt",EndDt),
                    };

            Dt1 = ObjMain.NewGetData_DT(Command, parameters);
            GridView1.DataSource = Dt1;
            //gridview totals
            GridView1.DataBind();
        }

        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {

            // XSS - Attack Prevention 
            string StartDT = Microsoft.Security.Application.Encoder.HtmlEncode(txtFromDt.Text.Trim());
            string EndDt = Microsoft.Security.Application.Encoder.HtmlEncode(txtToDt.Text.Trim());


            if (cmbBranches.Visible == false)
            {
                BraNam = Session["Branch_HQ"].ToString();
            }
            else
            {
                BranchFullName = Microsoft.Security.Application.Encoder.HtmlEncode(cmbBranches.SelectedItem.Text);    // This will Return Branch FullName 
                BraNam = ObjUserBL.GetBranchRealValue(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), BranchFullName);  // This will Return BranchName( Actual Database Name )
            }

            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                MySqlConnection Cn = new MySqlConnection(ConStr_Rds);
                Cn.Open();

                //for showing trans status texts
                TableCell statusCell = e.Row.Cells[3];
                caseSwitch = statusCell.Text;
                switch (caseSwitch)
                {
                    case "2":
                        statusCell.Text = "Paid";
                        break;
                    case "3":
                        statusCell.Text = "Hold";
                        break;
                    case "4":
                        statusCell.Text = "PB";
                        break;
                    case "5":
                        statusCell.Text = "Cancel";
                        break;
                    default:
                        statusCell.Text = "Others";
                        break;
                }

                //for Item Details
                GridView gv = (GridView)e.Row.FindControl("GridView2");
                Dt2.Clear();
                string sCmd, sCmd1;
                sCmd = "Select TD.TransID as ITransID, TD.ItemID as ItemID, Trim(TD.Barcode) as IBarcode, TD.Name as IName, TD.InventoryDesc as IDesc, TD.Qty as IQty,Format(TD.ActualPrice,2) as IActualPrice, Format(TD.Price,2) as IPrice," +
                    " (case when (TD.Class = 0 and TD.PriceType = '0' and TD.Price=TD.ActualPrice) then 'Normal' " +
                          " when (TD.Class = 0 and TD.PriceType = '1' ) then 'Manual' " +
                          " when (TD.Class = 0 and TD.PriceType = '2' ) then 'FOC' " +
                          " when (TD.Class = 6 and TD.PriceType = '0' ) then 'Zero' " +
                          " else 'Normal' " +
                    " end) as IPriceType, " +
                    " Format(TD.Amount-TD.ManualDisc-TD.MemberDisc,2) as IAmount, Format(TD.ManualDisc,2) as IDisc,Format(TD.MemberDisc,2) as MIDisc, " +
                    " (case when (TD.ItemStatus = '0') then 'Normal' " +
                          " when (TD.ItemStatus = '1') then 'Void' " +
                          " when (TD.ItemStatus = '2') then 'Return' " +
                          " else 'Others' " +
                    " end) as ISTA " +
                    " From {0}.Trans T Left Outer Join {0}.TransDetail TD On T.TransID=TD.TransID " +
                    " Where TD.TransID=" + ((DataRowView)e.Row.DataItem)["TransID"].ToString() + " And T.BusinessDate Between @StartDT  and  @EndDt  " +
                    " Order by 2";

                string command = string.Format(sCmd, BraNam);

                MySqlParameter[] parameters =
                  {
                     new MySqlParameter("@StartDT",StartDT),
                     new MySqlParameter("@EndDt",EndDt),
                    };

                Dt2 = ObjMain.NewGetData_DT(command, parameters);

                gv.DataSource = Dt2;
                gv.DataBind();

                //for Payment Details
                GridView gv1 = (GridView)e.Row.FindControl("GridView3");
                Dt3.Clear();
                sCmd1 = "Select T.TransID as TransID, TP.PaymentID as PaymentID, TP.PayDate as PPayDate, TP.PaymentType as PPaymentType, " +
                    " Format(TP.PaymentAmount,2) as PPaymentAmount, Trim(TP.CardNumber) as PCardNumber, Trim(TP.CardName) as PCardName,'' as PAction " +
                    " From {0}.Trans T Left Outer Join {0}.TransPayment TP On T.TransID=TP.TransID " +
                    " Where TP.TransID=" + ((DataRowView)e.Row.DataItem)["TransID"].ToString() + " And T.BusinessDate Between  @StartDT  and  @EndDt  " +
                    " Order by 2 ";

                string command1 = string.Format(sCmd1, BraNam);

                MySqlParameter[] paramss =
                  {
                     new MySqlParameter("@StartDT",StartDT),
                     new MySqlParameter("@EndDt",EndDt),
                    };

                Dt3 = ObjMain.NewGetData_DT(command1, paramss);

                //if (e.Row.RowType == DataControlRowType.DataRow)
                //{
                //    Button btnEdit = (Button)e.Row.FindControl("btnEdit");
                //    if (Session["Write_Acess"].ToString() == "N")
                //    {
                //        btnEdit.Visible = false;
                //    }
                //    else
                //    {
                //        btnEdit.Visible = true;
                //    }
                //}

                if (Session["Write_Acess"].ToString() == "N") //john added on 12-Dec-2024
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Script", "checkButtonPermission();", true);
                }

                gv1.DataSource = Dt3;
                gv1.DataBind();
            }
        }

        //protected void GridView3_RowCommand(object sender, GridViewCommandEventArgs e)
        //{
        //    if (e.CommandName != "Edit") return;
        //    int index = Convert.ToInt16(e.CommandArgument);
        //    //GridView gv1 = (GridView)sender;
        //    //GridViewRow gvr1 = (GridViewRow)gv1.Rows[e.];
        //}

        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {

            // XSS Attack Prevention 
            string StartDT = Microsoft.Security.Application.Encoder.HtmlEncode(txtFromDt.Text.Trim());
            string EndDt = Microsoft.Security.Application.Encoder.HtmlEncode(txtToDt.Text.Trim());


            if (cmbBranches.Visible == false)
            {
                GridView1.PageIndex = e.NewPageIndex;
                LoadJournalMainQuery(Session["Branch_HQ"].ToString(), StartDT, EndDt);
            }
            else
            {
                BranchFullName = Microsoft.Security.Application.Encoder.HtmlEncode(cmbBranches.SelectedItem.Text);    // This will Return Branch FullName 
                Cmb_BranchName = ObjUserBL.GetBranchRealValue(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), BranchFullName);  // This will Return BranchName( Actual Database Name )

                GridView1.PageIndex = e.NewPageIndex;
                LoadJournalMainQuery(Cmb_BranchName, StartDT, EndDt);
            }
        }

        protected void btnExcel_Click(object sender, EventArgs e)
        {


            // XSS Attack Prevention 
            string StartDT = Microsoft.Security.Application.Encoder.HtmlEncode(txtFromDt.Text.Trim());
            string EndDt = Microsoft.Security.Application.Encoder.HtmlEncode(txtToDt.Text.Trim());


            if (cmbBranches.Visible == true)
            {
                Curr_BranchFullName = Microsoft.Security.Application.Encoder.HtmlEncode(cmbBranches.SelectedItem.Text);
                cd_BranchAlias = ObjUserBL.GetBranchRealValue(Session["Branch_HQ"].ToString(), Session["UserId"].ToString(), Curr_BranchFullName);  // This will Return BranchName( Actual Database Name )
                BraNam = cd_BranchAlias;
            }
            else
            {

                BraNam = Session["Branch_HQ"].ToString();

            }
            //nid added excel export on 08-Apr-2020

            Dt2.Clear();
            string sCmd;
            //nid hide on 06-Oct-2020
            //sCmd = "Select T.TransID as TransID, T.TransNo as TransNo,  case  T.TransStatus when 2 then  'Paid'  when 3 then 'Hold'  when 4 then 'PB'  When 5 then 'Cancel'   else 'Others'  end  STA , DATE_FORMAT(T.TransDate,'%Y-%m-%d') as TDate, T.LastDate as LDate, T.CashierName as CName, T.SalesPersonName as SPName," +
            //    " Format(T.SubTotal,2) as SubTotal, Format((T.DiscAmount+T.MemberDiscAmount+T.BirthDayDiscAmount),2) as Disc, Format(T.TaxAmount1,2) as Tax1, Format(T.TaxAmount2,2) as Tax2, Format(T.Total,2) as Total," +
            //    " TD.TransID as ITransID, TD.ItemID as ItemID, Trim(TD.Barcode) as IBarcode, TD.Name as IName, TD.InventoryDesc as IDesc, TD.Qty as IQty," +
            //    " Format(TD.Price,2) as IPrice, Format(TD.Amount,2) as IAmount, Format(TD.ManualDisc,2) as IDisc," +
            //    " T.TransID as TransID, TP.PaymentID as PaymentID, TP.PayDate as PPayDate, TP.PaymentType as PPaymentType," +
            //    " Format(TP.PaymentAmount,2) as PPaymentAmount, Trim(TP.CardNumber) as PCardNumber, Trim(TP.CardName) as PCardName, Trim(T.CustomerNumber) as CustID " +
            //    " From " + BraNam + ".Trans T Left Outer Join " + BraNam + ".TransDetail TD On T.TransID=TD.TransID" +
            //    " Left Outer Join " + BraNam + ".TransPayment TP on T.TransID=TP.TransID " +
            //    " Where T.BusinessDate Between '" + txtFromDt.Text + "' and '" + txtToDt.Text + "' ";

            //MySqlDataAdapter Ada = new MySqlDataAdapter(sCmd, Cn);
            //ds = new DataSet();
            //Ada.Fill(Dt2);

            //Part 1 Different Types of Payment Types used in the period (Datatable Dt2) on 06-Oct-2020
            sSelQry = "";
            sCondQry = "";
            //sCmd = "Select Distinct PaymentType" +
            //sCmd = "Select Distinct Replace(PaymentType,' ','') as PaymentType" +
            //    " From " + BraNam + ".Trans T Left Outer Join " + BraNam + ".TransPayment TP On T.TransID=TP.TransID " +
            //    " Where T. TransStatus in (2) And T.BusinessDate Between '" + txtFromDt.Text + "' and '" + txtToDt.Text + "' ";
            sCmd = "Select Distinct Replace(PaymentType,' ','') as PaymentType" +
                 " From {0}.TransPayment TP  " +
                 " Where  TP.BusinessDate Between  @StartDT  and  @EndDt  ";

            DtP.Clear();

            string command = string.Format(sCmd, BraNam);
            MySqlParameter[] parameters =
                  {
                     new MySqlParameter("@StartDT",StartDT),
                     new MySqlParameter("@EndDt",EndDt),
                    };

            DtP = ObjMain.NewGetData_DT(command, parameters);


            //Sum(Round(ifnull(K.CASH,0),2)) as CASH, Sum(Round(ifnull(K.NETS,0),2)) as NETS
            //case when TP.PaymentType = 'CASH' then TP.PaymentAmount end as CASH,
            if (DtP.Rows.Count != 0)
            {
                foreach (DataRow row in DtP.Rows)
                {
                    if (sSelQry == "")
                    {
                        sSelQry = ",format(Sum(Round(ifnull(K." + row["PaymentType"] + ",0),2)),2) as " + row["PaymentType"];
                        //sCondQry = ",case when TP.PaymentType='" + row["PaymentType"] + "' then TP.PaymentAmount end As " + row["PaymentType"];
                        sCondQry = ",case when Replace(TP.PaymentType,' ','')='" + row["PaymentType"] + "' then TP.PaymentAmount end As " + row["PaymentType"];
                    }
                    else
                    {
                        sSelQry = sSelQry + ",format(Sum(Round(ifnull(K." + row["PaymentType"] + ",0),2)),2) as " + row["PaymentType"];
                        sCondQry = sCondQry + ",case when Replace(TP.PaymentType,' ','')='" + row["PaymentType"] + "' then TP.PaymentAmount end As " + row["PaymentType"];
                    }
                }
            }

            //Part 2 Main Query for Excel Export
            sCmd = " Select  TransID,TransNo,STA,TDate,LDate,CName,SPName,CustID,SubTotal,Disc,Tax1,Tax2,Total,ITransID,ItemID,IBarcode,IName,IDesc,IQty,IPrice,IAmount,IDisc,ISTA," +
            " PTransID " + sSelQry + " From (" +
            " Select T.TransID as TransID, T.TransNo as TransNo,  case  T.TransStatus when 2 then  'Paid'  when 3 then 'Hold'  when 4 then 'PB'  When 5 then 'Cancel'   else 'Others'  end  STA ," +
            " DATE_FORMAT(T.TransDate,'%Y-%m-%d') as TDate, T.LastDate as LDate, T.CashierName as CName, T.SalesPersonName as SPName, Trim(T.CustomerNumber) as CustID, Format(T.SubTotal,2) as SubTotal," +
            " Format((T.DiscAmount+T.MemberDiscAmount+T.BirthDayDiscAmount),2) as Disc, Format(T.TaxAmount1,2) as Tax1, Format(T.TaxAmount2,2) as Tax2, Format(T.Total,2) as Total," +
            " TD.TransID as ITransID, TD.ItemID as ItemID, Trim(TD.Barcode) as IBarcode, TD.Name as IName, TD.InventoryDesc as IDesc, TD.Qty as IQty, Format(TD.Price,2) as IPrice," +
            " Format(TD.Amount,2) as IAmount, Format(TD.ManualDisc,2) as IDisc,case  TD.ItemStatus when 0 then  'Normal'  when 1 then 'Void'  when 2 then 'Return'  else 'Others'  end  ISTA ," +
            " T.TransID as PTransID,TP.PaymentID as PaymentID " + sCondQry +
            " ,Trim(TP.CardNumber) as CardNumber, Trim(TP.CardName) as CardName" +
            " From {0}.Trans T Left Outer Join {0}.TransDetail TD On T.TransID=TD.TransID" +
            " Left Outer Join {0}.TransPayment TP on T.TransID=TP.TransID" +
            " Where  T.BusinessDate Between   @StartDT and  @EndDt  " +
            " ) K Group by TransID,ItemID";

            string command1 = string.Format(sCmd, BraNam);

            MySqlParameter[] paramss =
                  {
                     new MySqlParameter("@StartDT",StartDT),
                     new MySqlParameter("@EndDt",EndDt),
                    };

            Dt1 = ObjMain.NewGetData_DT(command1, paramss);


            //Create a dummy GridView
            GridView GridView1 = new GridView();
            GridView1.AllowPaging = false;
            GridView1.DataSource = Dt1;
            GridView1.DataBind();


            Response.Clear();
            Response.Buffer = true;
            Response.AddHeader("content-disposition",
             "attachment;filename=JournalReport.xls");
            Response.Charset = "";
            Response.ContentType = "application/vnd.ms-excel";
            StringWriter sw = new StringWriter();
            HtmlTextWriter hw = new HtmlTextWriter(sw);
            for (int i = 0; i < GridView1.Rows.Count; i++)
            {
                //Apply text style to each Row
                GridView1.Rows[i].Attributes.Add("class", "textmode");
            }

            GridView1.RenderControl(hw);
            string style = @"<style> td { mso-number-format:\@; } </style>";
            Response.Write(style);
            Response.Output.Write(sw.ToString());
            Response.Flush();
            Response.End();

            //ExportExcel();


        }

        public void ExportExcel()
        {

            DataTable dt = new DataTable("GridView_Data");
            GridView gvGridview2 = (GridView)GridView1.Rows[1].FindControl("Gridview2");
            foreach (TableCell cell in GridView1.HeaderRow.Cells)
            {
                dt.Columns.Add(cell.Text);
            }
            foreach (TableCell cell in gvGridview2.HeaderRow.Cells)
            {
                dt.Columns.Add(cell.Text);
            }
            dt.Columns.RemoveAt(0);
            foreach (GridViewRow row in GridView1.Rows)
            {
                GridView gvGridview2Cell = (row.FindControl("gvGridview2") as GridView);
                for (int j = 0; j < gvGridview2Cell.Rows.Count; j++)
                {
                    dt.Rows.Add(row.Cells[1].Text, row.Cells[2].Text, gvGridview2Cell.Rows[j].Cells[0].Text, gvGridview2Cell.Rows[j].Cells[1].Text);
                }
            }

            //using (XLWorkbook wb = new XLWorkbook())
            //{
            //    wb.Worksheets.Add(dt);

            //    Response.Clear();
            //    Response.Buffer = true;
            //    Response.Charset = "";
            //    Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
            //    Response.AddHeader("content-disposition", "attachment;filename=GridView.xlsx");
            //    using (MemoryStream MyMemoryStream = new MemoryStream())
            //    {
            //        wb.SaveAs(MyMemoryStream);
            //        MyMemoryStream.WriteTo(Response.OutputStream);
            //        Response.Flush();
            //        Response.End();
            //    }
            //}




            //Create a dummy GridView
            GridView GridView5 = new GridView();
            GridView5.AllowPaging = false;
            GridView5.DataSource = dt;
            GridView5.DataBind();


            Response.Clear();
            Response.Buffer = true;
            Response.AddHeader("content-disposition",
             "attachment;filename=JournalReport.xls");
            Response.Charset = "";
            Response.ContentType = "application/vnd.ms-excel";
            StringWriter sw = new StringWriter();
            HtmlTextWriter hw = new HtmlTextWriter(sw);
            for (int i = 0; i < GridView5.Rows.Count; i++)
            {
                //Apply text style to each Row
                GridView1.Rows[i].Attributes.Add("class", "textmode");
            }

            GridView1.RenderControl(hw);
            string style = @"<style> td { mso-number-format:\@; } </style>";
            Response.Write(style);
            Response.Output.Write(sw.ToString());
            Response.Flush();
            Response.End();





        }

     
        //public override void VerifyRenderingInServerForm(Control control)
        //{
        //    /* Confirms that an HtmlForm control is rendered for the specified ASP.NET
        //       server control at run time. */
        //}

        public void loadpaymenttype(string db) //john added on 12-Dec-2024 for change paymenttype
        {
            cmbpaymenttypes.DataSource = ObjSel.paymenttypes(db);
            cmbpaymenttypes.DataTextField = "paymenttype";
            cmbpaymenttypes.DataValueField = "paymenttype";
            cmbpaymenttypes.DataBind();
            //cmbpaymenttypes.Items.Insert(0, "Select PaymentType");

        }

        protected void btnLog_Click(object sender, EventArgs e)
        {
            DataTable dtLog = new DataTable();

            Cmb_BranchName = Session["selecteddb"].ToString();           
            string dtfrom = txtFromDt.Text.Trim();
            string dtto = txtToDt.Text.Trim();
            dtLog = ObjSel.getChangePaymentLog(Cmb_BranchName, dtfrom, dtto);

            GridView GridView1 = new GridView();
            GridView1.AllowPaging = false;
            GridView1.DataSource = dtLog;
            GridView1.DataBind();
            Response.Clear();
            Response.Buffer = true;
            Response.ContentEncoding = System.Text.Encoding.Unicode;
            Response.BinaryWrite(System.Text.Encoding.Unicode.GetPreamble());
            Response.Charset = "";
            Response.AddHeader("content-disposition",
                "attachment;filename=changepaymentlog.xls");

            Response.ContentType = "application/vnd.ms-excel";
            StringWriter sw = new StringWriter();
            HtmlTextWriter hw = new HtmlTextWriter(sw);
            for (int i = 0; i < GridView1.Rows.Count; i++)
            {
                GridView1.Rows[i].Attributes.Add("class", "textmode");
            }
            GridView1.RenderControl(hw);
            string style = @"<style> td { mso-number-format:\@; } </style>";
            Response.Write(style);
            Response.Output.Write(sw.ToString());
            Response.Flush();
            Response.End();
        }

        [WebMethod]
        public static string getCurrentPaymentType(int transid) //john added on 12-Dec-2024 for change paymenttype
        {
            HttpContext context = HttpContext.Current;
            MYSQLCLOUD ObjMain = new MYSQLCLOUD();

            string db = context.Session["selecteddb"].ToString();
            string paymenttype;
            string scmd = "select paymenttype from {0}.transpayment where transid = @transid";
            string command = string.Format(scmd, db);

            MySqlParameter[] param = {
                new MySqlParameter("@transid",transid),
            };
            paymenttype = ObjMain.NewExecuteScalar(command, param);
            return paymenttype;
        }

        [WebMethod]
        public static void putPaymenttype(int transid, string paymenttype) //john added on 12-Dec-2024 for change paymenttype
        {
            HttpContext context = HttpContext.Current;
            string db = context.Session["selecteddb"].ToString();

            MYSQLCLOUD ObjMain = new MYSQLCLOUD();
            string scmd = "update {0}.transpayment set paymenttype = @paymenttype where transid=@transid;";
            string command = string.Format(scmd, db);

            MySqlParameter[] param = {
                new MySqlParameter("@paymenttype",paymenttype),
                new MySqlParameter("@transid",transid),
            };

            ObjMain.ExecuteQuery(command, param);
        }

        [WebMethod]
        public static void postLog(int transid, string transno, DateTime transactiondate, string frompaymenttype, DateTime changepaymenttypedate, string topaymenttype) //john added on 12-Dec-2024 for change paymenttype
        {
            HttpContext context = HttpContext.Current;
            MYSQLCLOUD ObjMain = new MYSQLCLOUD();
            string db = context.Session["selecteddb"].ToString();
            string userid = context.Session["UserId"].ToString(); 
            string username = context.Session["UserName"].ToString();
            string scmd = "insert into {0}.changepaymentlog(transid,transno,transactiondate,frompaymenttype,changepaymenttypedate,topaymenttype,userid,username)" +
                "           values(@transid,@transno,@transactiondate,@frompaymenttype,@chanegpaymenttypedate,@topaymenttype,@userid,@username)";
            string command = string.Format(scmd, db);
            MySqlParameter[] param = {
                new MySqlParameter("@transid", transid),
                new MySqlParameter("@transno", transno),
                new MySqlParameter("@transactiondate", transactiondate),
                new MySqlParameter("@frompaymenttype", frompaymenttype),
                new MySqlParameter("@chanegpaymenttypedate", changepaymenttypedate),
                new MySqlParameter("@topaymenttype", topaymenttype),
                new MySqlParameter("@userid", userid),
                new MySqlParameter("@username", username),
            };

            ObjMain.ExecuteQuery(command, param);
        }

    }
}