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 System.Data.OleDb;

namespace SUNWEB
{
    public partial class UserCreation : 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 Dt2 = 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();
        // User Variables 
        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;
        // License Variables ..
        string PID = string.Empty;
        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_RetailPayment = string.Empty;
        string Branchidval = string.Empty;
        string BranchFullName = string.Empty;
        string Curr_BranchFullName = string.Empty;
        string Cmb_BranchName = string.Empty;

        string HQ = string.Empty;
        string Cm_id = string.Empty;
        string ISHQ = string.Empty;
        DataSet DS = new DataSet();

        string cd_id = string.Empty;
        string Cust_Id = string.Empty;
        string DataPath = string.Empty;
        string Cd_BranchAlias = string.Empty;
        string cd_BranchId = string.Empty;
        string IsmultiBranch = string.Empty;
        
        string ChkHq = string.Empty;
        string Status = "A";
        string GCmid = string.Empty;


        protected void Page_Load(object sender, EventArgs e)
        {

            //  Changed Code on 27-03-23
            if (Session["UserName"] == null)
            {
                Response.Redirect("Login.aspx");
            }

            PID = "9";    // This is for UserCreation  Page 

            //  Changed Code on 27-03-23
            if (!string.IsNullOrEmpty(Session["UserId"] as string))
            {
                string GetCmidQuery = "select cm_id from  {0}.usermaster where userid=@userid;";
                string Command = string.Format(GetCmidQuery, "portaldb");

                MySqlParameter[] parameters =
                       {
                     new MySqlParameter("@userid",Session["UserId"].ToString()),

                    };
                GCmid = ObjMain.NewExecuteScalar(Command, parameters);
                hidCmid.Value = GCmid;
            }


            if (!IsPostBack)
            {

            }
            MonthstartDt = new DateTime(System.DateTime.Now.Year, System.DateTime.Now.Month, 1);
            if (Session["UserName"] == null)
            {
                Response.Redirect("Login.aspx");
            }
            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;
                //LoadInventoryListGrid(cd_BranchAlias, txtStartDt.Text, txtEndDt.Text);
            }
            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 = "Branch Name" + "&nbsp;" + "-" + "&nbsp;" + Curr_BranchFullName + "&nbsp; ";

                cd_BranchAlias = Session["Branch_HQ"].ToString();
                Datapath = Session["DataPath"].ToString();
                PortalTypeId = Session["PortalTypeId"].ToString();

                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_RetailPayment"].ToString() == "N") || (Session["Page_Acess"].ToString() == "N"))
                {
                    Response.Redirect("DeniedPage.aspx");
                }
                else
                {
                    // lblMsgTotalSelection.Text = "Item Sale  Between" + "&nbsp;&nbsp;&nbsp;&nbsp;" + txtStartDt.Text + "&nbsp;&nbsp;&nbsp;  and  &nbsp;&nbsp;&nbsp;" + txtEndDt.Text;
                    if (!IsPostBack)
                    {
                        if (Session["Isdowld_Acess"].ToString() == "N")
                        {
                            // btnExcel.Enabled = false;
                            Response.Write(@"<script language='javascript'>alert('No Access To download.')</script>");
                        }
                        else
                        {


                            if (cmbBranches.Visible == false)
                            {
                                //  BindGridview(Session["Branch_HQ"].ToString(), txtStartDt.Text, txtEndDt.Text);
                            }

                        }


                    }

                }

            }
            else
            {

            }


        }


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


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

            if (ISHQ != "")
            {
                ActiveCallvalue = ObjSel.GetFirstBranch(Session["Branch_HQ"].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_RetailPayment = DtLicense.Rows[0]["RETAILPAYMENT"].ToString();
                Session["L_RetailPayment"] = L_RetailPayment;
            }
            if (Session["L_RetailPayment"].ToString() == "N" || Session["Page_Acess"].ToString() == "N")
            {
                Response.Redirect("DeniedPage.aspx");
            }
            else
            {
                LoadCompany();
                LoadBranchHeader();
                //btnExcel.Enabled = true;
                //lblMsgTotalSelection.Text = "Total Sale Selection Between" + "&nbsp;&nbsp;&nbsp;" + txtStartDt.Text + "&nbsp;&nbsp;&nbsp;  And &nbsp;&nbsp;&nbsp;" + txtEndDt.Text;
                cd_BranchAlias = cmbBranches.SelectedItem.Text;
                // BindGridview(ActiveCallvalue, txtStartDt.Text, txtEndDt.Text);
                System.Threading.Thread.Sleep(2000);

            }

        }


        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 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 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");

            }

        }


        public void LoadCompany()
        {
            cmbCompanyName.DataSource = ObjBL.GetCompanyList(hidCmid.Value);

            cmbCompanyName.DataTextField = "cm_name";
            cmbCompanyName.DataValueField = "cm_id";
            cmbCompanyName.DataBind();

        }
        public void LoadBranchHeader()
        {
            cmbBranchHeader.DataSource = ObjBL.BranchHeader(hidCmid.Value);
            cmbBranchHeader.DataValueField = "cd_id";
            cmbBranchHeader.DataTextField = "cd_branchname";
            cmbBranchHeader.DataBind();


        }

        protected void btnGetReports_Click(object sender, EventArgs e)
        {

        }

        protected void cmbBranches_SelectedIndexChanged(object sender, EventArgs e)
        {
        }


        protected void btnSave_Click(object sender, EventArgs e)
        {
            SaveCreateUser();

        }
        public void SaveCreateUser()
        {
            ReadBranchInfo();
            ObjCustPL.UserName = txtUserName.Text.ToString().Trim();
            ObjCustPL.Password = txtPassword.Text.ToString().Trim();
            ObjCustPL.PortalTypeId = PortalTypeId;
            ObjCustPL.cd_id = cd_id;
            ObjCustPL.DataPath = DataPath;
            ObjCustPL.cd_BranchAlias = Cd_BranchAlias;
            // Checks the MultiBranch Checkbox 
            if (chkIsMultiBranch.Checked == true)
            {
                string MutIBranch = "1";
                ObjCustPL.IsMultiBranch = MutIBranch;
            }
            else
            {
                string MutIBranch = "0";
                ObjCustPL.IsMultiBranch = MutIBranch;

            }

            // Checks IsSuperAdmin Checkbox
            if (chkIsSuperAdmin.Checked == true)
            {
                string IssuperAdm = "1";
                ObjCustPL.IsSuperAdmin = IssuperAdm;
            }
            else
            {

                string IssuperAdm = "0";
                ObjCustPL.IsSuperAdmin = IssuperAdm;
            }

            if (Convert.ToInt32(ChkHq) != 1)
            {

                string ChkUserNameQuery = "Select UserName from {0}.usermaster where Username=@Username;";
                string CommandA = string.Format(ChkUserNameQuery,"portaldb" );

                MySqlParameter[] parametersA =
                   {
                     new MySqlParameter("@Username",txtUserName.Text.ToString().Trim()),
                   };

                string ChkUserName = ObjMain.NewExecuteScalar(CommandA, parametersA);
                
                /*Exisiting Code */
                //string ChkUserName = ObjMain.ExecuteScalar("Select UserName from portaldb.usermaster where Username='" + txtUserName.Text.ToString().Trim() + "'  ");

                if (ChkUserName != "")
                {

                    ScriptManager.RegisterStartupScript(Page, Page.GetType(), "err_msg", "alert('User Name Exist ! Try Another UserName');location.href='UserCreation.aspx '", true);

                }
                else
                {

                    string ActiveVal = "0";

                    /*  Existing Code 
                    string Query = "Insert into  portaldb.usermaster(UserName,Password,PortalTypeId,cm_id,cd_id,Datapath,cd_BranchAlias,IsMultiBranch,IssuperAdmin,Status,Active)Values('" + ObjCustPL.UserName + "', '" + ObjCustPL.Password + "'," + ObjCustPL.PortalTypeId + "," + cmbCompanyName.SelectedItem.Value + " ," + ObjCustPL.cd_id + ",'" + ObjCustPL.DataPath + "','" + ObjCustPL.cd_BranchAlias + "' ," + ObjCustPL.IsMultiBranch + "," + ObjCustPL.IsSuperAdmin + ",'" + Status + "'," + ActiveVal + ") ";
                    K = ObjMain.ExecuteNonQuery(Query);
                    */
                    string Ins_Query = " Insert into  {0}.usermaster(UserName,Password,PortalTypeId,cm_id,cd_id,Datapath,cd_BranchAlias,IsMultiBranch,IssuperAdmin,Status,Active)" +
                        "Values(@UserName, @Password,@PortalTypeId,@cm_id ,@cd_id,@Datapath,@cd_BranchAlias,@IsMultiBranch,@IssuperAdmin,@Status,@Active);";

                    string CommandB = string.Format(Ins_Query, "portaldb");

                    

                    MySqlParameter[] parametersB =
                      {
                     new MySqlParameter("@UserName",ObjCustPL.UserName),
                     new MySqlParameter("@Password",ObjCustPL.Password),
                     new MySqlParameter("@PortalTypeId",ObjCustPL.PortalTypeId),
                     new MySqlParameter("@cm_id",cmbCompanyName.SelectedItem.Value),
                     new MySqlParameter("@cd_id",ObjCustPL.cd_id),
                     new MySqlParameter("@Datapath",ObjCustPL.DataPath),
                     new MySqlParameter("@cd_BranchAlias",ObjCustPL.cd_BranchAlias),
                     new MySqlParameter("@IsMultiBranch",ObjCustPL.IsMultiBranch),
                     new MySqlParameter("@IssuperAdmin",ObjCustPL.IsSuperAdmin),
                     new MySqlParameter("@Status",Status),
                     new MySqlParameter("@Active",ActiveVal),
                                          
                     };

                    L = ObjMain.ExecuteQuery(CommandB, parametersB);
                                        
                    UserCreatedLogs();
                    if (L > 0)
                    {
                        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "err_msg", "alert('User Has been Created');location.href='UserCreation.aspx '", true);
                    }
                    else
                    {
                        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "err_msg", "alert('User  Creation Failed');location.href='UserCreation.aspx '", true);
                    }

                }



            }
            else
            {


                string ChkUserNameQuery = "Select UserName from {0}.usermaster where Username=@Username;";
                string CommandA = string.Format(ChkUserNameQuery, "portaldb");

                MySqlParameter[] parametersA =
                   {
                     new MySqlParameter("@Username",txtUserName.Text.ToString().Trim()),
                   };

                string ChkUserName = ObjMain.NewExecuteScalar(CommandA, parametersA);

                /*Exisiting Code */
                //string ChkUserName = ObjMain.ExecuteScalar("Select UserName from portaldb.usermaster where Username='" + txtUserName.Text.ToString().Trim() + "'  ");

                if (ChkUserName != "")
                {

                    ScriptManager.RegisterStartupScript(Page, Page.GetType(), "err_msg", "alert('User Name Exist ! Try Another UserName');location.href='UserCreation.aspx '", true);

                }
                else
                {

                    string ActiveVal = "0";

                    string Ins_Query = " Insert into  {0}.usermaster(UserName,Password,cm_id,cd_id,Datapath,cd_BranchAlias,IsMultiBranch,IssuperAdmin,Status,Active)" +
                            "Values(@UserName, @Password,@cm_id ,@cd_id,@Datapath,@cd_BranchAlias,@IsMultiBranch,@IssuperAdmin,@Status,@Active);";

                    string CommandB = string.Format(Ins_Query, "portaldb");
                    ObjCustPL.PortalTypeId = "";
                    MySqlParameter[] parametersB =
                      {
                     new MySqlParameter("@UserName",ObjCustPL.UserName),
                     new MySqlParameter("@Password",ObjCustPL.Password),
                     //new MySqlParameter("@PortalTypeId",string.Empty),
                     new MySqlParameter("@cm_id",cmbCompanyName.SelectedItem.Value),
                     new MySqlParameter("@cd_id",ObjCustPL.cd_id),
                     new MySqlParameter("@Datapath",ObjCustPL.DataPath),
                     new MySqlParameter("@cd_BranchAlias",ObjCustPL.cd_BranchAlias),
                     new MySqlParameter("@IsMultiBranch",ObjCustPL.IsMultiBranch),
                     new MySqlParameter("@IssuperAdmin",ObjCustPL.IsSuperAdmin),
                     new MySqlParameter("@Status",Status),
                     new MySqlParameter("@Active",ActiveVal),

                     };

                    L = ObjMain.ExecuteQuery(CommandB, parametersB);

                    UserCreatedLogs();
                    if (L > 0)
                    {
                        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "err_msg", "alert('User Has been Created');location.href='UserCreation.aspx '", true);
                    }
                    else
                    {
                        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "err_msg", "alert('User  Creation Failed');location.href='UserCreation.aspx '", true);
                    }



                }


            }


        }


        public void ReadBranchInfo()
        {
            cd_id = cmbBranchHeader.SelectedItem.Value;


            // Parameterized Approach
            string Query = "select cd_hq from {0}.companydetails where cd_id={1}";
            string Command = string.Format(Query, "portaldb", cd_id );
            ChkHq = ObjMain.ExecuteScalar(Command);

            // Existing Query 
            //ChkHq = ObjMain.ExecuteScalar("select cd_hq from portaldb.companydetails where cd_id=" + cd_id + "");
            if (Convert.ToInt32(ChkHq) != 1)
            {
                DT = ObjUserBL.GetBranchInfo(cd_id);
            }
            else
            {
                DT = ObjUserBL.GetBranchInfoOnHQ(cd_id);

            }

            if (DT.Rows.Count > 0)
            {

                if (Convert.ToInt32(ChkHq) != 1)
                {

                    PortalTypeId = DT.Rows[0]["Portaltypeid"].ToString();
                    Cd_BranchAlias = DT.Rows[0]["cd_BranchAlias"].ToString();
                    cd_BranchId = DT.Rows[0]["cd_Branchid"].ToString();
                    DataPath = ObjMain.ExecuteScalar("select  DataPath from  " + Cd_BranchAlias + ".branches  where Branchid=" + cd_BranchId + "");

                }
                else
                {
                    //PortalTypeId = DT.Rows[0]["Portaltypeid"].ToString();
                    Cd_BranchAlias = DT.Rows[0]["cd_BranchAlias"].ToString();
                    cd_BranchId = DT.Rows[0]["cd_Branchid"].ToString();
                    DataPath = ObjMain.ExecuteScalar("select  DataPath from  " + Cd_BranchAlias + ".branches  where Branchid=" + cd_BranchId + "");


                }




            }



        }
        /// <summary>
        ///  Log Entery while create the Users . 
        /// </summary>
        public void UserCreatedLogs()
        {

            string RUserid = string.Empty;
            string GetUseridQuery = "select userid from {0}.usermaster where UserName=@UserName and Password=@Password ";
            string Command = string.Format(GetUseridQuery, "portaldb");

            MySqlParameter[] parameters =
                  {
                     new MySqlParameter("@UserName",ObjCustPL.UserName),
                     new MySqlParameter("@Password",ObjCustPL.Password),
                  };

            RUserid = ObjMain.NewExecuteScalar(Command, parameters);

            ObjCustPL.UserId = Convert.ToString(RUserid);
            ObjCustPL.CreateDt = Convert.ToDateTime(Curr_Date);
            ObjCustPL.CreateBy = Session["UserName"].ToString();
            string Qry = " Insert into {0}.usercreatedlog (Logid,Cm_id,Details,CreatedDt,CreatedBy) " +
                         " values(@Logid,@Cm_id,@Details,@CreatedDt,@CreatedBy);";

            string CommandA = string.Format( Qry, "portaldb");
            string CompanyName = ObjSel.GetCmp_Namee(Session["CM_ID"].ToString());

            string DetailsText = " CompanyName: " + CompanyName + " Created Userid:" + RUserid + " Created By: " + ObjCustPL.CreateBy + "   CreatedDate: " + ObjCustPL.CreateDt + "  ";


            MySqlParameter[] parametersA =
                 {
                     new MySqlParameter("@Logid",RUserid),
                     new MySqlParameter("@Cm_id", Session["CM_ID"].ToString()),
                     new MySqlParameter("@Details",DetailsText),
                     new MySqlParameter("@CreatedDt",ObjCustPL.CreateDt),
                     new MySqlParameter("@CreatedBy",ObjCustPL.CreateBy),
                 };



            L = ObjMain.ExecuteQuery(CommandA, parametersA);

        }


    }
}