protected void btnRemove_Click(object sender, EventArgs e)
    {
        try
        {
            int    id  = -1;
            string _id = Request.QueryString["id"].ToString();
            int.TryParse(_id, out id);
            int userId = CurrentEnvironment.LoggedUser.Id;

            int i = Uom.Delete(id);

            if (i > 0)
            {
                lblSuccess.Visible = true;
                lblWarning.Visible = false;
                lblError.Visible   = false;

                gvUom.DataSource = Uom.GetUomList();
                gvUom.DataBind();
                ClearControls(this);
            }
            else
            {
                lblSuccess.Visible = false;
                lblWarning.Visible = true;
                lblError.Visible   = false;
            }
        }
        catch (Exception ex)
        {
            lblSuccess.Visible = false;
            lblWarning.Visible = false;
            lblError.Visible   = true;
        }
    }
    protected void btnEdit_Click(object sender, EventArgs e)
    {
        try
        {
            if (Page.IsValid)
            {
                int    id  = -1;
                string _id = Request.QueryString["id"].ToString();
                int.TryParse(_id, out id);
                int userId = CurrentEnvironment.LoggedUser.Id;

                Uom o = Uom.GetUomById(id);

                o.Name  = txtName.Text.Replace("'", @"''");
                o.Notes = txtNotes.Text.Replace("'", @"''");

                int i = Uom.Update(o);

                if (i > 0)
                {
                    lblSuccess.Visible = true;
                    lblWarning.Visible = false;
                    lblError.Visible   = false;

                    gvUom.DataSource = Uom.GetUomList();
                    gvUom.DataBind();
                    ClearControls(this);
                }
                else
                {
                    lblSuccess.Visible = false;
                    lblWarning.Visible = true;
                    lblError.Visible   = false;
                }
            }
        }
        catch (Exception ex)
        {
            lblSuccess.Visible = false;
            lblWarning.Visible = false;
            lblError.Visible   = true;
        }
    }
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        try
        {
            if (Page.IsValid)
            {
                int userId = CurrentEnvironment.LoggedUser.Id;

                Uom o = new Uom();

                o.Name  = txtName.Text.Replace("'", @"''");
                o.Notes = txtNotes.Text.Replace("'", @"''");

                int i = Uom.Insert(o);

                if (i > 0)
                {
                    lblSuccess.Visible = true;
                    lblWarning.Visible = false;
                    lblError.Visible   = false;

                    gvUom.DataSource = Uom.GetUomList();
                    gvUom.DataBind();
                    ClearControls(this);
                }
                else
                {
                    lblSuccess.Visible = false;
                    lblWarning.Visible = true;
                    lblError.Visible   = false;
                }
            }
        }
        catch (Exception ex)
        {
            lblSuccess.Visible = false;
            lblWarning.Visible = false;
            lblError.Visible   = true;
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.Page.IsPostBack)
        {
            List <string> actionList        = null;
            string        sessionNameAction = "";
            if (CurrentEnvironment.LoggedUser != null)
            {
                sessionNameAction = "__GIS_actionList_" + CurrentEnvironment.LoggedUser.Id;
                actionList        = (List <string>)Session[sessionNameAction];
            }

            if ((actionList != null) && actionList.Contains("ViewUom") && (CurrentEnvironment.LoggedUser != null))
            {
                int    userId     = CurrentEnvironment.LoggedUser.Id;
                string language   = CurrentEnvironment.Language;
                int    languageId = int.Parse(language);
                Dictionary <string, string> wtList = (Dictionary <string, string>)HttpContext.Current.Cache["Uom-dictionary" + language];
                if (wtList == null)
                {
                    List <WordTranslate> wordTranslateList = WordTranslate.GetWordByLanguage(languageId, "Uom");
                    wtList = new Dictionary <string, string>();
                    foreach (WordTranslate vwt in wordTranslateList)
                    {
                        wtList.Add(vwt.Code, vwt.Name);
                    }
                    HttpContext.Current.Cache.Insert("Uom-dictionary" + language, wtList);
                }

                //controls
                this.lblName.Text  = wtList["UomName"];
                this.lblNotes.Text = wtList["UomNotes"];

                //grid header text
                gvUom.Columns[1].HeaderText = wtList["UomName"];
                gvUom.Columns[2].HeaderText = wtList["UomNotes"];

                //actions
                this.btnAdd.Visible    = actionList.Contains("AddUom");
                this.btnEdit.Visible   = actionList.Contains("EditUom");
                this.btnRemove.Visible = actionList.Contains("RemoveUom");

                //buttons
                this.btnAdd.Text    = wtList["UomAddButton"];
                this.btnEdit.Text   = wtList["UomEditButton"];
                this.btnRemove.Text = wtList["UomRemoveButton"];

                //message
                this.lblSuccess.Text = wtList["UomSuccessText"];
                this.lblWarning.Text = wtList["UomWarningText"];
                this.lblError.Text   = wtList["UomErrorText"];

                //Page Title
                this.lblTitle.Text = wtList["UomPageTitle"];

                //selected object
                int    id  = -1;
                string _id = Request.QueryString["id"];
                if (!String.IsNullOrEmpty(_id))
                {
                    int.TryParse(_id, out id);
                    Uom o = Uom.GetUomById(id);
                    if (o != null)
                    {
                        txtName.Text  = o.Name;
                        txtNotes.Text = o.Notes;
                    }
                    btnAdd.Visible = false;
                }
                else
                {
                    btnEdit.Visible   = false;
                    btnRemove.Visible = false;
                }

                gvUom.DataSource = Uom.GetUomList();
                gvUom.DataBind();
            }
            else
            {
                Response.Redirect("Default.aspx");
            }
        }
    }