private void btnAdd_Click(object sender, EventArgs e)
        {
            try
            {
                if (!Validate()) return;
                // Validate
                var check = new tblCheck();
                check.CheckCode = txtCode.Text;
                check.PlateNumber = StringUtil.RemoveAllNonAlphanumericString(txtPlateNumber.Text).ToUpper();
                if (txtDeclarationNumber.Text != "")
                {
                    check.DeclarationNumber = Convert.ToInt32(txtDeclarationNumber.Text);    
                }
                
                check.CompanyCode = txtCompanyCode.Text;                
                check.DeclarationType = comboBoxDeclarationType.SelectedIndex;
                var from = new DateTime(dtpFrom.Value.Year, dtpFrom.Value.Month, dtpFrom.Value.Day, 0, 0, 0);
                var to = new DateTime(dtpTo.Value.Year, dtpTo.Value.Month, dtpTo.Value.Day, 23, 59, 59);
                check.CheckFrom = from;
                check.CheckTo = to;
                check.CreatedBy = _userInfo.UserID;
                check.ModifiedBy = _userInfo.UserID;
                CheckFactory.Insert(check);

                // Bind data to the owner form
                ((FrmListCheck)this.Owner).InitData();
                this.Close();
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToString());
                if (GlobalInfo.IsDebug) MessageBox.Show(ex.ToString());
            }
        }
 public static int Insert(tblCheck check)
 {
     var db = new dbEcustomEntities(Common.Decrypt(ConfigurationManager.ConnectionStrings["dbEcustomEntities"].ConnectionString, true));
     check.CreateDate = CommonFactory.GetCurrentDate();
     check.ModifedDate = CommonFactory.GetCurrentDate();
     db.AddTotblChecks(check);
     int re = db.SaveChanges();
     db.Connection.Close();
     return re;
 }
 public static int Update(tblCheck check)
 {
     check.ModifedDate = CommonFactory.GetCurrentDate();
     var db = new dbEcustomEntities(Common.Decrypt(ConfigurationManager.ConnectionStrings["dbEcustomEntities"].ConnectionString, true));
     var checkOrgin = db.tblChecks.Where(g => g.CheckID == check.CheckID).FirstOrDefault();
     if (checkOrgin == null) return -1;
     db.Attach(checkOrgin);
     db.ApplyPropertyChanges("tblChecks", check);
     int re = db.SaveChanges();
     db.Connection.Close();
     return re;
 }