public static int Update(tblType typeObj)
        {
            dbEcustomEntities _db = new dbEcustomEntities(Common.Decrypt(ConfigurationManager.ConnectionStrings["dbEcustomEntities"].ConnectionString, true));
            _db.Connection.Open();

            tblType originType = _db.tblTypes.Where(g => g.TypeCode == typeObj.TypeCode).FirstOrDefault();

            if (originType == null)
            {
                return -1;
            }

            originType.TypeName = typeObj.TypeName;
            originType.Description = typeObj.Description;
            originType.ModifiedBy = typeObj.ModifiedBy;
            originType.ModifiedDate = CommonFactory.GetCurrentDate();

            try
            {
                return _db.SaveChanges();
            }
            catch (Exception ex)
            {
                return -1;
            }
            finally
            {
                _db.Connection.Close();
            }
        }
 public static int Insert(tblType type)
 {
     dbEcustomEntities _db = new dbEcustomEntities(Common.Decrypt(ConfigurationManager.ConnectionStrings["dbEcustomEntities"].ConnectionString, true));
     _db.Connection.Open();
     type.CreatedDate = CommonFactory.GetCurrentDate();
     type.ModifiedDate = CommonFactory.GetCurrentDate();
     _db.AddTotblTypes(type);
     try
     {
         if (_db.Connection.State == ConnectionState.Closed) _db.Connection.Open();
         return _db.SaveChanges();
     }
     catch (Exception ex)
     {
         return -1;
     }
     finally
     {
         _db.Connection.Close();
     }
 }
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (_mode == 0)
            {
                //validate
                if (validate())
                {
                    tblType type = new tblType();
                    type.TypeCode = txtTypeCode.Text;
                    type.TypeName = txtTypeName.Text.Trim();
                    type.Description = txtDescription.Text.Trim();
                    type.CreatedBy = _userInfo.UserID;
                    type.ModifiedBy = _userInfo.UserID;
                    if (TypeFactory.Insert(type) > 0)
                    {
                        try
                        {
                            _frmListType.init();
                        }
                        catch (Exception ex)
                        {
                            //do nothing
                        }
                        MessageBox.Show("Thêm mới loại hình thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        reset();
                    }
                    else
                    {
                        MessageBox.Show("Thêm mới loại hình không thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }

            

        }
        private void frmReport_Load(object sender, EventArgs e)
        {
            this.Location = new Point((_mainForm.Width - this.Width) / 2, (_mainForm.Height - this.Height) / 2);
            var list = new List<tblCustom>();
            var custom = new tblCustom {CustomsCode = "0", CustomsName = "Tất cả"};
            list.Add(custom);

            //tao danh sach don vi hai quan
            var listtblCustoms = CustomsFacory.getAll();
            list.AddRange(listtblCustoms.Select(item => new tblCustom {CustomsCode = item.CustomsCode.Trim(), CustomsName = item.CustomsName}));

            cbUnit.DisplayMember = "CustomsName";
            cbUnit.ValueMember = "CustomsCode";
            cbUnit.DataSource = list;
            if (FDHelper.RgGetSizeOfUnit() == ConstantInfo.Branch)
            {
                String unitCode= FDHelper.RgCodeOfUnit();
                cbUnit.SelectedValue = unitCode;
                cbUnit.Enabled = false;
            }

            //tao danh sach loai hinh
            List<tblType> listType = new List<tblType>();
            tblType type = new tblType();
            type.TypeCode = "";
            type.TypeName = "Tất cả";
            listType.Add(type);
            foreach (tblType obj in TypeFactory.getAllType())
            {
                tblType typeObj = new tblType();
                typeObj.TypeName = obj.TypeCode + " - " + obj.TypeName;
                typeObj.TypeCode = obj.TypeCode;
                listType.Add(typeObj);
            }
            cbType.DisplayMember = "TypeName";
            cbType.ValueMember = "TypeCode";
            cbType.DataSource = listType;
         }