protected void grdvwViewAsset_RowCommand(object sender, GridViewCommandEventArgs e) { ///Add Exception handilng try catch change by vishal 21-05-2012 try { if (e.CommandName == "ViewDetails") { int temp = 0; string strassecompany = e.CommandArgument.ToString(); string[] splitchar = strassecompany.Split(new char[] { ',' }); int Assetid = Convert.ToInt32(splitchar[0].ToString()); string compname = splitchar[1].ToString(); Session["Assetid"] = Assetid.ToString(); Session["temp"] = temp; Response.Redirect("~/Asset/ViewAssetDetails.aspx?" + compname + ""); } if (e.CommandName.Equals("AlphaPaging")) { string commandname = e.CommandArgument.ToString(); ViewState["commandname"] = e.CommandArgument.ToString(); col = ObjAsset.Get_By_comandname(commandname); if (col.Count != 0) { grdvwViewAsset.DataSource = col; grdvwViewAsset.DataBind(); } else { DataTable dt = new DataTable(); dt.Columns.Add("assetid"); dt.Columns.Add("computername"); dt.Columns.Add("domain"); DataRow dr = dt.NewRow(); dt.Rows.Add(dr); grdvwViewAsset.DataSource = dt; grdvwViewAsset.DataBind(); //grdvwViewAsset.Rows[0].Cells[3].Visible = false; //grdvwViewAsset.Rows[0].Cells[5].Visible = false; } } //////////add by vishal 02-06-2012 if (e.CommandName == "Del") { string asset = e.CommandArgument.ToString(); int assetid = Convert.ToInt32(asset); ObjAsset.Assetid = assetid; ObjAsset.UpdateDeleteFlag_Asset_id(); string myScript; myScript = "<script language=javascript>alert('Record deleted successfully !');</script>"; Page.RegisterClientScriptBlock("MyScript", myScript); // Refresh the data grdvwViewAsset.EditIndex = -1; BindGrid1(); } ////////end 02-06-2012 } catch (Exception ex) { string myScript; myScript = "<script language=javascript>alert('Exception - '" + ex + "');</script>"; Page.RegisterClientScriptBlock("MyScript", myScript); return; } }
protected void btnDelete_Click(object sender, EventArgs e) { try { string compname; compname = drpCmpList.SelectedItem.ToString(); if (compname != null && compname != "") { lbl_status.Text = compname; string path = "C:\\Asset\\Data\\" + compname + ".xml"; FileInfo fi = new FileInfo(path); if (fi.Exists) { fi.Delete(); /////////////////////////////////////////////////////////////////////////////change done by meenakshi string sQuery = ("select assetId from Asset_mst where computerName='" + compname + "'"); 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(); if (dr.HasRows) { dr.Read(); ObjAsset.Assetid = Convert.ToInt32(dr["assetId"].ToString()); } dr.Close(); sc.Close(); ObjAsset.UpdateDeleteFlag_Asset_id(); //////////////////////////////////////////////////////////////////////////////end //lbl_status.Text = "Inventory removed..."; string myScript; myScript = "<script language=javascript>alert('Inventory removed successfully....');</script>"; Page.RegisterClientScriptBlock("MyScript", myScript); filenames = Get_Data_Files(); Write_Computer_List(filenames); string xmlfilePath; DataSet ds = new DataSet(); xmlfilePath = Server.MapPath("~/files/Asset.xml"); ds.ReadXml(xmlfilePath); drpCmpList.DataSource = ds; drpCmpList.DataTextField = ds.Tables[0].Columns[0].ToString(); drpCmpList.DataValueField = ds.Tables[0].Columns[0].ToString(); drpCmpList.DataBind(); } else { //lbl_status.Text = "Computer not found.."; string myScript; myScript = "<script language=javascript>alert('Computer not found.'); </script>"; Page.RegisterClientScriptBlock("MyScript", myScript); } } } catch (Exception ex) { string myScript; myScript = "<script language=javascript>alert('Record Not Found'); </script>"; Page.RegisterClientScriptBlock("MyScript", myScript); } }