示例#1
0
    protected void buttonadd_click(object sender, EventArgs e)
    {
        /////Add Exception handilng try catch change by vishal 21-05-2012
        try
        {
            #region Find Userid of User who is Requesting to log a call

            #region If User Already Exist
            if (ViewState["UserCreate"].ToString() == "Exist")
            {
                objOrganization = objOrganization.Get_Organization();
                ObjUserLogin    = ObjUserLogin.Get_UserLogin_By_UserName(txtUsername.Text.ToString().Trim(), objOrganization.Orgid);
                if (ObjUserLogin.Userid != 0)
                {
                    requesterid = ObjUserLogin.Userid;
                }
            }
            #endregion
            #region If New User is to be Created
            else if (ViewState["UserCreate"].ToString() == "create")
            {
                string varEmail    = "";
                string varRoleName = Resources.MessageResource.BasicUserRole.ToString();
                if (txtEmail.Text == "")
                {
                    varEmail = Resources.MessageResource.errMemshipCreateUserEmail.ToString();
                }
                else
                {
                    varEmail = txtEmail.Text;
                }


                int roleid = objRole.Get_By_RoleName(varRoleName);
                int status;
                objOrganization = objOrganization.Get_Organization();

                objuser.Username       = txtUsername.Text.ToString();
                objuser.Password       = Resources.MessageResource.strDefaultPassword.ToString();
                objuser.Roleid         = roleid;
                objuser.Orgid          = objOrganization.Orgid;
                objuser.ADEnable       = false;
                objuser.Enable         = true;
                objuser.Createdatetime = DateTime.Now.ToString();
                status = objuser.Insert();
                if (status == 1)
                {
                    // Create Mstatus field to send in Membership.CreateUser function as Out Variable for creating Membership User database
                    MembershipCreateStatus Mstatus = default(MembershipCreateStatus);
                    // Call Membership.CreateUser function to create Membership user
                    Membership.CreateUser(txtUsername.Text.ToString().Trim(), Resources.MessageResource.strDefaultPassword.ToString(), varEmail, "Project Name", "Helpdesk", true, out Mstatus);
                    // Call Roles.AddUserToRole Function to Add User To Role
                    Roles.AddUserToRole(txtUsername.Text.ToString().Trim(), varRoleName);
                    // Declare Local Variable Userid to fetch userid of newly created user

                    // Create Object objUserLogin of UserLogin_mst()Class
                    objuser = new UserLogin_mst();
                    // Fetch userid of Newly created user and assign to local variable userid by calling function objUserLogin.Get_By_UserName
                    requesterid = objuser.Get_By_UserName(txtUsername.Text.ToString().Trim(), objOrganization.Orgid);
                    // If userid not equal to 0 then we get userid of Newly created user otherwise error Occured

                    ContactInfo_mst objContactInfo = new ContactInfo_mst();
                    objContactInfo.Userid    = requesterid;
                    objContactInfo.Emailid   = varEmail;
                    objContactInfo.Firstname = txtUsername.Text.ToString();
                    objContactInfo.Lastname  = txtUsername.Text.ToString();
                    objContactInfo.Insert();
                }
            }
            #endregion
            #region If User is Not to be Created
            else if (ViewState["UserCreate"].ToString() == "notcreate")
            {
                // FlagUserStatus = false;
            }
            #endregion

            #endregion
            ObjChange.Active = true;

            ObjChange.Statusid      = Convert.ToInt32(drpStatus.SelectedValue);
            ObjChange.Categoryid    = Convert.ToInt32(drpCategory.SelectedValue);
            ObjChange.Subcategoryid = Convert.ToInt32(drpSubcategory.SelectedValue);
            // ObjChange.Technician =Convert.ToInt32(drpTechnician.SelectedValue);
            ObjChange.Title          = txtTitle.Text;
            ObjChange.Description    = txtDescription.Text;
            ObjChange.Createdtime    = DateTime.Now.ToString();
            ObjChange.Changetype     = Convert.ToInt32(drpchangetype.SelectedValue);
            ObjChange.Approvalstatus = "Send For Approval";
            MembershipUser user     = Membership.GetUser();
            string         username = user.UserName.ToString();
            objOrganization = objOrganization.Get_Organization();
            ObjUserLogin    = ObjUserLogin.Get_UserLogin_By_UserName(username, objOrganization.Orgid);
            int userid = Convert.ToInt32(ObjUserLogin.Userid);
            ObjChange.CreatedByID = userid;
            ObjUserLogin          = ObjUserLogin.Get_UserLogin_By_UserName(txtUsername.Text, objOrganization.Orgid);
            ObjChange.Requestedby = ObjUserLogin.Userid;
            // ObjChange.Priority = Convert.ToInt32(drpPriority.SelectedValue);
            ObjChange.Insert();
            int changeid = ObjChange.Get_Current_Changeid();
            for (int i = ListAsset.Items.Count - 1; i >= 0; i--)
            {
                if (ListAsset.Items[i].Selected == true)
                {
                    Objincludeaasetchange.Assetid  = Convert.ToInt32(ListAsset.Items[i].Value);
                    Objincludeaasetchange.Changeid = changeid;
                    Objincludeaasetchange.Insert();
                }
            }
            ObjChangeHistory.Changeid = changeid;
            // ObjChangeHistory.Description = "create";
            ObjChangeHistory.Operation        = "create";
            ObjChangeHistory.Operationownerid = ObjUserLogin.Userid;
            ObjChangeHistory.Insert();
            int changetype = Convert.ToInt32(drpchangetype.SelectedValue);

            objSentEmailToChange.SentMailToChangeCommittee(changeid, changetype);

            Response.Redirect("~/Change/EditChange.aspx?" + changeid + " ");
        }
        catch (Exception ex)
        {
            string myScript;
            myScript = "<script language=javascript>alert('Exception - '" + ex + "');</script>";
            Page.RegisterClientScriptBlock("MyScript", myScript);
            return;
        }
    }
    protected void buttonadd_click(object sender, EventArgs e)
    {
        #region Find Userid of User who is Requesting to log a call

        #region If User Already Exist
        if (ViewState["UserCreate"].ToString() == "Exist")
        {
            objOrganization = objOrganization.Get_Organization();
            ObjUserLogin    = ObjUserLogin.Get_UserLogin_By_UserName(txtUsername.Text.ToString().Trim(), objOrganization.Orgid);
            if (ObjUserLogin.Userid != 0)
            {
                requesterid = ObjUserLogin.Userid;
            }
        }
        #endregion
        #region If New User is to be Created
        else if (ViewState["UserCreate"].ToString() == "create")
        {
            string varEmail    = "";
            string varRoleName = Resources.MessageResource.BasicUserRole.ToString();
            if (txtEmail.Text == "")
            {
                varEmail = Resources.MessageResource.errMemshipCreateUserEmail.ToString();
            }
            else
            {
                varEmail = txtEmail.Text;
            }


            int roleid = objRole.Get_By_RoleName(varRoleName);
            int status;
            objOrganization = objOrganization.Get_Organization();

            objuser.Username       = txtUsername.Text.ToString();
            objuser.Password       = Resources.MessageResource.strDefaultPassword.ToString();
            objuser.Roleid         = roleid;
            objuser.Orgid          = objOrganization.Orgid;
            objuser.ADEnable       = false;
            objuser.Enable         = true;
            objuser.Createdatetime = DateTime.Now.ToString();
            status = objuser.Insert();
            if (status == 1)
            {
                // Create Mstatus field to send in Membership.CreateUser function as Out Variable for creating Membership User database
                MembershipCreateStatus Mstatus = default(MembershipCreateStatus);
                // Call Membership.CreateUser function to create Membership user
                Membership.CreateUser(txtUsername.Text.ToString().Trim(), Resources.MessageResource.strDefaultPassword.ToString(), varEmail, "Project Name", "Helpdesk", true, out Mstatus);
                // Call Roles.AddUserToRole Function to Add User To Role
                Roles.AddUserToRole(txtUsername.Text.ToString().Trim(), varRoleName);
                // Declare Local Variable Userid to fetch userid of newly created user

                // Create Object objUserLogin of UserLogin_mst()Class
                objuser = new UserLogin_mst();
                // Fetch userid of Newly created user and assign to local variable userid by calling function objUserLogin.Get_By_UserName
                requesterid = objuser.Get_By_UserName(txtUsername.Text.ToString().Trim(), objOrganization.Orgid);
                // If userid not equal to 0 then we get userid of Newly created user otherwise error Occured

                ContactInfo_mst objContactInfo = new ContactInfo_mst();
                objContactInfo.Userid    = requesterid;
                objContactInfo.Emailid   = varEmail;
                objContactInfo.Firstname = txtUsername.Text.ToString();
                objContactInfo.Lastname  = txtUsername.Text.ToString();
                objContactInfo.Insert();
            }
        }
        #endregion
        #region If User is Not to be Created
        else if (ViewState["UserCreate"].ToString() == "notcreate")
        {
            // FlagUserStatus = false;
        }
        #endregion

        #endregion
        ObjChange.Active = true;

        ObjChange.Statusid       = Convert.ToInt16(drpStatus.SelectedValue);
        ObjChange.Categoryid     = Convert.ToInt16(drpCategory.SelectedValue);
        ObjChange.Subcategoryid  = Convert.ToInt16(drpSubcategory.SelectedValue);
        ObjChange.Technician     = Convert.ToInt16(drpTechnician.SelectedValue);
        ObjChange.Title          = txtTitle.Text;
        ObjChange.Description    = txtDescription.Text;
        ObjChange.Createdtime    = DateTime.Now.ToString();
        ObjChange.Changetype     = Convert.ToInt16(drpchangetype.SelectedValue);
        ObjChange.Approvalstatus = "Send For Approval";
        MembershipUser user     = Membership.GetUser();
        string         username = user.UserName.ToString();
        objOrganization = objOrganization.Get_Organization();
        ObjUserLogin    = ObjUserLogin.Get_UserLogin_By_UserName(username, objOrganization.Orgid);
        int userid = Convert.ToInt16(ObjUserLogin.Userid);
        ObjChange.CreatedByID = userid;
        ObjUserLogin          = ObjUserLogin.Get_UserLogin_By_UserName(txtUsername.Text, objOrganization.Orgid);
        ObjChange.Requestedby = ObjUserLogin.Userid;
        ObjChange.Priority    = Convert.ToInt16(drpPriority.SelectedValue);
        ObjChange.Insert();
        int changeid = ObjChange.Get_Current_Changeid();
        for (int i = ListAsset.Items.Count - 1; i >= 0; i--)
        {
            if (ListAsset.Items[i].Selected == true)
            {
                Objincludeaasetchange.Assetid  = Convert.ToInt16(ListAsset.Items[i].Value);
                Objincludeaasetchange.Changeid = changeid;
                Objincludeaasetchange.Insert();
            }
        }
        ObjProblemToChange.Changeid  = changeid;
        ObjProblemToChange.Problemid = Convert.ToInt16(Session["problemid"]);
        ObjProblemToChange.Insert();
        ScriptManager.RegisterStartupScript(this, this.GetType(), "Close()", "Close();", true);
    }