コード例 #1
0
        /// <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();
                }
            }
        }
コード例 #2
0
        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(ex, HttpContext.Current.User.Identity.Name, SourcePageName);
                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();
                }
            }
        }
コード例 #3
0
        private void Page_Load(object sender, System.EventArgs e)
        {
            int    j;
            string sTypeName;
            object oItem;

            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;
                }

                string [,] arrBrdCrumbs = new string [3, 2];
                arrBrdCrumbs[0, 0]      = "main.aspx";
                arrBrdCrumbs[0, 1]      = "Home";
                arrBrdCrumbs[1, 0]      = "list.aspx";
                arrBrdCrumbs[1, 1]      = "Equipment List";
                if (Session["EquipId"] != null)
                {
                    arrBrdCrumbs[2, 0] = "view.aspx?id=" + Session["EquipId"].ToString();
                }
                else
                {
                    arrBrdCrumbs[2, 0] = ParentPageURL;
                }
                arrBrdCrumbs[2, 1] = "Equipment Detail";
                PageTitle          = "Equipment-Edit Component";
                Header.BrdCrumbs   = ParseBreadCrumbs(arrBrdCrumbs, PageTitle);
                Header.PageTitle   = PageTitle;

                SaveCancelControl.ParentPageURL = ParentPageURL;

                SourcePageName = "editComponent.aspx.cs";

                if (!IsPostBack)
                {
                    comp = new clsComponents();

                    dtCustomFields = new DataTable();
                    dtCustomFields.Columns.Add("TypeName");
                    dtCustomFields.Columns.Add("ValueName");
                    dtCustomFields.Columns.Add("Value_String");
                    dtCustomFields.Columns.Add("Value_Boolean");
                    dtCustomFields.Columns.Add("Value_Int");
                    dtCustomFields.Columns.Add("Value_DateTime");
                    dtCustomFields.Columns.Add("TB_Visible");
                    dtCustomFields.Columns.Add("DDL_Visible");
                    dtCustomFields.Columns.Add("CB_Visible");
                    dtCustomFields.Columns.Add("MM_Visible");
                    dtCustomFields.Columns.Add("DT_Visible");
                    dtCustomFields.Columns.Add("Help");
                    dtCustomFields.Columns.Add("Val_Visible");
                    dtCustomFields.Columns.Add("ErrorMessage");
                    dtCustomFields.Columns.Add("Exp");

                    if (ComponentId == 0)
                    {                     // adding a component
                        lblLastUpdate.Text           = "";
                        ddlStatus.SelectedValue      = "1";
                        ViewState["ComponentTypeId"] = Convert.ToInt32(Request.QueryString["typeid"]);
                        btnRemove.Visible            = false;
                    }
                    else
                    {                     // editing a component
                        comp.iOrgId          = _functions.GetUserOrgId(HttpContext.Current.User.Identity.Name, false);
                        comp.iId             = ComponentId;
                        comp.cAction         = "S";
                        btnRemove.Visible    = true;
                        dtCustomFieldsFromDB = comp.ComponentDetail_CustomFields(null);

                        lblLastUpdate.Text = dtCustomFieldsFromDB.Rows[0]["UserName"].ToString() + " " + Convert.ToDateTime(dtCustomFieldsFromDB.Rows[0]["dtUpdated"]).ToString();
                        if ((bool)dtCustomFieldsFromDB.Rows[0]["btActive"])
                        {
                            ddlStatus.SelectedValue = "1";
                        }
                        else
                        {
                            ddlStatus.SelectedValue = "0";
                        }

                        ViewState["ComponentTypeId"] = Convert.ToInt32(dtCustomFieldsFromDB.Rows[0]["TypeId"]);
                    }
                    arrCFD = _functions.GetCustomFields(CFDataType.Component, (int)ViewState["ComponentTypeId"], HttpContext.Current.User.Identity.Name);
                    if (arrCFD.Count > 0)
                    {
                        // filling custom fields in the dtCustomFields table
                        for (j = 0; j < arrCFD.Count; j++)
                        {
                            cfd       = (clsCustomFieldsDef)arrCFD[j];
                            sTypeName = _functions.GetFieldTypeText(cfd.FieldTypeId) + cfd.NumberColumn.ToString();
                            if (ComponentId == 0)
                            {
                                oItem = DBNull.Value;
                            }
                            else
                            {
                                oItem = dtCustomFieldsFromDB.Rows[0][sTypeName];
                            }
                            switch (cfd.FieldTypeId)
                            {
                            case DBFieldType._nvarchar:
                                if (oItem != DBNull.Value)
                                {
                                    dtCustomFields.Rows.Add(new object [] { sTypeName, cfd.NameText, oItem, "False", 0, "2000-01-01", "True", "False", "False", "False", "False", cfd.Help, "False", "", "" });
                                }
                                else
                                {
                                    dtCustomFields.Rows.Add(new object [] { sTypeName, cfd.NameText, "", "False", 0, "2000-01-01", "True", "False", "False", "False", "False", cfd.Help, "False", "", "" });
                                }
                                break;

                            case DBFieldType._int:
                                if (oItem != DBNull.Value)
                                {
                                    dtCustomFields.Rows.Add(new object [] { sTypeName, cfd.NameText, oItem, "False", 0, "2000-01-01", "True", "False", "False", "False", "False", cfd.Help, "True", cfd.NameText + " must be numeric", "^\\d{0,10}?$" });
                                }
                                else
                                {
                                    dtCustomFields.Rows.Add(new object [] { sTypeName, cfd.NameText, "", "False", 0, "2000-01-01", "True", "False", "False", "False", "False", cfd.Help, "True", cfd.NameText + " must be numeric", "^\\d{0,10}?$" });
                                }
                                break;

                            case DBFieldType._float:
                                if (oItem != DBNull.Value)
                                {
                                    dtCustomFields.Rows.Add(new object [] { sTypeName, cfd.NameText, oItem, "False", 0, "2000-01-01", "True", "False", "False", "False", "False", cfd.Help, "True", cfd.NameText + " must be decimal numeric", "^\\d{0,8}(?:\\.\\d{0,8})?$" });
                                }
                                else
                                {
                                    dtCustomFields.Rows.Add(new object [] { sTypeName, cfd.NameText, "", "False", 0, "2000-01-01", "True", "False", "False", "False", "False", cfd.Help, "True", cfd.NameText + " must be decimal numeric", "^\\d{0,8}(?:\\.\\d{0,8})?$" });
                                }
                                break;

                            case DBFieldType._datetime:
                                if (oItem != DBNull.Value)
                                {
                                    dtCustomFields.Rows.Add(new object [] { sTypeName, cfd.NameText, "", "False", 0, ((SqlDateTime)oItem).Value.ToShortDateString(), "False", "False", "False", "False", "True", cfd.Help, "False", "", "" });
                                }
                                else
                                {
                                    dtCustomFields.Rows.Add(new object [] { sTypeName, cfd.NameText, "", "False", 0, "", "False", "False", "False", "False", "True", cfd.Help, "False", "", "" });
                                }
                                break;

                            case DBFieldType._bit:
                                if (oItem != DBNull.Value)
                                {
                                    if (((SqlBoolean)oItem) == SqlBoolean.True)
                                    {
                                        dtCustomFields.Rows.Add(new object [] { sTypeName, cfd.NameText, "", "True", 0, "2000-01-01", "False", "False", "True", "False", "False", cfd.Help, "False", "", "" });
                                    }
                                    else
                                    {
                                        dtCustomFields.Rows.Add(new object [] { sTypeName, cfd.NameText, "", "False", 0, "2000-01-01", "False", "False", "True", "False", "False", cfd.Help, "False", "", "" });
                                    }
                                    break;
                                }
                                else
                                {
                                    dtCustomFields.Rows.Add(new object [] { sTypeName, cfd.NameText, "", "False", 0, "2000-01-01", "False", "False", "True", "False", "False", cfd.Help, "False", "", "" });
                                }
                                break;

                            case DBFieldType._ntext:
                                if (oItem != DBNull.Value)
                                {
                                    dtCustomFields.Rows.Add(new object [] { sTypeName, cfd.NameText, oItem, "2000-01-01", 0, "2000-01-01", "True", "False", "False", "False", "False", cfd.Help, "False", "", "" });
                                }
                                else
                                {
                                    dtCustomFields.Rows.Add(new object [] { sTypeName, cfd.NameText, "", "2000-01-01", 0, "2000-01-01", "True", "False", "False", "False", "False", cfd.Help, "False", "", "" });
                                }
                                break;

                            case DBFieldType._sql_variant:
                                dtCustomFields.Rows.Add(new object [] { sTypeName, cfd.NameText, (string)dtCustomFieldsFromDB.Rows[0][sTypeName], "2000-01-01", 0, "2000-01-01", "True", "False", "False", "False", "False", cfd.Help, "False", "", "" });
                                break;

                            case DBFieldType._lookup:
                                if (oItem != DBNull.Value)
                                {
                                    if (cfd.NameLookupTable == "EquipModels")
                                    {
                                        // adding data into DropDownList controls both Make and Model
                                        dtCustomFields.Rows.Add(new object [] { sTypeName, "Make/Model", "", "False", Convert.ToInt32(oItem), "2000-01-01", "False", "False", "False", "True", "False", cfd.Help, "False", "", "" });
                                    }
                                    else
                                    {
                                        dtCustomFields.Rows.Add(new object [] { sTypeName, "Make/Model", "", "False", "0", "2000-01-01", "False", "False", "False", "True", "False", cfd.Help, "False", "", "" });
                                    }
                                }
                                else
                                {
                                    dtCustomFields.Rows.Add(new object [] { sTypeName, "Make/Model", "", "False", "0", "2000-01-01", "False", "False", "False", "True", "False", cfd.Help, "False", "", "" });
                                }
                                break;

                            default:
                                break;
                            }
                            cfd = null;
                        }
                        // binding main datalist
                        ViewState["CustomFields"]  = dtCustomFields;
                        repCustomFields.DataSource = new DataView(dtCustomFields);
                        repCustomFields.DataBind();
                    }
                    else
                    {
                        Session["lastpage"] = ParentPageURL;
                        Session["error"]    = _functions.ErrorMessage(102);
                        Response.Redirect("error.aspx", false);
                    }
                }
            }
            catch (Exception ex)
            {
                _functions.Log(ex, HttpContext.Current.User.Identity.Name, SourcePageName);
                Session["lastpage"]     = ParentPageURL;
                Session["error"]        = ex.Message;
                Session["error_report"] = ex.ToString();
                Response.Redirect("error.aspx", false);
            }
            finally
            {
                if (comp != null)
                {
                    comp.Dispose();
                }
            }
        }
コード例 #4
0
        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(ex, HttpContext.Current.User.Identity.Name, SourcePageName);
                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();
                }
            }
        }
コード例 #5
0
ファイル: view.aspx.cs プロジェクト: weedkiller/Fleet
        private void Page_Load(object sender, System.EventArgs e)
        {
            clsCustomFieldsDef cfd = null;
            int j;

            try
            {
                if (Request.QueryString["id"] == null)
                {
                    Session["lastpage"] = "list.aspx";
                    Session["error"]    = _functions.ErrorMessage(104);
                    Response.Redirect("error.aspx", false);
                    return;
                }
                try
                {
                    EquipId = Convert.ToInt32(Request.QueryString["id"]);
                }
                catch (FormatException fex)
                {
                    Session["lastpage"] = "list.aspx";
                    Session["error"]    = _functions.ErrorMessage(105);
                    Response.Redirect("error.aspx", false);
                    return;
                }

                PageTitle = "Equipment Detail";
                string [,] arrBrdCrumbs = new string [2, 2];
                arrBrdCrumbs[0, 0]      = "main.aspx";
                arrBrdCrumbs[0, 1]      = "Home";
                arrBrdCrumbs[1, 0]      = "list.aspx";
                arrBrdCrumbs[1, 1]      = "Equipment List";
                PageTitle        = "Equipment Detail";
                Header.BrdCrumbs = ParseBreadCrumbs(arrBrdCrumbs, PageTitle);
                Header.PageTitle = PageTitle;

                if (!IsPostBack)
                {
                    Session["EquipId"] = EquipId;
                    equip          = new clsEquipment();
                    comp           = new clsComponents();
                    dtCustomFields = new DataTable();
                    dtCustomFields.Columns.Add("ValueName");
                    dtCustomFields.Columns.Add("Value");
                    equip.iOrgId  = _functions.GetUserOrgId(HttpContext.Current.User.Identity.Name, false);
                    equip.iId     = EquipId;
                    equip.cAction = "S";
                    // getting a fixed fields in the label controls
                    if (equip.EquipmentDetail() == -1)
                    {
                        Session["lastpage"] = ParentPageURL;
                        Session["error"]    = _functions.ErrorMessage(102);
                        Response.Redirect("error.aspx", false);
                    }
                    // showing a Equipment's data from fixed fields
                    lbStatus.Text     = equip.sStatus.Value;
                    lbPMSched.Text    = equip.sPMSched.Value;
                    lbInspection.Text = equip.sInspect.Value;
                    if (!equip.iCurrentUnits.IsNull)
                    {
                        lbUnits.Text = equip.iCurrentUnits.Value.ToString();
                    }
                    if (!equip.daInService.IsNull)
                    {
                        lbDtInService.Text = equip.daInService.Value.ToShortDateString();
                    }
                    if (!equip.daAquired.IsNull)
                    {
                        lbDtAquired.Text = equip.daAquired.Value.ToShortDateString();
                    }
                    lbVchPurOrgContact.Text = equip.sPurOrgContact.Value;
                    if (!equip.curPurAmount.IsNull)
                    {
                        lbSmPurAmount.Text = equip.curPurAmount.Value.ToString();
                    }
                    if (!equip.iPurUnits.IsNull)
                    {
                        lbIntPurUnits.Text = equip.iPurUnits.Value.ToString();
                    }
                    lbVchPurNotes.Text = equip.sPurNotes.Value;
                    if (!equip.daOutOfService.IsNull)
                    {
                        lbDtOutOfService.Text = equip.daOutOfService.Value.ToShortDateString();
                    }
                    if (!equip.daDisposed.IsNull)
                    {
                        lbDtDisposed.Text = equip.daDisposed.Value.ToShortDateString();
                    }
                    if (!equip.sDispMethod.IsNull)
                    {
                        lbVchDispMethod.Text = equip.sDispMethod.Value;
                    }
                    if (!equip.sDispOrgContact.IsNull)
                    {
                        lbVchDispOrgContact.Text = equip.sDispOrgContact.Value;
                    }
                    if (!equip.curDispAmount.IsNull)
                    {
                        lbSmDispAmount.Text = equip.curDispAmount.Value.ToString();
                    }
                    if (!equip.iDispUnits.IsNull)
                    {
                        lbIntDispUnits.Text = equip.iDispUnits.Value.ToString();
                    }
                    lbVchDispNotes.Text = equip.sDispNotes.Value;

                    // getting all component's types to dropdownlist
                    comp.iOrgId = _functions.GetUserOrgId(HttpContext.Current.User.Identity.Name, false);
                    ddlComponentTypes.DataTextField  = "vchName";
                    ddlComponentTypes.DataValueField = "Id";
                    ddlComponentTypes.DataSource     = new DataView(comp.GetComponentTypeList());
                    ddlComponentTypes.DataBind();

                    // getting the fixed fields in the DataList control
                    dtCustomFieldsFromDB = equip.EquipmentDetail_CustomFields(null);
                    dtCustomFields.Rows.Add(new object [] { "Type", dtCustomFieldsFromDB.Rows[0]["TypeName"] });

                    // getting the custom fields in the DataList control

                    //arrCFD = _functions.CustomFieldsParse(dtCustomFieldsFromDB, Convert.ToInt32(Session["EquipTypeId"]));
                    arrCFD = _functions.GetCustomFields(false, Convert.ToInt32(Session["EquipTypeId"]), HttpContext.Current.User.Identity.Name);
                    if (arrCFD.Count > 0)
                    {
                        // fill custom fields
                        for (j = 0; j < arrCFD.Count; j++)
                        {
                            cfd       = (clsCustomFieldsDef)arrCFD[j];
                            sTypeName = _functions.GetFieldTypeText(cfd.FieldTypeId) + cfd.NumberColumn.ToString();

                            switch (cfd.FieldTypeId)
                            {
                            case DBFieldType._lookup:
                                switch (cfd.NameLookupTable)
                                {
                                case "EquipModels":
                                    mm          = new clsMakesModels();
                                    mm.iOrgId   = _functions.GetUserOrgId(HttpContext.Current.User.Identity.Name, false);
                                    mm.iModelId = Convert.ToInt32(dtCustomFieldsFromDB.Rows[0][sTypeName]);
                                    mm.GetModelMakes();
                                    dtCustomFields.Rows.Add(new object [] { "Make/Model", mm.sMakeName + "/" + mm.sModelName });
                                    break;

                                case "Departments":
                                    dep         = new clsDepartments();
                                    dep.cAction = "S";
                                    dep.iOrgId  = _functions.GetUserOrgId(HttpContext.Current.User.Identity.Name, false);
                                    dep.iId     = Convert.ToInt32(dtCustomFieldsFromDB.Rows[0][sTypeName]);
                                    if (dep.DepartmentDetail() == 0)
                                    {
                                        dtCustomFields.Rows.Add(new object [] { cfd.NameText, dep.sName.Value });
                                    }
                                    break;

                                case "Locations":
                                    loc         = new clsLocations();
                                    loc.cAction = "S";
                                    loc.iOrgId  = _functions.GetUserOrgId(HttpContext.Current.User.Identity.Name, false);
                                    loc.iId     = Convert.ToInt32(dtCustomFieldsFromDB.Rows[0][sTypeName]);
                                    if (loc.LocationDetail() == 0)
                                    {
                                        dtCustomFields.Rows.Add(new object [] { cfd.NameText, loc.sName.Value });
                                    }
                                    break;

                                default:
                                    break;
                                }
                                break;

                            case DBFieldType._datetime:
                                dtCustomFields.Rows.Add(new object [] { cfd.NameText, ((DateTime)dtCustomFieldsFromDB.Rows[0][sTypeName]).ToShortDateString() });
                                break;

                            case DBFieldType._bit:
                                if (((bool)dtCustomFieldsFromDB.Rows[0][sTypeName]) == true)
                                {
                                    dtCustomFields.Rows.Add(new object [] { cfd.NameText, "Yes" });
                                }
                                else
                                {
                                    dtCustomFields.Rows.Add(new object [] { cfd.NameText, "No" });
                                }
                                break;

                            default:
                                dtCustomFields.Rows.Add(new object [] { cfd.NameText, dtCustomFieldsFromDB.Rows[0][sTypeName] });
                                break;
                            }

                            cfd = null;
                        }

                        // showing a Equipment's data from custom fields
                        repCustomFields.DataSource = new DataView(dtCustomFields);
                        repCustomFields.DataBind();

                        comp.iEquipId            = EquipId;
                        comp.iOrgId              = _functions.GetUserOrgId(HttpContext.Current.User.Identity.Name, false);
                        dtComponents             = comp.GetComponentsList();
                        ViewState["Components"]  = dtComponents;
                        repComponents.DataSource = new DataView(dtComponents);
                        repComponents.DataBind();
                    }
                    else
                    {
                        Session["lastpage"] = ParentPageURL;
                        Session["error"]    = _functions.ErrorMessage(102);
                        Response.Redirect("error.aspx", false);
                    }
                }
            }
            catch (Exception ex)
            {
                _functions.Log("Application error: \n" + ex.ToString());
                Session["lastpage"]     = ParentPageURL;
                Session["error"]        = ex.Message;
                Session["error_report"] = ex.ToString();
                Response.Redirect("error.aspx", false);
            }
            finally
            {
                if (comp != null)
                {
                    comp.Dispose();
                }
                if (loc != null)
                {
                    loc.Dispose();
                }
                if (dep != null)
                {
                    dep.Dispose();
                }
                if (mm != null)
                {
                    mm.Dispose();
                }
                if (comp != null)
                {
                    comp.Dispose();
                }
                if (equip != null)
                {
                    equip.Dispose();
                }
            }
        }
コード例 #6
0
ファイル: e_view.aspx.cs プロジェクト: weedkiller/Fleet
        private void Page_Load(object sender, System.EventArgs e)
        {
            int  j;
            bool bVisibleLink;

            try
            {
                OrgId = _functions.GetUserOrgId(HttpContext.Current.User.Identity.Name, false);

                if (Request.QueryString["id"] == null)
                {
                    Session["lastpage"] = "e_list.aspx";
                    Session["error"]    = _functions.ErrorMessage(104);
                    Response.Redirect("error.aspx", false);
                    return;
                }
                try
                {
                    EquipId = Convert.ToInt32(Request.QueryString["id"]);
                }
                catch (FormatException fex)
                {
                    Session["lastpage"] = "e_list.aspx";
                    Session["error"]    = _functions.ErrorMessage(105);
                    Response.Redirect("error.aspx", false);
                    return;
                }

                if (!IsPostBack)
                {
                    hlEdit.NavigateUrl       = "e_edit.aspx?id=" + EquipId.ToString();
                    hlEdit2.NavigateUrl      = "e_edit2.aspx?id=" + EquipId.ToString();
                    hlEditCustom.NavigateUrl = "e_editCustom.aspx?id=" + EquipId.ToString();
                    hlEditAquis.NavigateUrl  = "e_editAquis.aspx?id=" + EquipId.ToString();
                    hlEditDisp.NavigateUrl   = "e_editDisp.aspx?id=" + EquipId.ToString();
                    hlReport.NavigateUrl     = "e_viewEquipAssignmentReport.aspx?id=" + EquipId.ToString();

                    bVisibleLink           = base.CheckPermission("e_editComponent.aspx");
                    trAddComponent.Visible = bVisibleLink;

                    Session["EquipId"] = EquipId;

                    equip = new clsEquipment();
                    comp  = new clsComponents();

                    dtCustomFields = new DataTable();
                    dtCustomFields.Columns.Add("ValueName");
                    dtCustomFields.Columns.Add("Value");

                    equip.iUserId = _functions.GetUserOrgId(HttpContext.Current.User.Identity.Name, true);
                    equip.iOrgId  = OrgId;
                    equip.iId     = EquipId;
                    equip.cAction = "S";

                    // showing a Equipment's main data from fixed fields
                    if (equip.EquipmentDetail() == -1)
                    {
                        Session["lastpage"] = ParentPageURL;
                        Session["error"]    = _functions.ErrorMessage(102);
                        Response.Redirect("error.aspx", false);
                        return;
                    }
                    lblEquipment.Text    = equip.sEquipId.Value;
                    lblType.Text         = equip.sType.Value;
                    lblMakeModel.Text    = equip.sMakeModelName.Value;
                    lblYear.Text         = equip.iYear.Value.ToString();
                    lblSerial.Text       = equip.sVinSerial.Value;
                    lblFuelCode.Text     = equip.sFuelCode.Value;
                    lblPlateNumber.Text  = equip.sPlateNumber.Value;
                    lblDepartment.Text   = equip.sDeptName.Value;
                    lblLocation.Text     = equip.sLocName.Value;
                    lblSpare.Text        = equip.bSpare.Value?"Yes":"No";
                    lblAssignedTo.Text   = equip.sEquipOperator.Value;
                    lblAssignTempTo.Text = equip.sTempOperator.Value;

                    // showing a Equipment's Alt data from fixed fields
                    if (equip.EquipmentDetail_Alt() == -1)
                    {
                        Session["lastpage"] = ParentPageURL;
                        Session["error"]    = _functions.ErrorMessage(102);
                        Response.Redirect("error.aspx", false);
                        return;
                    }
                    lbPMSched.Text    = equip.sPMSched.Value;
                    lbInspection.Text = equip.sInspectSchedule.Value;
                    if (!equip.dmCurrentUnits.IsNull)
                    {
                        lbUnits.Text = Convert.ToDouble(equip.dmCurrentUnits.Value).ToString();
                    }

                    // showing an Aquisition information from fixed fields
                    if (equip.EquipmentDetail_Aquis() == -1)
                    {
                        Session["lastpage"] = ParentPageURL;
                        Session["error"]    = _functions.ErrorMessage(102);
                        Response.Redirect("error.aspx", false);
                        return;
                    }
                    if (!equip.daInService.IsNull)
                    {
                        lbDtInService.Text = equip.daInService.Value.ToShortDateString();
                    }
                    if (!equip.daAquired.IsNull)
                    {
                        lbDtAquired.Text = equip.daAquired.Value.ToShortDateString();
                    }
                    lbVchPurOrgContact.Text = equip.sPurOrgContact.Value;
                    if (!equip.curPurAmount.IsNull)
                    {
                        lbSmPurAmount.Text = equip.curPurAmount.Value.ToString();
                    }
                    if (!equip.dmPurUnits.IsNull)
                    {
                        lbIntPurUnits.Text = Convert.ToDouble(equip.dmPurUnits.Value).ToString();
                    }
                    lbVchPurNotes.Text = equip.sPurNotes.Value;

                    // showing a Disposal info from fixed fields
                    if (equip.EquipmentDetail_Disp() == -1)
                    {
                        Session["lastpage"] = ParentPageURL;
                        Session["error"]    = _functions.ErrorMessage(102);
                        Response.Redirect("error.aspx", false);
                        return;
                    }
                    if (!equip.daOutOfService.IsNull)
                    {
                        lbDtOutOfService.Text = equip.daOutOfService.Value.ToShortDateString();
                    }
                    if (!equip.daDisposed.IsNull)
                    {
                        lbDtDisposed.Text = equip.daDisposed.Value.ToShortDateString();
                    }
                    if (!equip.sDispMethod.IsNull)
                    {
                        lbVchDispMethod.Text = equip.sDispMethod.Value;
                    }
                    if (!equip.sDispOrgContact.IsNull)
                    {
                        lbVchDispOrgContact.Text = equip.sDispOrgContact.Value;
                    }
                    if (!equip.curDispAmount.IsNull)
                    {
                        lbSmDispAmount.Text = equip.curDispAmount.Value.ToString();
                    }
                    if (!equip.dmDispUnits.IsNull)
                    {
                        lbIntDispUnits.Text = Convert.ToDouble(equip.dmDispUnits.Value).ToString();
                    }
                    lbVchDispNotes.Text = equip.sDispNotes.Value;

                    // getting all component's types to dropdownlist
                    comp.iEquipId = EquipId;
                    DataTable dtComponmentAdd = comp.GetComponentTypeList();
                    if (dtComponmentAdd.Rows.Count > 0)
                    {
                        ddlComponentTypes.DataTextField  = "vchName";
                        ddlComponentTypes.DataValueField = "Id";
                        ddlComponentTypes.DataSource     = new DataView(dtComponmentAdd);
                        ddlComponentTypes.DataBind();
                    }
                    else
                    {
                        ddlComponentTypes.Items.Add(new ListItem("<none>", "0"));
                        lbAddComponent.Enabled = false;
                    }

                    #region Show Custom Fileds for current equipment
                    // getting the custom fields in the DataList control
                    equip.iId            = EquipId;
                    dtCustomFieldsFromDB = equip.EquipmentDetail_CustomFields(null);

                    if (dtCustomFieldsFromDB.Rows.Count > 0)
                    {
                        arrCFD = _functions.GetCustomFields(CFDataType.Equipment, Convert.ToInt32(dtCustomFieldsFromDB.Rows[0]["TypeId"]), HttpContext.Current.User.Identity.Name);
                        if (arrCFD.Count > 0)
                        {
                            // fill custom fields
                            for (j = 0; j < arrCFD.Count; j++)
                            {
                                cfd       = (clsCustomFieldsDef)arrCFD[j];
                                sTypeName = _functions.GetFieldTypeText(cfd.FieldTypeId) + cfd.NumberColumn.ToString();

                                switch (cfd.FieldTypeId)
                                {
                                case DBFieldType._lookup:
                                    switch (cfd.NameLookupTable)
                                    {
                                    case "EquipModels":
                                        if (dtCustomFieldsFromDB.Rows[0][sTypeName] == DBNull.Value)
                                        {
                                            dtCustomFields.Rows.Add(new object [] { "Make/Model", "" });
                                        }
                                        else
                                        {
                                            mm          = new clsMakesModels();
                                            mm.iOrgId   = _functions.GetUserOrgId(HttpContext.Current.User.Identity.Name, false);
                                            mm.iModelId = Convert.ToInt32(dtCustomFieldsFromDB.Rows[0][sTypeName]);
                                            mm.GetModelMakes();
                                            dtCustomFields.Rows.Add(new object [] { "Make/Model", mm.sMakeName + "/" + mm.sModelName });
                                        }
                                        break;

                                    case "Departments":
                                        if (dtCustomFieldsFromDB.Rows[0][sTypeName] == DBNull.Value)
                                        {
                                            dtCustomFields.Rows.Add(new object [] { cfd.NameText, "" });
                                        }
                                        else
                                        {
                                            dep         = new clsDepartments();
                                            dep.cAction = "S";
                                            dep.iOrgId  = _functions.GetUserOrgId(HttpContext.Current.User.Identity.Name, false);
                                            dep.iId     = Convert.ToInt32(dtCustomFieldsFromDB.Rows[0][sTypeName]);
                                            if (dep.DepartmentDetail() == 0)
                                            {
                                                dtCustomFields.Rows.Add(new object [] { cfd.NameText, dep.sName.Value });
                                            }
                                            else
                                            {
                                                dtCustomFields.Rows.Add(new object [] { cfd.NameText, "" });
                                            }
                                        }
                                        break;

                                    case "Locations":
                                        if (dtCustomFieldsFromDB.Rows[0][sTypeName] == DBNull.Value)
                                        {
                                            dtCustomFields.Rows.Add(new object [] { cfd.NameText, "" });
                                        }
                                        else
                                        {
                                            loc         = new clsLocations();
                                            loc.cAction = "S";
                                            loc.iOrgId  = _functions.GetUserOrgId(HttpContext.Current.User.Identity.Name, false);
                                            loc.iId     = Convert.ToInt32(dtCustomFieldsFromDB.Rows[0][sTypeName]);
                                            if (loc.LocationDetail() == 0)
                                            {
                                                dtCustomFields.Rows.Add(new object [] { cfd.NameText, loc.sName.Value });
                                            }
                                            else
                                            {
                                                dtCustomFields.Rows.Add(new object [] { cfd.NameText, "" });
                                            }
                                        }
                                        break;

                                    default:
                                        break;
                                    }
                                    break;

                                case DBFieldType._datetime:
                                    if (dtCustomFieldsFromDB.Rows[0][sTypeName] == DBNull.Value)
                                    {
                                        dtCustomFields.Rows.Add(new object [] { cfd.NameText, "" });
                                    }
                                    else
                                    {
                                        dtCustomFields.Rows.Add(new object [] { cfd.NameText, ((DateTime)dtCustomFieldsFromDB.Rows[0][sTypeName]).ToShortDateString() });
                                    }
                                    break;

                                case DBFieldType._bit:
                                    if (dtCustomFieldsFromDB.Rows[0][sTypeName] == DBNull.Value)
                                    {
                                        dtCustomFields.Rows.Add(new object [] { cfd.NameText, "" });
                                    }
                                    else
                                    {
                                        if (((bool)dtCustomFieldsFromDB.Rows[0][sTypeName]) == true)
                                        {
                                            dtCustomFields.Rows.Add(new object [] { cfd.NameText, "Yes" });
                                        }
                                        else
                                        {
                                            dtCustomFields.Rows.Add(new object [] { cfd.NameText, "No" });
                                        }
                                    }
                                    break;

                                default:
                                    if (dtCustomFieldsFromDB.Rows[0][sTypeName] == DBNull.Value)
                                    {
                                        dtCustomFields.Rows.Add(new object [] { cfd.NameText, "" });
                                    }
                                    else
                                    {
                                        dtCustomFields.Rows.Add(new object [] { cfd.NameText, dtCustomFieldsFromDB.Rows[0][sTypeName] });
                                    }
                                    break;
                                }
                                cfd = null;
                            }

                            // showing a Equipment's data from custom fields
                            repCustomFields.DataSource = new DataView(dtCustomFields);
                            repCustomFields.DataBind();

                            comp.iEquipId = EquipId;
                            comp.iOrgId   = OrgId;
                            dtComponents  = comp.GetComponentsList();
                            dtComponents.Columns.Add("VisibleLink");
                            foreach (DataRow _row in dtComponents.Rows)
                            {
                                if (bVisibleLink)
                                {
                                    _row["VisibleLink"] = "True";
                                }
                                else
                                {
                                    _row["VisibleLink"] = "False";
                                }
                            }
                            ViewState["Components"]  = dtComponents;
                            repComponents.DataSource = new DataView(dtComponents);
                            repComponents.DataBind();
                        }
                        else
                        {
                            Session["lastpage"] = ParentPageURL;
                            Session["error"]    = _functions.ErrorMessage(102);
                            Response.Redirect("error.aspx", false);
                        }
                    }
                }
                #endregion
            }
            catch (Exception ex)
            {
                _functions.Log(ex, HttpContext.Current.User.Identity.Name, SourcePageName);
                Session["lastpage"]     = ParentPageURL;
                Session["error"]        = ex.Message;
                Session["error_report"] = ex.ToString();
                Response.Redirect("error.aspx", false);
            }
            finally
            {
                if (comp != null)
                {
                    comp.Dispose();
                }
                if (loc != null)
                {
                    loc.Dispose();
                }
                if (dep != null)
                {
                    dep.Dispose();
                }
                if (mm != null)
                {
                    mm.Dispose();
                }
                if (comp != null)
                {
                    comp.Dispose();
                }
                if (equip != null)
                {
                    equip.Dispose();
                }
            }
        }