private void btnRemove_Click(object sender, System.EventArgs e) { try { if(Request.QueryString["id"] == null) { Session["lastpage"] = "view.aspx?id=" + Session["EquipId"].ToString(); Session["error"] = _functions.ErrorMessage(104); Response.Redirect("error.aspx", false); return; } try { ComponentId = Convert.ToInt32(Request.QueryString["id"]); } catch(FormatException fex) { Session["lastpage"] = "view.aspx?id=" + Session["EquipId"].ToString(); Session["error"] = _functions.ErrorMessage(105); Response.Redirect("error.aspx", false); return; } comp = new clsComponents(); comp.iOrgId = _functions.GetUserOrgId(HttpContext.Current.User.Identity.Name, false); comp.iId = ComponentId; comp.DeleteComponent(); Response.Redirect("view.aspx?id=" + Session["EquipId"].ToString(), false); } catch(Exception ex) { _functions.Log("Application error: \n" + ex.ToString()); Session["lastpage"] = "editComponent.aspx?id=" + ComponentId.ToString(); Session["error"] = ex.Message; Session["error_report"] = ex.ToString(); Response.Redirect("error.aspx", false); } finally { if(comp != null) { comp.Dispose(); } } }
private void btSave_FormSubmit(object sender, EventArgs e) { DBFieldType FieldType; string sDataGridName; try { if(Request.QueryString["id"] == null) { Session["lastpage"] = "view.aspx?id=" + Session["EquipId"].ToString(); Session["error"] = _functions.ErrorMessage(104); Response.Redirect("error.aspx", false); return; } try { ComponentId = Convert.ToInt32(Request.QueryString["id"]); } catch(FormatException fex) { Session["lastpage"] = "view.aspx?id=" + Session["EquipId"].ToString(); Session["error"] = _functions.ErrorMessage(105); Response.Redirect("error.aspx", false); return; } comp = new clsComponents(); dtCustomFields = (DataTable)ViewState["CustomFields"]; comp.cAction="U"; comp.iOrgId = _functions.GetUserOrgId(HttpContext.Current.User.Identity.Name, false); comp.iId = ComponentId; // editing a Equipment ot adding if ComponentId is zero comp.iEquipId = Convert.ToInt32(Session["EquipId"]); comp.iUserId = _functions.GetUserOrgId(HttpContext.Current.User.Identity.Name, true); comp.iTypeId = Convert.ToInt32(ViewState["ComponentTypeId"]); if(ddlStatus.SelectedValue == "1") comp.bitActive = SqlBoolean.True; else comp.bitActive = SqlBoolean.False; sDataGridName = "repCustomFields"; // getting data from Form and changing the dtCustomFields datatable for(int i=0; i<dtCustomFields.Rows.Count; i++) { for(int j=0; j<Request.Form.Count; j++) { if((string)dtCustomFields.Rows[i]["TypeName"] == Request.Form[sDataGridName + ":_ctl" + j.ToString() + ":inputTypeName"]) { FieldType = _functions.TypeNameParser((string)dtCustomFields.Rows[i]["TypeName"]); // nvarchar1...n, ... switch(FieldType) { case DBFieldType._nvarchar: dtCustomFields.Rows[i]["Value_String"] = Request.Form[sDataGridName + ":_ctl" + j.ToString() + ":tbValue"]; break; case DBFieldType._int: dtCustomFields.Rows[i]["Value_String"] = Request.Form[sDataGridName + ":_ctl" + j.ToString() + ":tbValue"]; break; case DBFieldType._float: dtCustomFields.Rows[i]["Value_String"] = Request.Form[sDataGridName + ":_ctl" + j.ToString() + ":tbValue"]; break; case DBFieldType._datetime: dtCustomFields.Rows[i]["Value_String"] = new SqlDateTime(Convert.ToInt32(Request.Form[sDataGridName + ":_ctl" + j.ToString() + ":adtValue_year"]), Convert.ToInt32(Request.Form[sDataGridName + ":_ctl" + j.ToString() + ":adtValue_month"]), Convert.ToInt32(Request.Form[sDataGridName + ":_ctl" + j.ToString() + ":adtValue_day"])); break; case DBFieldType._bit: if(Request.Form[sDataGridName + ":_ctl" + j.ToString() + ":chValue"] == "ON") { dtCustomFields.Rows[i]["Value_String"] = "True"; } else { dtCustomFields.Rows[i]["Value_String"] = "False"; } break; case DBFieldType._ntext: dtCustomFields.Rows[i]["Value_String"] = Request.Form[sDataGridName + ":_ctl" + j.ToString() + ":tbValue"]; break; case DBFieldType._sql_variant: dtCustomFields.Rows[i]["Value_String"] = Request.Form[sDataGridName + ":_ctl" + j.ToString() + ":tbValue"]; break; case DBFieldType._lookup: if((string)dtCustomFields.Rows[i]["ValueName"] != "Make/Model") { dtCustomFields.Rows[i]["Value_String"] = Request.Form[sDataGridName + ":_ctl" + j.ToString() + ":ddlValue"]; } else { dtCustomFields.Rows[i]["Value_String"] = Request.Form[sDataGridName + ":_ctl" + j.ToString() + ":mmValue:ddlModels"]; } break; default: dtCustomFields.Rows[i]["Value_String"] = Request.Form[sDataGridName + ":_ctl" + j.ToString() + ":tbValue"]; break; } } } } // saving data to database comp.ComponentDetail_CustomFields(_functions.SetDataToParameters(dtCustomFields)); if(comp.iId >= 0) { Response.Redirect("view.aspx?id=" + Session["EquipId"].ToString(), false); } else { Session["lastpage"] = "editComponent.aspx?id=" + ComponentId.ToString(); Session["error"] = _functions.ErrorMessage(110); Response.Redirect("error.aspx", false); } } catch(FormatException fex) { Session["lastpage"] = "editComponent.aspx?id=" + ComponentId.ToString(); Session["error"] = _functions.ErrorMessage(108); Response.Redirect("error.aspx", false); } catch(Exception ex) { _functions.Log("Application error: \n" + ex.ToString()); Session["lastpage"] = "editComponent.aspx?id=" + ComponentId.ToString(); Session["error"] = ex.Message; Session["error_report"] = ex.ToString(); Response.Redirect("error.aspx", false); } finally { if(comp!=null) { comp.Dispose(); } } }
/// <summary> /// Removing current component from equipment /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnRemove_Click(object sender, System.EventArgs e) { try { comp = new clsComponents(); comp.iOrgId = OrgId; comp.iId = ComponentId; comp.DeleteComponent(); Response.Redirect("e_view.aspx?id=" + Session["EquipId"].ToString(), false); } catch(Exception ex) { _functions.Log(ex, HttpContext.Current.User.Identity.Name, SourcePageName); Session["lastpage"] = "e_editComponent.aspx?id=" + ComponentId.ToString(); Session["error"] = ex.Message; Session["error_report"] = ex.ToString(); Response.Redirect("error.aspx", false); } finally { if(comp != null) { comp.Dispose(); } } }