private void btnAdd_Click(object sender, EventArgs e)
        {
            session = null;
            SessionDetailForm detailForm = new SessionDetailForm(session);

            detailForm.FormClosed += new FormClosedEventHandler(DetailForm_Closed);
            detailForm.ShowDialog();
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            int result = CRUDStatusCode.ERROR;

            try
            {
                _sessionService = new SessionService();

                if (model == null)
                {
                    //Add
                    model = new DataService.Model.Session()
                    {
                        Code = txtCode.Text,
                        Name = txtName.Text
                    };
                    result = _sessionService.AddSession(model);
                    if (result == CRUDStatusCode.SUCCESS)
                    {
                        Utilities.ShowMessage(CommonMessage.ADD_SUCESSFULLY);
                        Logging.LogBusiness(string.Format("{0} {1} {2}",
                                                          Common.Session.GetUserName(),
                                                          Common.Constants.LogAction.Create, "buổi phát " + model.Code + " " + model.Name),
                                            Common.Constants.BusinessLogType.Create);
                    }
                }
                else
                {
                    //Edit
                    model.Code = txtCode.Text;
                    model.Name = txtName.Text;

                    result = _sessionService.EditSession(model);
                    if (result == CRUDStatusCode.SUCCESS)
                    {
                        Utilities.ShowMessage(CommonMessage.EDIT_SUCESSFULLY);
                        Logging.LogBusiness(string.Format("{0} {1} {2}",
                                                          Common.Session.GetUserName(),
                                                          Common.Constants.LogAction.Update, "buổi phát " + model.Code + " " + model.Name),
                                            Common.Constants.BusinessLogType.Update);
                    }
                }
            }
            catch (Exception ex)
            {
                throw;
            }
            finally
            {
                _sessionService = null;
            }
        }
        private void adgv_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (adgv.SelectedRows.Count > 0)
            {
                var selectedRow = adgv.SelectedRows[0];

                //Prepare model
                if (selectedRow.Cells[0].Value.ToString() != "0")
                {
                    session = new Session()
                    {
                        Id = int.Parse(selectedRow.Cells[0].Value.ToString())
                    };
                }
            }
        }
 public void LoadData()
 {
     try
     {
         if (model != null)
         {
             _sessionService = new SessionService();
             model           = _sessionService.GetById(model.Id);
             if (model != null)
             {
                 txtCode.Text = model.Code;
                 txtName.Text = model.Name;
             }
         }
     }
     catch (Exception)
     {
         throw;
     }
     finally
     {
         _sessionService = null;
     }
 }
 public SessionDetailForm(DataService.Model.Session inputModel)
 {
     this.model = inputModel;
     InitializeComponent();
     LoadData();
 }