Пример #1
0
    private void UserAdd()
    {
        string data = "";

        try
        {
            if (rdoCityLocation.SelectedItem.Value == "SC")
            {
                ubal.CityName = Convert.ToString(Session["CityNameN"]);
            }
            else if (rdoCityLocation.SelectedItem.Value == "DC")
            {
                if (cmbCity.SelectedValue != null)
                {
                    ubal.CityName = Convert.ToString(cmbCity.SelectedItem.Text);
                }
                else
                {
                    ubal.CityName = Convert.ToString(Session["CityNameN"]);
                }
                if (cmbDistrict.SelectedValue != null)
                {
                    ubal.District = Convert.ToString(cmbDistrict.SelectedItem.Text);
                }
                else
                {
                    ubal.District = Convert.ToString(Session["CityNameN"]);
                }
            }
            else if (rdoCityLocation.SelectedItem.Value == "DC")
            {
                if (cmbDistrict.SelectedValue != null)
                {
                    ubal.District = Convert.ToString(cmbDistrict.SelectedItem.Text);
                }
                else
                {
                    ubal.District = Convert.ToString(Session["CityNameN"]);
                }
            }
            if (ddlRole.SelectedValue == "34" || ddlRole.SelectedValue == "35" || ddlRole.SelectedValue == "36")
            {
                if (ddlmenselection.SelectedValue == "1")
                {
                    ubal.RoleName1 = Convert.ToString(ddlRole.SelectedItem.Text) + "-Public";
                    ubal.RoleId1   = Convert.ToInt32(ddlRole.SelectedValue);
                    string roleid = Convert.ToString(ubal.RoleId1);
                    ubal.RoleId1 = Convert.ToInt32(roleid);
                }
                else if (ddlmenselection.SelectedValue == "2")
                {
                    ubal.RoleName1 = Convert.ToString(ddlRole.SelectedItem.Text) + "-Govt";
                    ubal.RoleId1   = Convert.ToInt32(ddlRole.SelectedValue);
                    string roleid = Convert.ToString(ubal.RoleId1);
                    ubal.RoleId1 = Convert.ToInt32(roleid);
                }
            }
            else
            {
                ubal.RoleName1 = Convert.ToString(ddlRole.SelectedItem.Text);
                ubal.RoleId1   = Convert.ToInt32(ddlRole.SelectedValue);
            }
            /////////////////////////

            if (ubal.RoleId1 == 14 || ubal.RoleId1 == 15 || ubal.RoleId1 == 16 || ubal.RoleId1 == 17 || ubal.RoleId1 == 18 || ubal.RoleId1 == 19 || ubal.RoleId1 == 20 || ubal.RoleId1 == 21 || ubal.RoleId1 == 75 || ubal.RoleId1 == 76 || ubal.RoleId1 == 77)
            {
                Response.Write("<script>alert('You can not Add this member of Marketing Persons')</script>");
            }
            else
            {
                ubal.MONO = Convert.ToString(Session["Mobile"]);
                ubal.Date = Convert.ToString(cc.ChangeDate(txtDOB.Text));
                ubal.Id   = Convert.ToString(ViewState["User"]);
                string  sql11 = "select usrUserid,usrFirstName from usermaster where usrMobileNo='" + ubal.MONO + "'";
                DataSet ds    = new DataSet();
                ds = cc.ExecuteDataset(sql11);
                string usruserid = ds.Tables[0].Rows[0]["usrUserid"].ToString();

                //string usruserid = cc.ExecuteScalar(sql11);

                ///Add Here For EzeeTest Marketing Tree Managment when creating role as marketing person

                string  gt  = "select usrUserid,usrFirstName from usermaster where usrMobileNo='" + txtMobileNumber.Text + "'";
                DataSet ds0 = new DataSet();
                ds0 = cc.ExecuteDataset(gt);
                string usruserid1   = ds0.Tables[0].Rows[0]["usrUserid"].ToString();
                string usrFirstName = ds0.Tables[0].Rows[0]["usrFirstName"].ToString();
                string deal         = "Update [Come2myCityDB].[come2mycity].[tbl_TreeDemOfMarketingSection] set [Role]='" + ubal.RoleName1 + "',ParentName='" + usrFirstName + "' where [Parent_MobileNo]='" + txtMobileNumber.Text + "'";
                cc.ExecuteNonQuery(deal);

                string deal1 = "Update usermaster set [isMarketingPerson]='Y' where [usrMobileNo]='" + txtMobileNumber.Text + "'";
                cc.ExecuteNonQuery(deal1);

                status = ubal.insertUser(ubal);
                if (status > 0)
                {
                    if (ddlRole.SelectedValue == "29")
                    {
                        for (int i = 0; i < chkCommitee.Items.Count; i++)
                        {
                            if (chkCommitee.Items[i].Selected == true)
                            {
                                data = data + "," + chkCommitee.Items[i].Value;
                                //data = data + "," + chkCommitee.Items[i].Value;
                            }
                        }
                        if (data.Length > 1)
                        {
                            data = data.Substring(1);
                        }

                        ubal.Id          = Convert.ToString(ViewState["User"]);
                        ubal.Committeeid = data;
                        status           = ubal.BLLinsertUserCommittee(ubal);

                        string AddJunior = "update [Come2myCityDB].[come2mycity].AdminSubMarketingSubUser set Mainrole=0 where friendid='" + usruserid + "' ";
                        int    Data1     = cc.ExecuteNonQuery(AddJunior);

                        string sql = "insert into [Come2myCityDB].[come2mycity].AdminSubMarketingSubUser(userid,roleid,rolename,friendid,doj,reference_id1,Ref_Ways ,Active ,mainrole)" +
                                     "values('" + usruserid + "','" + ubal.RoleId1 + "','" + ubal.RoleName1 + "','" + ubal.Id + "','" + CurrenctDate + "','" + usruserid + "','AddNewUser',1,1)";
                        string a = cc.ExecuteScalar(sql);
                    }
                    else if (ddlRole.SelectedValue == "28")
                    {
                        data             = "1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31";
                        ubal.Id          = Convert.ToString(ViewState["User"]);
                        ubal.Committeeid = data;
                        status           = ubal.BLLinsertUserCommittee(ubal);

                        string AddJunior = "update [Come2myCityDB].[come2mycity].AdminSubMarketingSubUser set Mainrole=0 where friendid='" + usruserid + "' ";
                        int    Data1     = cc.ExecuteNonQuery(AddJunior);

                        string sql = "insert into [Come2myCityDB].[come2mycity].AdminSubMarketingSubUser(userid,roleid,rolename,friendid,doj,reference_id1,Ref_Ways,Active ,mainrole)" +
                                     "values('" + usruserid + "','" + ubal.RoleId1 + "','" + ubal.RoleName1 + "','" + ubal.Id + "','" + CurrenctDate + "','" + usruserid + "','AddNewUser',1,1)";
                        string a = cc.ExecuteScalar(sql);
                    }
                    else
                    {
                        string AddJunior = "update [Come2myCityDB].[come2mycity].AdminSubMarketingSubUser set Mainrole=0 where friendid='" + usruserid + "' ";
                        int    Data1     = cc.ExecuteNonQuery(AddJunior);

                        string sql = "insert into [Come2myCityDB].[come2mycity].AdminSubMarketingSubUser(userid,roleid,rolename,friendid,doj,reference_id1,Ref_Ways,Active ,mainrole)" +
                                     "values('" + usruserid + "','" + ubal.RoleId1 + "','" + ubal.RoleName1 + "','" + ubal.Id + "','" + CurrenctDate + "','" + usruserid + "','AddNewUser',1,1)";
                        int a = cc.ExecuteNonQuery(sql);
                    }
                    string Sql = "Update UserMaster set IsMarketingPerson='Y' where UsrUserId='" + Convert.ToString(ViewState["User"]) + "'";
                    cc.ExecuteNonQuery(Sql);

                    //Sql = "update [Come2myCityDB].[dbo].[EzeeDrugsAppDetail] set='10' where mobileNo='" + Convert.ToString(Session["MobileNumber"]) + "'";
                    //cc.ExecuteNonQuery(Sql);

                    string query     = "select id from [Come2myCityDB].[come2mycity].TreeDemo where userid='" + usruserid + "' and Roleid= 1";
                    string CheckTree = cc.ExecuteScalar(query); // Get leader ID already add in tree digrame
                    if (!(CheckTree == null || CheckTree == ""))
                    {
                        // string check_Available = "select id from TreeDemo where userid='" + JuniorNo_usrID + "' and id=" + CheckTree + " ";
                        string check_Available = "select parentid from [Come2myCityDB].[come2mycity].TreeDemo where userid='" + ubal.Id + "' and Roleid=" + ubal.RoleId1 + "";

                        string GetID = cc.ExecuteScalar(check_Available); // check leader ID & Juniour Is already define or Not
                        if (!(GetID == null || GetID == ""))
                        {
                            if (CheckTree == GetID)
                            {
                                //Not
                            }
                            else
                            {
                                string Addtree = "insert into [Come2myCityDB].[come2mycity].TreeDemo(userid,parentid,RoleId)values('" + ubal.Id + "','" + CheckTree + "'," + ubal.RoleId1 + ")";
                                int    b       = cc.ExecuteNonQuery(Addtree); // add new juniour in tree digrame
                            }
                        }
                        else
                        {
                            string Addtree = "insert into [Come2myCityDB].[come2mycity].TreeDemo(userid,parentid,RoleId)values('" + ubal.Id + "','" + CheckTree + "'," + ubal.RoleId1 + ")";
                            int    b       = cc.ExecuteNonQuery(Addtree); // add new juniour in tree digrame
                        }
                    }

                    ScriptManager.RegisterStartupScript(this, typeof(Page), "msg", "alert('This Marketing Person Added Successfully')", true);
                    Response.Redirect("../MarketingAdmin/UserList.aspx");
                }

                else
                {
                    //Page.ClientScript.RegisterStartupScript(typeof(Page), "MessagePopUp", "alert('This Marketing Person is already exist'); window.location.href ='../MarketingAdmin/UserList.aspx';", true);
                    ScriptManager.RegisterStartupScript(this, typeof(Page), "msg", "alert('This Marketing Person is already exist')", true);

                    HttpContext.Current.ApplicationInstance.CompleteRequest();
                }
            }
            /////////////////////////////////////////////////////////////////
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }