コード例 #1
0
    //////////////////////////////////////////////////////////////////meenakshi
    //protected void btnMapped_Click(object sender, EventArgs e)
    //{/////Add Exception handilng try catch change by vishal 21-05-2012
    //    try
    //    {
    //        //lblErrorMsg.Text = "";
    //        int flag = 0;
    //        int tempuser;
    //        tempuser = Convert.ToInt32(Session["tempuser"]);

    //        foreach (GridViewRow gv in grdvwViewAsset.Rows)
    //        {
    //            string gvIDs;
    //            RadioButton selectonebutton = (RadioButton)gv.FindControl("selectone");
    //            if (selectonebutton.Checked)
    //            {
    //                flag = 1;
    //                int assetid;
    //                gvIDs = ((Label)gv.FindControl("lblAssetID")).Text.ToString();
    //                assetid = Convert.ToInt32(gvIDs);
    //                string Username = lblusername.Text.ToString().Trim();
    //                objUser = objUser.Get_UserLogin_By_UserName_Like(Username);
    //                userid = objUser.Userid;
    //                if (lblusername.Text == "")
    //                {

    //                    //lblErrorMsg.Text = "Enter the user name for mapped a particular Asset";
    //                    break;
    //                }

    //                else if (tempuser == 1)
    //                {
    //                    assetcount = objusertoasset.Get_AssetId_From_UserToAssetMap(assetid);
    //                    int tempuser1 = 0;
    //                    if (assetcount == 0)
    //                    {
    //                        int flag1 = 1;
    //                        ObjAsset = ObjAsset.Get_By_id(assetid);
    //                        string compname = ObjAsset.Computername.ToString();
    //                        string username = lblusername.Text.ToString();
    //                        Session["compname"] = compname;
    //                        Session["flag"] = flag1;
    //                        Session["username"] = username;
    //                        Session["assetid"] = assetid;
    //                        Session["userid"] = userid;
    //                        tempuser1 = 1;
    //                        Session["tempuser1"] = tempuser1;
    //                        Session["flag1"] = flag1;
    //                        break;
    //                    }
    //                    else
    //                    {
    //                        //lblErrorMsg.Text = "Asset already mapped";
    //                        break;
    //                    }
    //                }
    //                else if (userid == 0)
    //                {
    //                    //lblErrorMsg.Text = "User Name doen not exist";
    //                    break;
    //                }
    //                else
    //                {
    //                    assetcount = objusertoasset.Get_AssetId_From_UserToAssetMap(assetid);
    //                    usercount = objusertoasset.Get_UserId_From_UserToAssetMap(userid);
    //                    //  objcontactinfo = objcontactinfo.Get_By_id(userid);
    //                    objUser = objUser.Get_By_id(userid);
    //                    if (assetcount == 0)
    //                    {
    //                        if (usercount == 0)
    //                        {
    //                            int flag1 = 1;
    //                            objusertoasset.Insert(userid, assetid, objUser.City, objUser.Company);
    //                            //lblErrorMsg.Text = "Mapped Succussfully";
    //                            ObjAsset = ObjAsset.Get_By_id(assetid);
    //                            string compname = ObjAsset.Computername.ToString();
    //                            string username = lblusername.Text.ToString();
    //                            Session["compname"] = compname;
    //                            Session["flag"] = flag1;
    //                            Session["username"] = username;
    //                            Session["assetid"] = assetid;
    //                            Session["userid"] = userid;
    //                            Session["flag1"] = flag1;
    //                            break;

    //                        }
    //                        else  //Update Asset id from UserToAsset table.
    //                        {
    //                            int flag1 = 1;
    //                            int oldassetid = Convert.ToInt32(Session["assignassetid"]);
    //                            objusertoasset.Update_Assetid(oldassetid, assetid, objUser.City, objUser.Company);
    //                            ObjAsset = ObjAsset.Get_By_id(assetid);
    //                            string compname = ObjAsset.Computername.ToString();
    //                            string username = lblusername.Text.ToString();
    //                            Session["compname"] = compname;
    //                            Session["flag"] = flag1;
    //                            Session["username"] = username;
    //                            Session["assetid"] = assetid;
    //                            Session["userid"] = userid;
    //                            Session["flag1"] = flag1;
    //                            break;
    //                        }
    //                    }
    //                    else
    //                    {
    //                        //lblErrorMsg.Text = "Asset already mapped";
    //                        break;
    //                    }
    //                }
    //            }

    //        }
    //        if (flag == 0)
    //        {
    //            //lblErrorMsg.Text = "Select Asset for mapping";
    //        }

    //        string myScript;
    //        myScript = "<script language=javascript>javascript:refreshParent(); javascript:window.close();</script>";
    //        Page.RegisterClientScriptBlock("MyScript", myScript);
    //    }
    //    catch (Exception ex)

    //        string myScript;
    //        myScript = "<script language=javascript>alert('Exception - '" + ex + "');</script>";
    //        Page.RegisterClientScriptBlock("MyScript", myScript);
    //        return;
    //    }
    // }



    protected void btnSelect_Click(object sender, EventArgs e)
    {
        try
        {
            int flag = 0;
            foreach (GridViewRow gv in grdvwViewAsset.Rows)
            {
                string      gvIDs;
                RadioButton selectonebutton = (RadioButton)gv.FindControl("selectone");
                if (selectonebutton.Checked)
                {
                    flag = 1;
                    int assetid;
                    gvIDs            = ((Label)gv.FindControl("lblAssetID")).Text.ToString();
                    assetid          = Convert.ToInt32(gvIDs);
                    Session["assId"] = assetid;
                    int incidentid = Convert.ToInt32(Session["incidentid"]);

                    colin = objintoass.Get_All();
                    //objintoass.incidentid=Convert.ToInt32(objintoass.Get_incidentId_From_incidentToAssetMap(incidentid));
                    int Count = Convert.ToInt32(objintoass.Get_incidentId_From_incidentToAssetMap(incidentid));
                    IncidentToAssetMapping objincass = new IncidentToAssetMapping();
                    if (incidentid != 0 && assetid != 0)
                    {
                        for (int i = 0; i < Count; i++)
                        {
                            string        sQuery = ("update IncidentToAssetMapping set assetid='" + assetid + "' where incidentid='" + incidentid + "'");
                            string        constr = System.Configuration.ConfigurationManager.ConnectionStrings["CSM_DB"].ToString();
                            SqlConnection sc     = new SqlConnection(constr);
                            sc.Open();
                            SqlCommand    cmd = new SqlCommand(sQuery, sc);
                            SqlDataReader dr  = cmd.ExecuteReader();
                            dr.Read();
                            //ObjAsset = ObjAsset.Get_By_id(assetid);
                            //string compname = ObjAsset.Computername.ToString();
                            //Session["compname"] = compname;
                            //Session["flag"] = flag;
                        }

                        if (Count == 0)
                        {
                            objincass.Insert(incidentid, assetid);
                            //ObjAsset = ObjAsset.Get_By_id(assetid);
                            //string compname = ObjAsset.Computername.ToString();
                            //Session["compname"] = compname;
                            //Session["flag"] = flag;
                            break;
                        }
                    }
                    ObjAsset = ObjAsset.Get_By_id(assetid);
                    string compname = ObjAsset.Computername.ToString();
                    Session["compname"] = compname;
                    Session["flag"]     = flag;
                }
            }
            string myScript;
            myScript = "<script language=javascript>javascript:refreshParent(); javascript:window.close();</script>";
            Page.RegisterClientScriptBlock("MyScript", myScript);
        }
        catch (Exception ex)
        {
            string myScript;
            myScript = "<script language=javascript>alert('Exception - '" + ex + "');</script>";
            Page.RegisterClientScriptBlock("MyScript", myScript);
            return;
        }
    }
 public int Update_IncidentToAssetMapping_By_id(IncidentToAssetMapping objIncidentToAssetMapping)
 {
     return (int)ExecuteNonQuery(Sp_IncidentToAssetMapping_Update, new object[] { objIncidentToAssetMapping.incidentid, objIncidentToAssetMapping.Assetid });
 }
    public CollectionBase GenerateIncidentToAssetMapping_mstCollection(ref IDataReader returnData)
    {
        BLLCollection<IncidentToAssetMapping> col = new BLLCollection<IncidentToAssetMapping>();
        while (returnData.Read())
        {
            IncidentToAssetMapping obj = new IncidentToAssetMapping();

            obj.Assetid = (int)returnData["assetid"];
            obj.incidentid = (int)returnData["incidentid"];
            col.Add(obj);
        }
        returnData.Close();
        returnData.Dispose();
        return col;
    }
    public object GenerateIncidentToAssetMapping_mstObject(ref IDataReader returnData)
    {
        IncidentToAssetMapping obj = new IncidentToAssetMapping();
        while (returnData.Read())
        {
            obj.Assetid = (int)returnData["assetid"];
            obj.incidentid = (int)returnData["incidentid"];

        }
        returnData.Close();
        returnData.Dispose();
        return obj;
    }
    //////////////////////////////////////////////////////////////////meenakshi
    //protected void btnMapped_Click(object sender, EventArgs e)
    //{/////Add Exception handilng try catch change by vishal 21-05-2012
    //    try
    //    {
    //        //lblErrorMsg.Text = "";
    //        int flag = 0;
    //        int tempuser;
    //        tempuser = Convert.ToInt32(Session["tempuser"]);
    //        foreach (GridViewRow gv in grdvwViewAsset.Rows)
    //        {
    //            string gvIDs;
    //            RadioButton selectonebutton = (RadioButton)gv.FindControl("selectone");
    //            if (selectonebutton.Checked)
    //            {
    //                flag = 1;
    //                int assetid;
    //                gvIDs = ((Label)gv.FindControl("lblAssetID")).Text.ToString();
    //                assetid = Convert.ToInt32(gvIDs);
    //                string Username = lblusername.Text.ToString().Trim();
    //                objUser = objUser.Get_UserLogin_By_UserName_Like(Username);
    //                userid = objUser.Userid;
    //                if (lblusername.Text == "")
    //                {
    //                    //lblErrorMsg.Text = "Enter the user name for mapped a particular Asset";
    //                    break;
    //                }
    //                else if (tempuser == 1)
    //                {
    //                    assetcount = objusertoasset.Get_AssetId_From_UserToAssetMap(assetid);
    //                    int tempuser1 = 0;
    //                    if (assetcount == 0)
    //                    {
    //                        int flag1 = 1;
    //                        ObjAsset = ObjAsset.Get_By_id(assetid);
    //                        string compname = ObjAsset.Computername.ToString();
    //                        string username = lblusername.Text.ToString();
    //                        Session["compname"] = compname;
    //                        Session["flag"] = flag1;
    //                        Session["username"] = username;
    //                        Session["assetid"] = assetid;
    //                        Session["userid"] = userid;
    //                        tempuser1 = 1;
    //                        Session["tempuser1"] = tempuser1;
    //                        Session["flag1"] = flag1;
    //                        break;
    //                    }
    //                    else
    //                    {
    //                        //lblErrorMsg.Text = "Asset already mapped";
    //                        break;
    //                    }
    //                }
    //                else if (userid == 0)
    //                {
    //                    //lblErrorMsg.Text = "User Name doen not exist";
    //                    break;
    //                }
    //                else
    //                {
    //                    assetcount = objusertoasset.Get_AssetId_From_UserToAssetMap(assetid);
    //                    usercount = objusertoasset.Get_UserId_From_UserToAssetMap(userid);
    //                    //  objcontactinfo = objcontactinfo.Get_By_id(userid);
    //                    objUser = objUser.Get_By_id(userid);
    //                    if (assetcount == 0)
    //                    {
    //                        if (usercount == 0)
    //                        {
    //                            int flag1 = 1;
    //                            objusertoasset.Insert(userid, assetid, objUser.City, objUser.Company);
    //                            //lblErrorMsg.Text = "Mapped Succussfully";
    //                            ObjAsset = ObjAsset.Get_By_id(assetid);
    //                            string compname = ObjAsset.Computername.ToString();
    //                            string username = lblusername.Text.ToString();
    //                            Session["compname"] = compname;
    //                            Session["flag"] = flag1;
    //                            Session["username"] = username;
    //                            Session["assetid"] = assetid;
    //                            Session["userid"] = userid;
    //                            Session["flag1"] = flag1;
    //                            break;
    //                        }
    //                        else  //Update Asset id from UserToAsset table.
    //                        {
    //                            int flag1 = 1;
    //                            int oldassetid = Convert.ToInt32(Session["assignassetid"]);
    //                            objusertoasset.Update_Assetid(oldassetid, assetid, objUser.City, objUser.Company);
    //                            ObjAsset = ObjAsset.Get_By_id(assetid);
    //                            string compname = ObjAsset.Computername.ToString();
    //                            string username = lblusername.Text.ToString();
    //                            Session["compname"] = compname;
    //                            Session["flag"] = flag1;
    //                            Session["username"] = username;
    //                            Session["assetid"] = assetid;
    //                            Session["userid"] = userid;
    //                            Session["flag1"] = flag1;
    //                            break;
    //                        }
    //                    }
    //                    else
    //                    {
    //                        //lblErrorMsg.Text = "Asset already mapped";
    //                        break;
    //                    }
    //                }
    //            }
    //        }
    //        if (flag == 0)
    //        {
    //            //lblErrorMsg.Text = "Select Asset for mapping";
    //        }
    //        string myScript;
    //        myScript = "<script language=javascript>javascript:refreshParent(); javascript:window.close();</script>";
    //        Page.RegisterClientScriptBlock("MyScript", myScript);
    //    }
    //    catch (Exception ex)
    //        string myScript;
    //        myScript = "<script language=javascript>alert('Exception - '" + ex + "');</script>";
    //        Page.RegisterClientScriptBlock("MyScript", myScript);
    //        return;
    //    }
    // }
    protected void btnSelect_Click(object sender, EventArgs e)
    {
        try
        {
            int flag = 0;
            foreach (GridViewRow gv in grdvwViewAsset.Rows)
            {
                string gvIDs;
                RadioButton selectonebutton = (RadioButton)gv.FindControl("selectone");
                if (selectonebutton.Checked)
                {
                    flag = 1;
                    int assetid;
                    gvIDs = ((Label)gv.FindControl("lblAssetID")).Text.ToString();
                    assetid = Convert.ToInt32(gvIDs);
                    Session["assId"] = assetid;
                    int incidentid = Convert.ToInt32(Session["incidentid"]);

                    colin = objintoass.Get_All();
                    //objintoass.incidentid=Convert.ToInt32(objintoass.Get_incidentId_From_incidentToAssetMap(incidentid));
                    int Count = Convert.ToInt32(objintoass.Get_incidentId_From_incidentToAssetMap(incidentid));
                    IncidentToAssetMapping objincass = new IncidentToAssetMapping();
                    if (incidentid != 0 && assetid != 0)
                    {
                        for (int i = 0; i < Count; i++)
                        {
                            string sQuery = ("update IncidentToAssetMapping set assetid='" + assetid + "' where incidentid='" + incidentid + "'");
                            string constr = System.Configuration.ConfigurationManager.ConnectionStrings["CSM_DB"].ToString();
                            SqlConnection sc = new SqlConnection(constr);
                            sc.Open();
                            SqlCommand cmd = new SqlCommand(sQuery, sc);
                            SqlDataReader dr = cmd.ExecuteReader();
                            dr.Read();
                            //ObjAsset = ObjAsset.Get_By_id(assetid);
                            //string compname = ObjAsset.Computername.ToString();
                            //Session["compname"] = compname;
                            //Session["flag"] = flag;
                        }

                        if (Count == 0)
                        {
                            objincass.Insert(incidentid, assetid);
                            //ObjAsset = ObjAsset.Get_By_id(assetid);
                            //string compname = ObjAsset.Computername.ToString();
                            //Session["compname"] = compname;
                            //Session["flag"] = flag;
                            break;
                        }

                    }
                    ObjAsset = ObjAsset.Get_By_id(assetid);
                    string compname = ObjAsset.Computername.ToString();
                    Session["compname"] = compname;
                    Session["flag"] = flag;
                }
            }
                string myScript;
                myScript = "<script language=javascript>javascript:refreshParent(); javascript:window.close();</script>";
                Page.RegisterClientScriptBlock("MyScript", myScript);

        }
        catch (Exception ex)
        {
            string myScript;
            myScript = "<script language=javascript>alert('Exception - '" + ex + "');</script>";
            Page.RegisterClientScriptBlock("MyScript", myScript);
            return;
        }
    }