Example #1
0
        private void btnSua_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            string maGT = txtMaGiaThue.EditValue.ToString().Trim();

            try
            {
                int     gia = int.Parse(txtGia.EditValue.ToString().Trim());
                GiaThue gt  = new GiaThue()
                {
                    MaGiaThue = maGT,
                    Gia       = gia,
                };

                if (giaThue.SuaGiaThue(gt))
                {
                    MessageBox.Show("Sửa thành công: " + maGT, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    FrmGiaThue_Load(null, null);
                }
                else
                {
                    MessageBox.Show("Sửa không thành công: " + maGT, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    FrmGiaThue_Load(null, null);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Sửa không thành công: " + maGT, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                var error = ex;
                FrmGiaThue_Load(null, null);
            }
        }
 public bool SuaGiaThue(GiaThue gt)
 {
     try
     {
         GiaThue giaThue = db.GiaThues.Where(t => t.MaGiaThue == gt.MaGiaThue).FirstOrDefault();
         giaThue.Gia = gt.Gia;
         db.SubmitChanges();
         return(true);
     }
     catch (Exception ex)
     {
         var error = ex;
         return(false);
     }
 }
Example #3
0
        private void btnLuu_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            string maGT = txtMaGiaThue.EditValue.ToString().Trim();

            if (string.IsNullOrEmpty(txtTenGiaThue.EditValue.ToString().Trim()))
            {
                MessageBox.Show("Không được để trống tên giá thuê", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtTenGiaThue.Focus();
            }
            else if (string.IsNullOrEmpty(txtGia.EditValue.ToString().Trim()))
            {
                MessageBox.Show("Không được để trống giá thuê", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtGia.Focus();
            }
            else
            {
                string   tenGT       = txtTenGiaThue.EditValue.ToString().Trim();
                int      gia         = int.Parse(txtGia.EditValue.ToString().Trim());
                DateTime ngayCapNhat = DateTime.Now;
                try
                {
                    GiaThue gt = new GiaThue
                    {
                        MaGiaThue   = maGT,
                        TenGiaThue  = tenGT,
                        Gia         = gia,
                        NgayCapNhat = ngayCapNhat,
                    };

                    if (giaThue.ThemGiaThue(gt))
                    {
                        MessageBox.Show("Thêm giá thuê: " + maGT + " thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        FrmGiaThue_Load(null, null);
                    }
                    else
                    {
                        MessageBox.Show("Thêm giá thuê: " + maGT + " không thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        FrmGiaThue_Load(null, null);
                    }
                }
                catch (Exception ex)
                {
                    var er = ex;
                    MessageBox.Show("Thêm giá thuê: " + maGT + " không thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    FrmGiaThue_Load(null, null);
                }
            }
        }
 // Thêm sửa giá thuê
 public bool ThemGiaThue(GiaThue gt)
 {
     try
     {
         GiaThue giaThue = new GiaThue
         {
             MaGiaThue   = gt.MaGiaThue,
             TenGiaThue  = gt.TenGiaThue,
             Gia         = gt.Gia,
             NgayCapNhat = gt.NgayCapNhat,
         };
         db.GiaThues.InsertOnSubmit(giaThue);
         db.SubmitChanges();
         return(true);
     }
     catch (Exception ex)
     {
         var error = ex;
         return(false);
     }
 }
 public bool XoaGiaThue(string maGiaThue)
 {
     try
     {
         // Kiểm tra mã giá thuê có tồn tại trong bảng mặt bằng chưa ?
         if (db.MatBangs.Where(t => t.Gia == maGiaThue).Count() == 0)
         {
             GiaThue gt = db.GiaThues.Where(t => t.MaGiaThue == maGiaThue).FirstOrDefault();
             db.GiaThues.DeleteOnSubmit(gt);
             db.SubmitChanges();
             return(true);
         }
         else
         {
             return(false);
         }
     }
     catch (Exception ex)
     {
         var error = ex;
         return(false);
     }
 }
 public bool SuaGiaThue(GiaThue gt)
 {
     return(db.SuaGiaThue(gt));
 }
 public bool ThemGiaThue(GiaThue gt)
 {
     return(db.ThemGiaThue(gt));
 }
        public int TinhTienThue(int dientich)
        {
            GiaThue gia = db.GiaThues.Select(t => t).OrderByDescending(t => t.MaGiaThue).FirstOrDefault();

            return((int)(gia.Gia * dientich * 12));
        }