segunda-feira, 20 de julho de 2015

MVC EAA

using System;
using System.Collections.Generic;
using System.Web;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;



namespace Lapuinka.EAA.Controller.Web
{
    ///
    /// Represents DetailView
    ///
    public class BasePageDetailView : BaseView
    {

        #region Methods

        #region Edit
        ///
        /// Search
        ///
        public virtual void Edit()
        {
            ObjectsToView();
            BindData();
        }
        #endregion

        #region Validator
        ///
        /// Validator
        ///
        ///
        ///
        protected string Validator(IDataPersist obj)
        {
            return obj.Validator();
        }
        #endregion

        #region Save
        ///
        /// Save Object in Database
        ///
        ///
        ///
        protected virtual bool Save()
        {
            ViewToObjects();
            try
            {
                //Persist object in Database
                string msg = ((IDataPersist)this.ObjectEdit).Validator();
                if (msg == string.Empty)
                {
                    int ID = ((IDataPersist)this.ObjectEdit).Save();
                    AfterSave(ID);
                    base.ShowMessageAlert(Message.getMessage(Message.IDMessage.MSG_RECORD_INSERTED_SUCESS));
                    BeforeSave(ID);
                }
                else
                {
                    base.ShowMessageAlert(msg);
                    return false;
                }
            }
            catch (System.Data.SqlClient.SqlException ex)
            {
                this.ShowMessageAlert(DataBase.DataBaseController.ShowErrorMessage(ex));
                return false;
            }
            return true;
        }
        #endregion

        #region Delete
        ///
        /// Delete Object in Database
        ///
        ///
        ///
        protected virtual bool Delete(IDataPersist obj)
        {
            try
            {
                //Persist object in Database
                bool bret = obj.Delete();
                ///Generic message because object can be restored
                base.ShowMessageAlertAndCloseWindow(Message.getMessage(Message.IDMessage.MSG_RECORD_OPERATION_SUCESS));
            }
            catch (System.Data.SqlClient.SqlException ex)
            {
                this.ShowMessageAlert(DataBase.DataBaseController.ShowErrorMessage(ex));
                return false;
            }
            return true;
        }
        #endregion

        #endregion

        #region Events

        #region OnInit
        ///
        /// OnInit
        ///
        ///
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            Edit();
        }
        #endregion

        #region btnUpdate_Click
        ///
        /// Update Object in Storage
        ///
        ///
        ///
        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            Save();
        }
        #endregion

        #region btnRemove_Click
        ///
        /// Remove Click
        ///
        ///
        ///
        protected void btnRemove_Click(object sender, EventArgs e)
        {
            ViewToObjects();
            this.ObjectDelete = null;
            BeforeDelete(DataBase.DataBaseController.GetIDObject(ObjectEdit));
            Delete(((BaseObject)base.ObjectDelete));
        }
        #endregion

        #endregion

    }

}


Postar um comentário