public static int Update(tblVehicleType vehicletype)
 {
     var _db = new dbEcustomEntities(Common.Decrypt(ConfigurationManager.ConnectionStrings["dbEcustomEntities"].ConnectionString, true));
     _db.Connection.Open();
     var _vehicletype = (from vt in _db.tblVehicleTypes
                         where vt.VehicleTypeID == vehicletype.VehicleTypeID
                         select vt).First();
     _vehicletype.Name = vehicletype.Name;
     _vehicletype.Capacity = vehicletype.Capacity;
     _vehicletype.Description = vehicletype.Description;
     vehicletype.UpdatedDate = CommonFactory.GetCurrentDate();
     try
     {
         if (_db.Connection.State == ConnectionState.Closed) _db.Connection.Open();
         _db.SaveChanges();
     }
     catch (Exception ex)
     {
         return 1;
     }
     finally
     {
         if (_db.Connection.State == ConnectionState.Closed) _db.Connection.Open();
         _db.Connection.Close();
     }
     return 0;
 }
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (validateAddNew() == false)
            {
                return;
            }
            try
            {
                tblVehicleType vehicleType = new tblVehicleType();
                vehicleType.Name = txtName.Text.Trim();
                vehicleType.Code = txtCode.Text.Trim();
                vehicleType.Capacity = txtCapacity.Text.Trim();
                vehicleType.Description = txtDescription.Text.Trim();
                vehicleType.CreatedUser = _userInfo.UserID;
                vehicleType.UpdatedUser = _userInfo.UserID;

                int result = VehicleTypeFactory.Insert(vehicleType);
                if (result == 0)
                {
                    MessageBox.Show("Thêm mới thành công");
                    txtCapacity.Text = "";
                    txtCode.Text = "";
                    txtDescription.Text = "";
                    txtName.Text = "";
                    frmMainForm mainForm = (frmMainForm)this.MdiParent;
                    Form[] listForm = mainForm.MdiChildren;
                    foreach (Form form in listForm)
                    {
                        if (form.GetType() == new frmListVehicleType().GetType())
                        {
                            ((frmListVehicleType)form).init();
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Dữ liệu không hợp lệ. Thêm mới không thành công.");
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToString());
                if (GlobalInfo.IsDebug) MessageBox.Show(ex.ToString());
            }
        }
 public static int Insert(tblVehicleType vehicletype)
 {
     dbEcustomEntities _db = new dbEcustomEntities(Common.Decrypt(ConfigurationManager.ConnectionStrings["dbEcustomEntities"].ConnectionString, true));
     _db.Connection.Open();
     vehicletype.CreatedDate = CommonFactory.GetCurrentDate();
     vehicletype.UpdatedDate = CommonFactory.GetCurrentDate();
     _db.AddTotblVehicleTypes(vehicletype);
     try
     {
         if (_db.Connection.State == ConnectionState.Closed) _db.Connection.Open();
         _db.SaveChanges();
     }
     catch (Exception ex)
     {
         return 1;
     }
     finally
     {
         _db.Connection.Close();
     }
     return 0;
 }