Beispiel #1
0
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        #region Declaration of Local Variables
        int    siteid, priorityid;
        int    SLAid       = 0;
        int    createdbyid = 0;
        int    requesterid = 0;
        int    FlagInsert;
        int    requesttypeid;
        string userName;
        bool   FlagUserStatus;
        FlagUserStatus = true;
        FlagInsert     = 0;
        #endregion
        #region Fetch Current User
        MembershipUser User = Membership.GetUser();
        userName = User.UserName.ToString();
        #endregion
        #region Get Current Site and Priority id
        siteid     = Convert.ToInt16(drpSite.SelectedValue);
        priorityid = Convert.ToInt16(drpPriority.SelectedValue);
        #endregion
        #region Get SLAid on the basis of siteid and Priority id

        if (siteid != 0 && priorityid != 0)
        {
            SLAid         = objIncident.Get_By_SLAid(siteid, priorityid);
            requesttypeid = Convert.ToInt16(Resources.MessageResource.strRequestTypeId.ToString());
            if (requesttypeid == Convert.ToInt16(drpRequestType.SelectedValue))
            {
                SLAid = 0;
            }
        }
        #endregion
        if (userName != "")
        {
            #region Find Userid of User who Created this Request
            objOrganization = objOrganization.Get_Organization();
            objUser         = objUser.Get_UserLogin_By_UserName(userName, objOrganization.Orgid);
            if (objUser.Userid != 0)
            {
                createdbyid = objUser.Userid;
            }

            #endregion
            #region Find Userid of User who is Requesting to log a call
            #region If User Already Exist
            if (Session["UserCreate"].ToString() == "Exist")
            {
                objUser = objUser.Get_UserLogin_By_UserName(txtUsername.Text.ToString().Trim(), objOrganization.Orgid);
                if (objUser.Userid != 0)
                {
                    requesterid = objUser.Userid;
                }
            }
            #endregion
            #region If New User is to be Created
            else if (Session["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();
                UserLogin_mst objUserLogin = new UserLogin_mst();
                objUserLogin.Username       = txtUsername.Text.Trim().ToString();
                objUserLogin.Password       = Resources.MessageResource.strDefaultPassword.ToString();
                objUserLogin.Roleid         = roleid;
                objUserLogin.Orgid          = objOrganization.Orgid;
                objUserLogin.ADEnable       = false;
                objUserLogin.Enable         = true;
                objUserLogin.Createdatetime = DateTime.Now.ToString();
                status = objUserLogin.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
                    objUserLogin = new UserLogin_mst();
                    // Fetch userid of Newly created user and assign to local variable userid by calling function objUserLogin.Get_By_UserName
                    requesterid = objUserLogin.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 (Session["UserCreate"].ToString() == "notcreate")
            {
                FlagUserStatus = false;
            }
            #endregion

            #endregion
        }

        objIncident.Title = txtTitle.Text.Trim();
        //objIncident.Title = drpTitle.SelectedItem.Text;
        objIncident.Slaid          = SLAid;
        objIncident.Createdbyid    = createdbyid;
        objIncident.Requesterid    = requesterid;
        objIncident.Siteid         = siteid;
        objIncident.Description    = txtDescription.Text.ToString().Trim();
        objIncident.Deptid         = Convert.ToInt16(drpDepartment.SelectedValue);
        objIncident.Createdatetime = DateTime.Now.ToString();
        IFormatProvider provider = new System.Globalization.CultureInfo("en-CA", true);
        String          datetime = txtReportedDate.Text.Trim();

        DateTime dt = DateTime.Parse(datetime, provider, System.Globalization.DateTimeStyles.NoCurrentDateDefault);
        //changed by prachi

        //objIncident.Reporteddatetime = dt.ToShortDateString() + " " + DateTime.Now.ToShortTimeString();
        DateTime dtNowForTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, Convert.ToInt32(drpTimeHours.SelectedItem.Text), Convert.ToInt32(drpTimeMin.SelectedItem.Text), 0);
        //end prachi

        objIncident.Reporteddatetime = dt.ToShortDateString() + " " + dtNowForTime.ToShortTimeString();
        objIncident.Modeid           = Convert.ToInt16(drpMode.SelectedValue);
        //objIncident.ExternalTicketNo = txtExternalTicket.Text.ToString().Trim();
        if (FlagUserStatus == true)
        {
            FlagInsert = objIncident.Insert();
            #region Save Assetid and incident id in incidenttoassetmaaping
            // Get Asset and Incident Id for incidenttoassetmaaping
            objOrganization = objOrganization.Get_Organization();
            objUser         = objUser.Get_UserLogin_By_UserName(txtUsername.Text.Trim().ToString().Trim(), objOrganization.Orgid);
            int userid    = Convert.ToInt16(objUser.Userid);
            int tempuser1 = Convert.ToInt16(Session["tempuser1"]);
            if (tempuser1 == 1)
            {
                assetid = Convert.ToInt16(Session["assetid"]);
            }
            else
            {
                assetid = Convert.ToInt16(objusertoasset.Get_AssetId_By_UserId(userid));
            }
            int incid = Convert.ToInt16(objIncident.Get_TopIncidentId());
            //if (txtassignasset.Text != "")
            {
                //assetid = Convert.ToInt16(txtassignasset.Text);
                if (assetid != 0)
                {
                    objincidenttoasset.Insert(incid, assetid);
                    objusertoasset.Insert(userid, assetid);
                    Session.Abandon();
                }
            }

            #endregion
        }

        if (FlagInsert == 1)
        {
            int FlagIncdStatesInsert;
            int incidentid;
            incidentid = objIncident.Get_Current_Incidentid();
            objIncidentStates.Incidentid    = incidentid;
            objIncidentStates.Priorityid    = Convert.ToInt16(drpPriority.SelectedValue);
            objIncidentStates.Categoryid    = Convert.ToInt16(drpCategory.SelectedValue);
            objIncidentStates.Statusid      = Convert.ToInt16(drpStatus.SelectedValue);
            objIncidentStates.Subcategoryid = Convert.ToInt16(drpSubcategory.SelectedValue);
            objIncidentStates.Technicianid  = Convert.ToInt16(drpTechnician.SelectedValue);
            if (Convert.ToInt16(drpTechnician.SelectedValue) != 0)
            {
                objIncidentStates.AssignedTime = DateTime.Now.ToString();
            }
            objIncidentStates.Requesttypeid = Convert.ToInt16(drpRequestType.SelectedValue);
            FlagIncdStatesInsert            = objIncidentStates.Insert();
            if (FlagIncdStatesInsert == 1)
            {
                objIncidentHistory.Incidentid       = incidentid;
                objIncidentHistory.Operation        = "create";
                objIncidentHistory.Operationownerid = createdbyid;
                objIncidentHistory.Insert();

                objSentmailtoUser.SentmailUser(requesterid, incidentid, "open");
                if (Convert.ToInt16(drpTechnician.SelectedValue) != 0)
                {
                    objSentmailtoUser.SentmailTechnician(Convert.ToInt16(drpTechnician.SelectedValue), incidentid);
                }
                ////////////////////Added by lalit 28nov to /////////////////////////////////////////////////////
                if (Session["id"] != null)
                {
                    int           id = Convert.ToInt32(Session["id"].ToString());
                    SqlConnection con;
                    SqlCommand    cmd;
                    string        connection = ConfigurationManager.ConnectionStrings["CSM_DB"].ConnectionString;
                    con = new SqlConnection(connection);
                    cmd = new SqlCommand();
                    con.Open();
                    cmd.Connection  = con;
                    cmd.CommandText = "update storemail set IsActive=2 where id='" + id + "'";
                    cmd.ExecuteNonQuery();
                }

                Response.Redirect("~/Incident/IncidentRequestUpdate.aspx?" + incidentid + "");
            }
        }
    }
Beispiel #2
0
    //protected void BindDropCustomer()
    //{
    //    BLLCollection<Customer_mst> colCtS = new BLLCollection<Customer_mst>();

    //    string userName = "";
    //    MembershipUser User = Membership.GetUser();
    //    if (User != null)
    //    {
    //        userName = User.UserName.ToString();
    //    }


    //    if (userName != "")
    //    {
    //        int userid;
    //        int Flagcount = 0;
    //        objOrganization = objOrganization.Get_Organization();
    //        objUser = objUser.Get_UserLogin_By_UserName(userName, objOrganization.Orgid);
    //        if (objUser.Userid != 0)
    //        {
    //            userid = objUser.Userid;
    //            colUserToSite = ObjUserToSite.Get_All_By_userid(userid);
    //            foreach (UserToSiteMapping obj in colUserToSite)
    //            {
    //                int siteid;
    //                Site_mst objSite1 = new Site_mst();
    //                siteid = obj.Siteid;
    //                objSite1 = objSite1.Get_By_id(siteid);
    //                if (objSite1.Siteid != 0)
    //                {
    //                    colCustToSite=objCustToSite.Get_All_By_siteid(objSite1.Siteid);


    //                    foreach (CustomerToSiteMapping objcts in colCustToSite)
    //                    {
    //                        Customer_mst objC = new Customer_mst();
    //                        int FlagStatus = 0;
    //                        objC = objC.Get_By_id(objcts.Custid);
    //                        if (Flagcount == 0)
    //                        {
    //                            colCtS.Add(objC);
    //                        }
    //                        else
    //                        {
    //                            foreach (Customer_mst objCus in colCtS)
    //                            {
    //                                if (objC.Custid == objCus.Custid)
    //                                {
    //                                    FlagStatus = 1;
    //                                }

    //                            }
    //                            if (FlagStatus==0)
    //                            {
    //                                colCtS.Add(objC);
    //                            }

    //                        }

    //                        Flagcount = Flagcount + 1;

    //                    }

    //                }

    //            }


    //        }


    //    }

    //    drpCustomer.DataTextField = "Customer_Name";
    //    drpCustomer.DataValueField = "CustId";
    //    drpCustomer.DataSource = colCtS;
    //    drpCustomer.DataBind();
    //    if (colCtS.Count  == 0)
    //    {
    //        ListItem item = new ListItem();
    //        item.Text = "-------------Select-------------";
    //        item.Value = "0";
    //        drpCustomer.Items.Add(item);

    //    }



    //}
    protected void btnAdd_Click(object sender, EventArgs e)
    {//Add Exception handilng try catch change by vishal 21-05-2012
        try
        {
            Session["UserCreate"] = "Exist";

            #region Declaration of Local Variables
            int    siteid, priorityid;
            int    SLAid       = 0;
            int    createdbyid = 0;
            int    requesterid = 0;
            int    FlagInsert;
            int    requesttypeid;
            string userName;
            bool   FlagUserStatus;
            FlagUserStatus = true;
            FlagInsert     = 0;
            #endregion

            #region Fetch Current User
            MembershipUser User = Membership.GetUser();
            userName = User.UserName.ToString();
            #endregion
            #region Get Current Site and Priority id
            siteid     = Convert.ToInt32(drpSite.SelectedValue);
            priorityid = Convert.ToInt32(drpPriority.SelectedValue);
            #endregion


            #region Get SLAid on the basis of siteid and Priority id

            if (siteid != 0 && priorityid != 0)
            {
                SLAid         = objIncident.Get_By_SLAid(siteid, priorityid);
                requesttypeid = Convert.ToInt32(Resources.MessageResource.strRequestTypeId.ToString());
                if (requesttypeid == Convert.ToInt32(drpRequestType.SelectedValue))
                {
                    SLAid = 0;
                }
            }
            #endregion
            if (userName != "")
            {
                #region Find Userid of User who Created this Request
                objOrganization = objOrganization.Get_Organization();
                objUser         = objUser.Get_UserLogin_By_UserName(userName, objOrganization.Orgid);
                if (objUser.Userid != 0)
                {
                    createdbyid = objUser.Userid;
                }

                #endregion



                #region Find Userid of User who is Requesting to log a call

                #region If User Already Exist
                if (Session["UserCreate"].ToString() == "Exist")
                {
                    objUser = objUser.Get_UserLogin_By_UserName(txtUsername.Text.ToString().Trim(), objOrganization.Orgid);
                    if (objUser.Userid != 0)
                    {
                        requesterid = objUser.Userid;
                    }
                }
                #endregion



                #endregion
            }

            //added by lalit
            objIncident.Reporteddatetime = DBNull.Value.ToString();
            objIncident.AMCCall          = false;
            //end
            objIncident.Title          = txtTitle.Text.ToString().Trim() + "-" + TxtExtension.Text.Trim();
            objIncident.Slaid          = SLAid;
            objIncident.Createdbyid    = createdbyid;
            objIncident.Requesterid    = requesterid;
            objIncident.Siteid         = siteid;
            objIncident.Description    = txtDescription.Text.ToString().Trim();
            objIncident.Deptid         = 0;
            objIncident.Createdatetime = DateTime.Now.ToString();
            objIncident.Modeid         = Convert.ToInt32(drpMode.SelectedValue);
            UserToSiteMapping objUserToSite = new UserToSiteMapping();

            if (FlagUserStatus == true)
            {
                FlagInsert = objIncident.Insert();

                #region Save Assetid and incident id in incidenttoassetmaaping


                objOrganization = objOrganization.Get_Organization();
                objUser         = objUser.Get_UserLogin_By_UserName(txtUsername.Text.ToString().Trim(), objOrganization.Orgid);
                int userid    = Convert.ToInt32(objUser.Userid);
                int tempuser1 = Convert.ToInt32(Session["tempuser1"]);
                if (tempuser1 == 1)
                {
                    assetid = Convert.ToInt32(Session["assetid"]);
                }
                else
                {
                    assetid = Convert.ToInt32(objusertoasset.Get_AssetId_By_UserId(userid));
                }
                int incid = Convert.ToInt32(objIncident.Get_TopIncidentId());
                if (txtassignasset.Text != "")
                {
                    //assetid = Convert.ToInt32(txtassignasset.Text);
                    if (assetid != 0)
                    {
                        objincidenttoasset.Insert(incid, assetid);
                        objusertoasset.Insert(userid, assetid, objUser.City, objUser.Company);    //added a new column siteid
                        Session.Abandon();
                    }
                }

                #endregion
            }

            if (FlagInsert == 1)
            {
                int FlagIncdStatesInsert;
                int incidentid;
                incidentid = objIncident.Get_Current_Incidentid();
                objIncidentStates.Incidentid    = incidentid;
                objIncidentStates.Priorityid    = Convert.ToInt32(drpPriority.SelectedValue);
                objIncidentStates.Categoryid    = Convert.ToInt32(drpCategory.SelectedValue);
                objIncidentStates.Statusid      = Convert.ToInt32(drpStatus.SelectedValue);
                objIncidentStates.Subcategoryid = Convert.ToInt32(drpSubcategory.SelectedValue);
                objIncidentStates.Technicianid  = 0;

                objIncidentStates.Requesttypeid = Convert.ToInt32(drpRequestType.SelectedValue);
                FlagIncdStatesInsert            = objIncidentStates.Insert();
                if (FlagIncdStatesInsert == 1)
                {
                    objIncidentHistory.Incidentid       = incidentid;
                    objIncidentHistory.Operation        = "create";
                    objIncidentHistory.Operationownerid = createdbyid;
                    objIncidentHistory.Insert();
                    objSentmailtoUser.SentmailUser(requesterid, incidentid, "open");
                    // change code/////////////////////////////////////////////////////////////////
                    if (FileUpload1.HasFile)
                    {
                        string   filepath    = Server.MapPath("~/FileAttach/");
                        string[] filenameupd = FileUpload1.FileName.Split(new char[] { '.' });
                        string   filenew     = Convert.ToString(incidentid) + "." + filenameupd[1];
                        FileUpload1.PostedFile.SaveAs(filepath + filenew);
                    }
                    ///////////////////////////////////////////////////////////////////////////////
                    ////////change code on 27 march///
                    #region Map Site to user
                    //FlagInsert=0;
                    int FlagDelete = 0;
                    int FlagStatus = 0;
                    //string Username;
                    //string gvIDs;
                    int organizationId;
                    //string gv;
                    // Get object of Organization to get organization id and assign to local variable organizationId
                    objOrganization = objOrganization.Get_Organization();
                    organizationId  = objOrganization.Orgid;
                    // Get username from textbox and assign to local variable Username
                    //Username = txtUserName.Text.ToString().Trim();
                    // Find User Exist ,by calling function Get_UserLogin_By_UserName()
                    //objUser = objUser.Get_UserLogin_By_UserName(Username, organizationId);
                    // If Userid is not zero ,then user exist in database
                    if (objUser.Userid != 0)
                    {
                        //'Navigate through each row in the GridView for checkbox items
                        //foreach (GridViewRow gv in grdvwSite.Rows)
                        //{
                        // Declare local variable deleteChkBxItem of Checkbox type to get the Checkbox Instance of Grid Row
                        // CheckBox deleteChkBxItem = (CheckBox)gv.FindControl("deleteRec");
                        // If deleteChkBxItem is Checked then ,mapped Current site to this user
                        //if (deleteChkBxItem.Checked)
                        //{
                        // Get the Site Id from variable of Label type declare in GridView of grdvwSite
                        //gvIDs = ((Label)gv.FindControl("SiteID")).Text.ToString();
                        // Check if gvIDs is not null
                        // if (gvIDs != "")
                        //{
                        // Declare local variable userid and siteid to get userid and SiteId
                        int userid;

                        userid = Convert.ToInt32(objUser.Userid);
                        //siteid = Convert.ToInt32(gvIDs);
                        // To Find Current Site to this User is Mapped by Calling Function objUserToSite.Get_By_Id()
                        FlagStatus = objUserToSite.Get_By_Id(userid, siteid);
                        // If FlagStatus is  zero then site is not  mapped to this user
                        if (FlagStatus == 0)
                        {
                            objUserToSite.Siteid = siteid;
                            objUserToSite.Userid = userid;
                            // Mapped Current Site to this User by calling function objUserToSite.Insert()
                            FlagInsert = objUserToSite.Insert();
                        }
                        //}
                    }
                    // If deleteChkBxItem is Un Checked then ,Un mapped Current site to this user
                    else
                    {
                        // Get the Site Id from variable of Label type declare in GridView of grdvwSite
                        // gvIDs = ((Label)gv.FindControl("SiteID")).Text.ToString();
                        // Check if gvIDs is not null
                        //if (gvIDs != "")
                        // {
                        // Declare local variable userid and siteid to get userid and SiteId
                        int userid;

                        userid = Convert.ToInt32(objUser.Userid);
                        //siteid = Convert.ToInt32(gvIDs);
                        // To Find Current Site to this User is Mapped by Calling Function objUserToSite.Get_By_Id()
                        FlagStatus = objUserToSite.Get_By_Id(userid, siteid);
                        // If FlagStatus is not  zero then site is   mapped to this user
                        if (FlagStatus != 0)
                        {
                            // Un Mapped Current Site to this User by calling function objUserToSite.Delete()
                            FlagDelete = objUserToSite.Delete(userid, siteid);
                        }
                        //}
                    }
                    //}
                    #endregion

                    /////////////end/////////////////


                    Response.Redirect("../Login/AllUserCall.aspx");
                }
            }
        }
        catch (Exception ex)
        {
            string myScript;
            myScript = "<script language=javascript>alert('Exception - '" + ex + "');</script>";
            Page.RegisterClientScriptBlock("MyScript", myScript);
            return;
        }
    }
Beispiel #3
0
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        Session["UserCreate"] = "Exist";

        #region Declaration of Local Variables
        int    siteid, priorityid;
        int    SLAid       = 0;
        int    createdbyid = 0;
        int    requesterid = 0;
        int    FlagInsert;
        int    requesttypeid;
        string userName;
        bool   FlagUserStatus;
        FlagUserStatus = true;
        FlagInsert     = 0;
        #endregion

        #region Fetch Current User
        MembershipUser User = Membership.GetUser();
        userName = User.UserName.ToString();
        #endregion
        #region Get Current Site and Priority id
        siteid     = Convert.ToInt16(drpSite.SelectedValue);
        priorityid = Convert.ToInt16(drpPriority.SelectedValue);
        #endregion


        #region Get SLAid on the basis of siteid and Priority id

        if (siteid != 0 && priorityid != 0)
        {
            SLAid         = objIncident.Get_By_SLAid(siteid, priorityid);
            requesttypeid = Convert.ToInt16(Resources.MessageResource.strRequestTypeId.ToString());
            if (requesttypeid == Convert.ToInt16(drpRequestType.SelectedValue))
            {
                SLAid = 0;
            }
        }
        #endregion
        if (userName != "")
        {
            #region Find Userid of User who Created this Request
            objOrganization = objOrganization.Get_Organization();
            objUser         = objUser.Get_UserLogin_By_UserName(userName, objOrganization.Orgid);
            if (objUser.Userid != 0)
            {
                createdbyid = objUser.Userid;
            }

            #endregion



            #region Find Userid of User who is Requesting to log a call

            #region If User Already Exist
            if (Session["UserCreate"].ToString() == "Exist")
            {
                objUser = objUser.Get_UserLogin_By_UserName(txtUsername.Text.ToString().Trim(), objOrganization.Orgid);
                if (objUser.Userid != 0)
                {
                    requesterid = objUser.Userid;
                }
            }
            #endregion



            #endregion
        }


        objIncident.Title          = txtTitle.Text.ToString().Trim();
        objIncident.Slaid          = SLAid;
        objIncident.Createdbyid    = createdbyid;
        objIncident.Requesterid    = requesterid;
        objIncident.Siteid         = siteid;
        objIncident.Description    = txtDescription.Text.ToString().Trim();
        objIncident.Deptid         = 0;
        objIncident.Createdatetime = DateTime.Now.ToString();
        objIncident.Modeid         = Convert.ToInt16(drpMode.SelectedValue);

        if (FlagUserStatus == true)
        {
            FlagInsert = objIncident.Insert();

            #region Save Assetid and incident id in incidenttoassetmaaping


            objOrganization = objOrganization.Get_Organization();
            objUser         = objUser.Get_UserLogin_By_UserName(txtUsername.Text.ToString().Trim(), objOrganization.Orgid);
            int userid    = Convert.ToInt16(objUser.Userid);
            int tempuser1 = Convert.ToInt16(Session["tempuser1"]);
            if (tempuser1 == 1)
            {
                assetid = Convert.ToInt16(Session["assetid"]);
            }
            else
            {
                assetid = Convert.ToInt16(objusertoasset.Get_AssetId_By_UserId(userid));
            }
            int incid = Convert.ToInt16(objIncident.Get_TopIncidentId());
            if (txtassignasset.Text != "")
            {
                //assetid = Convert.ToInt16(txtassignasset.Text);
                if (assetid != 0)
                {
                    objincidenttoasset.Insert(incid, assetid);
                    objusertoasset.Insert(userid, assetid);
                    Session.Abandon();
                }
            }

            #endregion
        }

        if (FlagInsert == 1)
        {
            int FlagIncdStatesInsert;
            int incidentid;
            incidentid = objIncident.Get_Current_Incidentid();
            objIncidentStates.Incidentid    = incidentid;
            objIncidentStates.Priorityid    = Convert.ToInt16(drpPriority.SelectedValue);
            objIncidentStates.Categoryid    = Convert.ToInt16(drpCategory.SelectedValue);
            objIncidentStates.Statusid      = Convert.ToInt16(drpStatus.SelectedValue);
            objIncidentStates.Subcategoryid = Convert.ToInt16(drpSubcategory.SelectedValue);
            objIncidentStates.Technicianid  = 0;

            objIncidentStates.Requesttypeid = Convert.ToInt16(drpRequestType.SelectedValue);
            FlagIncdStatesInsert            = objIncidentStates.Insert();
            if (FlagIncdStatesInsert == 1)
            {
                objIncidentHistory.Incidentid       = incidentid;
                objIncidentHistory.Operation        = "create";
                objIncidentHistory.Operationownerid = createdbyid;
                objIncidentHistory.Insert();
                objSentmailtoUser.SentmailUser(requesterid, incidentid, "open");
                // change code/////////////////////////////////////////////////////////////////


                if (FileUpload1.HasFile)
                {
                    string   filepath    = Server.MapPath("~/FileAttach/");
                    string[] filenameupd = FileUpload1.FileName.Split(new char[] { '.' });
                    string   filenew     = Convert.ToString(incidentid) + "." + filenameupd[1];
                    FileUpload1.PostedFile.SaveAs(filepath + filenew);
                }
                ///////////////////////////////////////////////////////////////////////////////
                Response.Redirect("../Login/AllUserCall.aspx");
            }
        }
    }
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        /////Add Exception handilng try catch change by vishal 21-05-2012
        try
        {
            #region Declaration of Local Variables
            int    siteid, priorityid;
            int    SLAid       = 0;
            int    createdbyid = 0;
            int    requesterid = 0;
            int    FlagInsert;
            int    requesttypeid;
            string userName;
            bool   FlagUserStatus;
            FlagUserStatus = true;
            FlagInsert     = 0;
            #endregion

            #region Fetch Current User
            MembershipUser User = Membership.GetUser();
            userName = User.UserName.ToString();
            #endregion
            #region Get Current Site and Priority id
            siteid     = Convert.ToInt32(drpSite.SelectedValue);
            priorityid = Convert.ToInt32(drpPriority.SelectedValue);
            #endregion


            #region Get SLAid on the basis of siteid and Priority id

            if (siteid != 0 && priorityid != 0)
            {
                SLAid         = objIncident.Get_By_SLAid(siteid, priorityid);
                requesttypeid = Convert.ToInt32(Resources.MessageResource.strRequestTypeId.ToString());
                if (requesttypeid == Convert.ToInt32(drpRequestType.SelectedValue))
                {
                    SLAid = 0;
                }
            }
            #endregion
            if (userName != "")
            {
                #region Find Userid of User who Created this Request
                objOrganization = objOrganization.Get_Organization();
                objUser         = objUser.Get_UserLogin_By_UserName(userName, objOrganization.Orgid);
                if (objUser.Userid != 0)
                {
                    createdbyid = objUser.Userid;
                }

                #endregion



                #region Find Userid of User who is Requesting to log a call

                #region If User Already Exist
                if (Session["UserCreate"].ToString() == "Exist")
                {
                    objUser = objUser.Get_UserLogin_By_UserName_Ex(txtUsername.Text.ToString().Trim(), objOrganization.Orgid);
                    if (objUser.Userid != 0)
                    {
                        requesterid = objUser.Userid;
                    }
                }
                #endregion
                #region If New User is to be Created
                else if (Session["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();
                    UserLogin_mst objUserLogin = new UserLogin_mst();
                    objUserLogin.Username       = txtUsername.Text.ToString();
                    objUserLogin.Password       = Resources.MessageResource.strDefaultPassword.ToString();
                    objUserLogin.Roleid         = roleid;
                    objUserLogin.Orgid          = objOrganization.Orgid;
                    objUserLogin.ADEnable       = false;
                    objUserLogin.Enable         = true;
                    objUserLogin.Createdatetime = DateTime.Now.ToString();
                    status = objUserLogin.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
                        objUserLogin = new UserLogin_mst();
                        // Fetch userid of Newly created user and assign to local variable userid by calling function objUserLogin.Get_By_UserName
                        requesterid = objUserLogin.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();
                        /// added by vishal 18-05-2012
                        Session["UserCreate"] = "";
                    }
                }
                #endregion
                #region If User is Not to be Created
                else if (Session["UserCreate"].ToString() == "notcreate")
                {
                    FlagUserStatus = false;
                }
                #endregion

                #endregion
            }

            objIncident.Title = txtTitle.Text.Trim();
            //objIncident.Title = drpTitle.SelectedItem.Text;
            // objIncident.Title = txtTitle.Text.Trim() + "-" + Txtextension.Text.Trim();
            //objIncident.Title = txtTitle.Text.Trim();
            if (Txtextension.Text != "")
            {
                string extension = Txtextension.Text;
                Int64  vOut      = Convert.ToInt64(extension);
                //int vOut = Convert.ToInt32(extension);
                objIncident.Extension = vOut;
            }
            //start changed by prachi-19thmarch
            if (drpAMCcall.SelectedItem.Text == "NO")
            {
                objIncident.AMCCall = false;
            }
            else if (drpAMCcall.SelectedItem.Text == "YES")
            {
                objIncident.AMCCall = true;
            }
            //end
            objIncident.Slaid          = SLAid;
            objIncident.Createdbyid    = createdbyid;
            objIncident.Requesterid    = requesterid;
            objIncident.Siteid         = siteid;
            objIncident.Description    = txtDescription.Text.ToString().Trim();
            objIncident.Deptid         = Convert.ToInt32(drpDepartment.SelectedValue);
            objIncident.Createdatetime = DateTime.Now.ToString();
            objIncident.Modeid         = Convert.ToInt32(drpMode.SelectedValue);
            //objIncident.ExternalTicketNo = txtExternalTicket.Text.ToString().Trim();
            if (FlagUserStatus == true)
            {
                FlagInsert = objIncident.Insert();

                #region Save Assetid and incident id in incidenttoassetmaaping

                // Get Asset and Incident Id for incidenttoassetmaaping
                objOrganization = objOrganization.Get_Organization();
                objUser         = objUser.Get_UserLogin_By_UserName_Ex(txtUsername.Text.ToString().Trim(), objOrganization.Orgid);
                int userid    = Convert.ToInt32(objUser.Userid);
                int tempuser1 = Convert.ToInt32(Session["tempuser1"]);
                if (tempuser1 == 1)
                {
                    assetid = Convert.ToInt32(Session["assetid"]);
                }
                else
                {
                    assetid = Convert.ToInt32(objusertoasset.Get_AssetId_By_UserId(userid));
                }
                int incid = Convert.ToInt32(objIncident.Get_TopIncidentId());
                if (txtassignasset.Text != "")
                {
                    //assetid = Convert.ToInt32(txtassignasset.Text);
                    if (assetid != 0)
                    {
                        objincidenttoasset.Insert(incid, assetid);
                        objusertoasset.Insert(userid, assetid, objUser.City, objUser.Company);
                        Session.Abandon();
                    }
                }

                #endregion
            }

            if (FlagInsert == 1)
            {
                int FlagIncdStatesInsert;
                int incidentid;
                incidentid = objIncident.Get_Current_Incidentid();
                objIncidentStates.Incidentid    = incidentid;
                objIncidentStates.Priorityid    = Convert.ToInt32(drpPriority.SelectedValue);
                objIncidentStates.Categoryid    = Convert.ToInt32(drpCategory.SelectedValue);
                objIncidentStates.Statusid      = Convert.ToInt32(drpStatus.SelectedValue);
                objIncidentStates.Subcategoryid = Convert.ToInt32(drpSubcategory.SelectedValue);
                objIncidentStates.Technicianid  = Convert.ToInt32(drpTechnician.SelectedValue);
                if (Convert.ToInt32(drpTechnician.SelectedValue) != 0)
                {
                    objIncidentStates.AssignedTime = DateTime.Now.ToString();
                }
                objIncidentStates.Requesttypeid = Convert.ToInt32(drpRequestType.SelectedValue);
                FlagIncdStatesInsert            = objIncidentStates.Insert();
                if (FlagIncdStatesInsert == 1)
                {
                    objIncidentHistory.Incidentid       = incidentid;
                    objIncidentHistory.Operation        = "create";
                    objIncidentHistory.Operationownerid = createdbyid;
                    objIncidentHistory.Insert();



                    objSentmailtoUser.SentmailUser(requesterid, incidentid, "open");
                    // change code/////////////////////////////////////////////////////////////////
                    if (FileUpload1.HasFile)
                    {
                        string   filepath    = Server.MapPath("~/FileAttach/");
                        string[] filenameupd = FileUpload1.FileName.Split(new char[] { '.' });
                        string   filenew     = Convert.ToString(incidentid) + "." + filenameupd[1];
                        FileUpload1.PostedFile.SaveAs(filepath + filenew);
                    }
                    ///////////////////////////////////////////////////////////////////////////////


                    if (Convert.ToInt32(drpTechnician.SelectedValue) != 0)
                    {
                        objSentmailtoUser.SentmailTechnician(Convert.ToInt32(drpTechnician.SelectedValue), incidentid);
                    }

                    Response.Redirect("~/Incident/IncidentRequestUpdate.aspx?incidentid=" + incidentid + "");
                }
            }
        }
        catch (Exception ex)
        {
            string myScript;
            myScript = "<script language=javascript>alert('Exception - '" + ex + "');</script>";
            Page.RegisterClientScriptBlock("MyScript", myScript);
            return;
        }
    }