Example #1
0
        private void btnLuu_Click(object sender, EventArgs e)
        {
            if (txtMasothu.Text == "")
            {
                MessageBox.Show("Bạn chưa nhập mã số thu!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtMasothu.Focus();
                return;
            }
            if (cmbMasothue.SelectedIndex == -1)
            {
                MessageBox.Show("Bạn chưa chọn mã thuê nhà!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (txtNam.Text == "")
            {
                MessageBox.Show("Bạn chưa nhập năm!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtNam.Focus();
                return;
            }

            string strThang = "";

            if (chk1.Checked == true)
            {
                strThang += chk1.Text + "_";
            }
            if (chk2.Checked == true)
            {
                strThang += chk2.Text + "_";
            }
            if (chk3.Checked == true)
            {
                strThang += chk3.Text + "_";
            }
            if (chk4.Checked == true)
            {
                strThang += chk4.Text + "_";
            }
            if (chk5.Checked == true)
            {
                strThang += chk5.Text + "_";
            }
            if (chk6.Checked == true)
            {
                strThang += chk6.Text + "_";
            }
            if (chk7.Checked == true)
            {
                strThang += chk7.Text + "_";
            }
            if (chk8.Checked == true)
            {
                strThang += chk8.Text + "_";
            }
            if (chk9.Checked == true)
            {
                strThang += chk9.Text + "_";
            }
            if (chk10.Checked == true)
            {
                strThang += chk10.Text + "_";
            }
            if (chk11.Checked == true)
            {
                strThang += chk11.Text + "_";
            }
            if (chk12.Checked == true)
            {
                strThang += chk12.Text + "_";
            }
            if (strThang == "")
            {
                MessageBox.Show("Bạn chưa chọn tháng!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (txtNguoithu.Text == "")
            {
                MessageBox.Show("Bạn chưa nhập người thu!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtNguoithu.Focus();
                return;
            }
            if (dtpNgaythu.Text == "")
            {
                MessageBox.Show("Bạn phải nhập ngày thu", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                dtpNgaythu.Focus();
                return;
            }
            string sql = "select * from tblThuTienNha where Masothu = '" + txtMasothu.Text.Trim() + "'";

            DAO.OpenConnection();
            if (DAO.CheckKeyExit(sql))
            {
                MessageBox.Show("Mã số thu đã tồn tại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                DAO.CloseConnection();
                txtMasothu.Focus();
                return;
            }
            else
            {
                sql = "insert into tblThuTienNha (Masothu,Masothue,Thang,Nam,Tongtien,Nguoithu,Ngaythu,Ghichu) " +
                      " values ('" + txtMasothu.Text.Trim() + "','" + cmbMasothue.SelectedValue.ToString() + "',N'"
                      + strThang.ToString() + "'," + txtNam.Text.Trim() + "," + txtTongtien.Text.Trim() + ",N'" + txtNguoithu.Text.Trim()
                      + "',N'" + DAO.ConvertDateTime(dtpNgaythu.Text.ToString()) + "',N'" + txtGhichu.Text.Trim() + "')";
                SqlCommand cmd = new SqlCommand(sql, DAO.con);
                cmd.ExecuteNonQuery();
                DAO.CloseConnection();
                loadDataGridView();
            }
        }
Example #2
0
        private void btnSua_Click(object sender, EventArgs e)
        {
            if (txtMasothu.Text == "")
            {
                MessageBox.Show("Bạn chưa nhập mã số thu!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtMasothu.Focus();
                return;
            }
            if (cmbMasothue.SelectedIndex == -1)
            {
                MessageBox.Show("Bạn chưa chọn mã thuê nhà!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            string strThang = "";

            if (chk1.Checked == true)
            {
                strThang += chk1.Text + "_";
            }
            if (chk2.Checked == true)
            {
                strThang += chk2.Text + "_";
            }
            if (chk3.Checked == true)
            {
                strThang += chk3.Text + "_";
            }
            if (chk4.Checked == true)
            {
                strThang += chk4.Text + "_";
            }
            if (chk5.Checked == true)
            {
                strThang += chk5.Text + "_";
            }
            if (chk6.Checked == true)
            {
                strThang += chk6.Text + "_";
            }
            if (chk7.Checked == true)
            {
                strThang += chk7.Text + "_";
            }
            if (chk8.Checked == true)
            {
                strThang += chk8.Text + "_";
            }
            if (chk9.Checked == true)
            {
                strThang += chk9.Text + "_";
            }
            if (chk10.Checked == true)
            {
                strThang += chk10.Text + "_";
            }
            if (chk11.Checked == true)
            {
                strThang += chk11.Text + "_";
            }
            if (chk12.Checked == true)
            {
                strThang += chk12.Text + "_";
            }
            if (strThang == "")
            {
                MessageBox.Show("Bạn chưa chọn tháng!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (txtNam.Text == "")
            {
                MessageBox.Show("Bạn chưa nhập năm!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtNam.Focus();
                return;
            }
            if (txtNguoithu.Text == "")
            {
                MessageBox.Show("Bạn chưa nhập người thu!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtNguoithu.Focus();
                return;
            }
            if (dtpNgaythu.Text == "")
            {
                MessageBox.Show("Bạn phải nhập ngày thu", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                dtpNgaythu.Focus();
                return;
            }

            string sql = "UPDATE tblThuTienNha SET  Masothue='" + cmbMasothue.SelectedValue.ToString() +
                         "',Thang =N'" + strThang + "',Nam=" + txtNam.Text.Trim() + ",Tongtien=" +
                         txtTongtien.Text.Trim() + ",Nguoithu=N'" + txtNguoithu.Text.Trim() +
                         "',Ngaythu=N'" + DAO.ConvertDateTime(dtpNgaythu.Value.ToString("MM/dd/yyyy")) +
                         "',Ghichu=N'" + txtGhichu.Text.Trim() + "' WHERE Masothu=N'" + txtMasothu.Text.Trim() + "'";

            DAO.OpenConnection();
            SqlCommand cmd = new SqlCommand();

            cmd.CommandText = sql;
            cmd.Connection  = DAO.con;
            cmd.ExecuteNonQuery();
            loadDataGridView();
            DAO.CloseConnection();
        }