protected void btnMapped_Click(object sender, EventArgs e) { //lblErrorMsg.Text = ""; int flag = 0; int tempuser; tempuser = Convert.ToInt16(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.ToInt16(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); if (assetcount == 0) { if (usercount == 0) { int flag1 = 1; objusertoasset.Insert(userid, assetid); //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.ToInt16(Session["assignassetid"]); objusertoasset.Update_Assetid(oldassetid, assetid); 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); }
//protected void btngetuser_Click(object sender, EventArgs e) //{ // lblErrorMsg.Text = ""; // string Username = txtusername.Text.ToString().Trim(); // objUser = objUser.Get_UserLogin_By_UserName_Like(Username); // if (objUser.Userid != 0) // { // txtusername.Text = objUser.Username.ToString().Trim(); // userid = objUser.Userid; // } // else // { // txtusername.Text = ""; // } //} //protected void btnshow_Click(object sender, EventArgs e) //{ // lblErrorMsg.Text = ""; // string Username = txtusername.Text.ToString().Trim(); // objUser = objUser.Get_UserLogin_By_UserName_Like(Username); // userid = objUser.Userid; // int assid=Convert.ToInt32(objusertoasset.Get_AssetId_By_UserId(userid)); // int usercount = objusertoasset.Get_UserId_From_UserToAssetMap(userid); // col = ObjAsset.Get_Assetdetails_By_Assetid(assid); // grdvwViewAsset.DataSource = col; // grdvwViewAsset.DataBind(); // foreach (GridViewRow gv in grdvwViewAsset.Rows) // { // RadioButton selectonebutton = (RadioButton)gv.FindControl("selectone"); // selectonebutton.Checked = true; // } //} 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; 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 = txtusername.Text.ToString().Trim(); objUser = objUser.Get_UserLogin_By_UserName_Like(Username); //objcontactinfo = objcontactinfo.Get_By_id(objUser.Userid); //added by lalit 24 feb 2012 userid = objUser.Userid; if (txtusername.Text == "") { lblErrorMsg.Text = "Enter the user name for mapped a particular Asset"; break; } else if (userid == 0) { lblErrorMsg.Text = "User Name doesn't exist"; break; } else { assetcount = objusertoasset.Get_AssetId_From_UserToAssetMap(assetid); usercount = objusertoasset.Get_UserId_From_UserToAssetMap(userid); assetlocation = objUser.City; //added by lalit 24 feb 2012 companyname = objUser.Company; if (assetcount == 0) { if (usercount == 0) { objusertoasset.Insert(userid, assetid, assetlocation, companyname); //added a new field siteid on 24 feb. lblErrorMsg.Text = "Asset Mapped Successfully to the Current User"; break; } else { int oldassetid = Convert.ToInt32(objusertoasset.Get_AssetId_By_UserId(userid)); objusertoasset.Update_Assetid(oldassetid, assetid, assetlocation, companyname); lblErrorMsg.Text = "Asset Mapped Successfully to the Current User"; break; } } else { lblErrorMsg.Text = "Asset already Mapped"; break; } } } } if (flag == 0) { lblErrorMsg.Text = "Select Asset for mapping"; } } catch (Exception ex) { string myScript; myScript = "<script language=javascript>alert('Exception - '" + ex + "');</script>"; Page.RegisterClientScriptBlock("MyScript", myScript); return; } }
//protected void btngetuser_Click(object sender, EventArgs e) //{ // lblErrorMsg.Text = ""; // string Username = txtusername.Text.ToString().Trim(); // objUser = objUser.Get_UserLogin_By_UserName_Like(Username); // if (objUser.Userid != 0) // { // txtusername.Text = objUser.Username.ToString().Trim(); // userid = objUser.Userid; // } // else // { // txtusername.Text = ""; // } //} //protected void btnshow_Click(object sender, EventArgs e) //{ // lblErrorMsg.Text = ""; // string Username = txtusername.Text.ToString().Trim(); // objUser = objUser.Get_UserLogin_By_UserName_Like(Username); // userid = objUser.Userid; // int assid=Convert.ToInt16(objusertoasset.Get_AssetId_By_UserId(userid)); // int usercount = objusertoasset.Get_UserId_From_UserToAssetMap(userid); // col = ObjAsset.Get_Assetdetails_By_Assetid(assid); // grdvwViewAsset.DataSource = col; // grdvwViewAsset.DataBind(); // foreach (GridViewRow gv in grdvwViewAsset.Rows) // { // RadioButton selectonebutton = (RadioButton)gv.FindControl("selectone"); // selectonebutton.Checked = true; // } //} protected void btnMapped_Click(object sender, EventArgs e) { lblErrorMsg.Text = ""; 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.ToInt16(gvIDs); string Username = txtusername.Text.ToString().Trim(); objUser = objUser.Get_UserLogin_By_UserName_Like(Username); userid = objUser.Userid; if (txtusername.Text == "") { lblErrorMsg.Text = "Enter the user name for mapped a particular Asset"; break; } else if (userid == 0) { lblErrorMsg.Text = "User Name doesn't exist"; break; } else { assetcount = objusertoasset.Get_AssetId_From_UserToAssetMap(assetid); usercount = objusertoasset.Get_UserId_From_UserToAssetMap(userid); if (assetcount == 0) { if (usercount == 0) { objusertoasset.Insert(userid, assetid); lblErrorMsg.Text = "Asset Mapped Successfully to the Current User"; break; } else { int oldassetid = Convert.ToInt16(objusertoasset.Get_AssetId_By_UserId(userid)); objusertoasset.Update_Assetid(oldassetid, assetid); lblErrorMsg.Text = "Asset Mapped Successfully to the Current User"; break; } } else { lblErrorMsg.Text = "Asset already Mapped"; break; } } } } if (flag == 0) { lblErrorMsg.Text = "Select Asset for mapping"; } }