Example #1
0
        private void DataGridViewChiTiet_CellDoubleClick_1(object sender, DataGridViewCellEventArgs e)
        {
            string Mabinhxoa, sql;
            Double ThanhTienxoa, SoLuongxoa, sl, slcon, tong, tongmoi;

            //if ( DM_Binh_ga.Rows.Count == 0)
            //{
            // MessageBox.Show("Không có dữ liệu!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
            //return;
            //}
            if ((MessageBox.Show("Bạn có chắc chắn muốn xóa không?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes))
            {
                //Xóa hàng và cập nhật lại số lượng hàng
                Mabinhxoa    = DataGridViewChiTiet.CurrentRow.Cells["Mabinh"].Value.ToString();
                SoLuongxoa   = Convert.ToDouble(DataGridViewChiTiet.CurrentRow.Cells["SoLuong"].Value.ToString());
                ThanhTienxoa = Convert.ToDouble(DataGridViewChiTiet.CurrentRow.Cells["ThanhTien"].Value.ToString());
                sql          = "DELETE Chi_tiet_hoa_don_ban WHERE SoHDB=N'" + txtSoHDB.Text + "' AND Mabinh = N'" + Mabinhxoa + "'";
                DAO.RunSql(sql);
                // Cập nhật lại số lượng cho các mặt hàng
                sl    = Convert.ToDouble(DAO.GetFieldValues("SELECT Soluong FROM DM_Binh_ga WHERE Mabinh = N'" + Mabinhxoa + "'"));
                slcon = sl + SoLuongxoa;
                sql   = "UPDATE DM_Binh_ga SET Soluong =" + slcon + " WHERE Mabinh= N'" + Mabinhxoa + "'";
                DAO.RunSql(sql);
                // Cập nhật lại tổng tiền cho hóa đơn bán
                tong    = Convert.ToDouble(DAO.GetFieldValues("SELECT TongTien FROM Hoa_don_ban WHERE SoHDB = N'" + txtSoHDB.Text + "'"));
                tongmoi = tong - ThanhTienxoa;
                sql     = "UPDATE Hoa_don_ban SET Tongtien =" + tongmoi + " WHERE SoHDB = N'" + txtSoHDB.Text + "'";
                DAO.RunSql(sql);
                txtTongtien.Text = tongmoi.ToString();
                labelChuyen.Text = "Bằng chữ: " + DAO.ChuyenSoSangChu(tongmoi.ToString());
                txtTongtien.Text = tongmoi.ToString();
                Load_DataGridViewChitiet();
            }
        }
Example #2
0
        private void btnXoa_Click_1(object sender, EventArgs e)
        {
            double sl, slcon, slxoa;

            if (MessageBox.Show("Bạn có chắc chắn muốn xóa không?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                string    sql        = "SELECT Mabinh,Soluong FROM Chi_tiet_hoa_don_ban WHERE SoHDB = N'" + txtSoHDB.Text + "'";
                DataTable DM_Binh_ga = DAO.GetDataToTable(sql);
                for (int hang = 0; hang <= DM_Binh_ga.Rows.Count - 1; hang++)
                {
                    // Cập nhật lại số lượng cho các mặt hàng
                    sl    = Convert.ToDouble(DAO.GetFieldValues("SELECT SoLuong FROM DM_Binh_ga WHERE Mabinh = N'" + DM_Binh_ga.Rows[hang][0].ToString() + "'"));
                    slxoa = Convert.ToDouble(DM_Binh_ga.Rows[hang][1].ToString());
                    slcon = sl + slxoa;
                    sql   = "UPDATE DM_Binh_ga SET Soluong =" + slcon + " WHERE Mabinh= N'" + DM_Binh_ga.Rows[hang][0].ToString() + "'";
                    DAO.RunSql(sql);
                }

                //Xóa chi tiết hóa đơn
                sql = "DELETE Chi_tiet_hoa_don_ban WHERE SoHDB=N'" + txtSoHDB.Text + "'";
                DAO.RunSqlDel(sql);

                //Xóa hóa đơn
                sql = "DELETE Hoa_don_ban WHERE SoHDB=N'" + txtSoHDB.Text + "'";
                DAO.RunSqlDel(sql);
                ResetValues();
                Load_DataGridViewChitiet();
                btnXoa.Enabled = false;
            }
        }
Example #3
0
        private void btnHuy_Click(object sender, EventArgs e)
        {
            double sl, slcon, slxoa;

            if (MessageBox.Show("Bạn có chắc chắn muốn xóa không?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                string    sql        = "SELECT Mabinh,SoLuong FROM chi_tiet_hoa_don_nhap WHERE SoHDN = N'" + txtSoHDN.Text + "'";
                DataTable DM_Binh_ga = DAO.GetDataToTable(sql);
                for (int ga = 0; ga <= DM_Binh_ga.Rows.Count - 1; ga++)
                {
                    // Cập nhật lại số lượng cho các loại ga
                    sl    = Convert.ToDouble(DAO.GetFieldValues("SELECT SoLuong FROM DM_Binh_ga WHERE Mabinh = N'" + DM_Binh_ga.Rows[ga][0].ToString() + "'"));
                    slxoa = Convert.ToDouble(DM_Binh_ga.Rows[ga][1].ToString());
                    slcon = sl - slxoa;
                    sql   = "UPDATE DM_Binh_ga SET SoLuong =" + slcon + " WHERE Mabinh= N'" + DM_Binh_ga.Rows[ga][0].ToString() + "'";
                    DAO.RunSql(sql);
                }

                //Xóa chi tiết hóa đơn
                sql = "DELETE Chi_tiet_hoa_don_nhap WHERE SoHDN=N'" + txtSoHDN.Text + "'";
                DAO.RunSqlDel(sql);

                //Xóa hóa đơn
                sql = "DELETE hoa_don_nhap WHERE SoHDN=N'" + txtSoHDN.Text + "'";
                DAO.RunSqlDel(sql);
                ResetValues();
                LoadDataGridView();
            }
        }
Example #4
0
 private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
 {
     string sql = "select sum(thanhtien) from  hoa_don_ban JOIN dbo.Chi_tiet_hoa_don_ban "
               + " ON hoa_don_ban.sohdb = chi_tiet_hoa_don_ban.sohdb" +
         "  where makhach='" + dataGridView1.CurrentRow.Cells["mak"] + "'";
     labeltongtien.Text = DAO.GetFieldValues(sql);
 }
Example #5
0
        private void DataGridView_hdn_DoubleClick(object sender, EventArgs e)
        {
            DAO.OpenConnection();
            string mabinhxoa, sql;
            Double thanhtienxoa, soluongxoa, sl, slcon, tong, tongmoi;

            if ((MessageBox.Show("Bạn có chắc chắn muốn xóa không?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes))
            {
                //Xóa sách và cập nhật lại số lượng ga
                mabinhxoa    = DataGridView_hdn.CurrentRow.Cells["Mabinh"].Value.ToString();
                soluongxoa   = Convert.ToDouble(DataGridView_hdn.CurrentRow.Cells["SoLuong"].Value.ToString());
                thanhtienxoa = Convert.ToDouble(DataGridView_hdn.CurrentRow.Cells["Thanhtien"].Value.ToString());
                sql          = "DELETE chi_tiet_hoa_don_nhap WHERE SoHDN =N'" + txtSoHDN.Text + "' AND Mabinh = N'" + mabinhxoa + "'";
                DAO.RunSql(sql);

                // Cập nhật lại số lượng cho các loại bình
                sl    = Convert.ToDouble(DAO.GetFieldValues("SELECT SoLuong FROM DM_binh_ga WHERE Mabinh = N'" + mabinhxoa + "'"));
                slcon = sl - soluongxoa;
                sql   = "UPDATE DM_binh_ga SET SoLuong =" + slcon + " WHERE Mabinh= N'" + mabinhxoa + "'";
                DAO.RunSql(sql);

                // Cập nhật lại tổng tiền cho hóa đơn nhập
                tong    = Convert.ToDouble(DAO.GetFieldValues("SELECT TongTien FROM hoa_don_nhap WHERE SoHDN = N'" + txtSoHDN.Text + "'"));
                tongmoi = tong - thanhtienxoa;
                sql     = "UPDATE hoa_don_nhap SET TongTien =" + tongmoi + " WHERE SoHDN = N'" + txtSoHDN.Text + "'";
                DAO.RunSql(sql);
                txtTongtien.Text = tongmoi.ToString();
                lblBangchu.Text  = "Bằng chữ: " + DAO.ChuyenSoSangChu(tongmoi.ToString());
                LoadDataGridView();
            }
        }
Example #6
0
        private void bt_thongke_Click_1(object sender, EventArgs e)
        {
            if (text_nam.Text == "")
            {
                MessageBox.Show("bạn phải nhập năm báo cáo");
                text_nam.Focus();
                return;
            }
            if (comboBox1.SelectedIndex == -1)
            {
                MessageBox.Show("bạn phải chọn mã nhà cung cấp");
            }
            DAO.OpenConnection();
            string sql = "select Chi_tiet_hoa_don_nhap.SoHDN,NgayNhap, nha_cc.MaNCC,TenNCC," +
                         "Dienthoai,Mabinh,Soluong,GIAMGIA,Dongia,Thanhtien from Nha_cc join Hoa_don_nhap on " +
                         "Nha_cc.MaNCC = Hoa_don_nhap.MaNCC join Chi_tiet_hoa_don_nhap " +
                         "on Hoa_don_nhap.SoHDN = Chi_tiet_hoa_don_nhap.SoHDN where month(ngaynhap)='"
                         + numeric_thang.Value + "' and year(ngaynhap)='" + text_nam.Text + "'" +
                         "AND nha_cc.mancc='" + comboBox1.SelectedValue + "'";

            DAO.loatdata(sql, datagridview_DSHDN);
            // LBTONG=
            string sql1 = "select sum(thanhtien)  from Nha_cc join Hoa_don_nhap on " +
                          "Nha_cc.MaNCC = Hoa_don_nhap.MaNCC join Chi_tiet_hoa_don_nhap " +
                          "on Hoa_don_nhap.SoHDN = Chi_tiet_hoa_don_nhap.SoHDN  where month(ngaynhap)='"
                          + numeric_thang.Value + "' and year(ngaynhap)='" + text_nam.Text + "' and " +
                          " hoa_don_nhap.mancc='" + comboBox1.SelectedValue + "'";

            LBTONG.Text = DAO.GetFieldValues(sql1);
            DAO.CloseConnection();
        }
Example #7
0
        private void cmbMaNV_SelectedIndexChanged_1(object sender, EventArgs e)
        {
            string str;

            if (cmbMaNV.Text == "")
            {
                txtTenNV.Text = "";
            }
            //
            str           = "select TenNV from nhan_vien where MaNV = N'" + cmbMaNV.SelectedValue + "'";
            txtTenNV.Text = DAO.GetFieldValues(str);
        }
Example #8
0
        private void LoadInfoHoaDon()
        {
            string str;

            str              = "SELECT NgayBan FROM Hoa_don_ban WHERE SoHDB = N'" + txtSoHDB.Text + "'";
            txtNgayBan.Text  = DAO.ConvertDateTime(DAO.GetFieldValues(str));
            str              = "SELECT MaNV FROM Hoa_don_ban  WHERE SoHDB = N'" + txtSoHDB.Text + "'";
            cmbMaNV.Text     = DAO.GetFieldValues(str);
            str              = "SELECT Makhach FROM Hoa_don_ban WHERE SoHDB = N'" + txtSoHDB.Text + "'";
            cmbMaKH.Text     = DAO.GetFieldValues(str);
            str              = "SELECT Tongtien FROM Hoa_don_ban WHERE SoHDB = N'" + txtSoHDB.Text + "'";
            txtTongtien.Text = DAO.GetFieldValues(str);
            labelChuyen.Text = "Bằng chữ: " + DAO.ChuyenSoSangChu(txtTongtien.Text);
        }
Example #9
0
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            DAO.OpenConnection();
            string str;

            if (comboBox1.Text == "")
            {
                textBoxtenncc.Text = "";
            }

            str = "Select Tenncc from nha_cc where Mancc =N'" + comboBox1.SelectedValue + "'";
            textBoxtenncc.Text = DAO.GetFieldValues(str);
            DAO.CloseConnection();
        }
Example #10
0
        private void cboManhanvien_SelectedIndexChanged(object sender, EventArgs e)
        {
            DAO.OpenConnection();
            string str;

            if (cboManhanvien.Text == "")
            {
                txtTennhanvien.Text = "";
            }
            // Khi chọn Mã nhân viên thì tên nhân viên tự động hiện ra
            str = "Select TenNV from nhan_vien where MaNV =N'" + cboManhanvien.SelectedValue + "'";
            txtTennhanvien.Text = DAO.GetFieldValues(str);
            DAO.CloseConnection();
        }
Example #11
0
        private void LoadInfoHoadon()
        {
            string str;

            str = "SELECT MaNV FROM hoa_don_nhap WHERE SoHDN = N'" + txtSoHDN.Text + "'";
            cboManhanvien.Text = DAO.GetFieldValues(str);
            str = "SELECT NgayNhap FROM hoa_don_nhap WHERE SoHDN = N'" + txtSoHDN.Text + "'";
            txtNgaynhap.Text = DAO.ConvertDateTime(DAO.GetFieldValues(str));
            str              = "SELECT MaNCC FROM hoa_don_nhap WHERE SoHDN = N'" + txtSoHDN.Text + "'";
            cboMaNCC.Text    = DAO.GetFieldValues(str);
            str              = "SELECT TongTien FROM hoa_don_nhap WHERE SoHDN = N'" + txtSoHDN.Text + "'";
            txtTongtien.Text = DAO.GetFieldValues(str);
            lblBangchu.Text  = "Bằng chữ: " + DAO.ChuyenSoSangChu(txtTongtien.Text);
        }
Example #12
0
        private void cboMabinh_SelectedIndexChanged(object sender, EventArgs e)
        {
            string str;

            if (cboMabinh.Text == "")
            {
                txtTenbinh.Text = "";
                txtDongia.Text  = "";
            }
            // Khi chọn mã binh  thì các thông tin về hàng hiện ra
            str             = "SELECT Tenbinh FROM DM_binh_ga WHERE Mabinh =N'" + cboMabinh.SelectedValue + "'";
            txtTenbinh.Text = DAO.GetFieldValues(str);
            str             = "SELECT DonGianhap FROM DM_binh_ga WHERE Mabinh =N'" + cboMabinh.SelectedValue + "'";
            txtDongia.Text  = DAO.GetFieldValues(str);
        }
Example #13
0
        private void cmbMabinh_SelectedIndexChanged_1(object sender, EventArgs e)
        {
            DAO.OpenConnection();
            string str;

            if (cmbMabinh.Text == "")
            {
                txtTenbinh.Text = "";
                txtDongia.Text  = "";
            }
            str             = "select tenbinh from DM_Binh_ga where mabinh = N'" + cmbMabinh.SelectedValue + "'";
            txtTenbinh.Text = DAO.GetFieldValues(str);
            str             = "select dongiaban from DM_Binh_ga where mabinh = N'" + cmbMabinh.SelectedValue + "'";
            txtDongia.Text  = DAO.GetFieldValues(str);
        }
Example #14
0
        private void cmbMaKH_SelectedIndexChanged_1(object sender, EventArgs e)
        {
            string str;

            if (cmbMaKH.Text == "")
            {
                txtTenKH.Text     = "";
                txtDiachi.Text    = "";
                txtDienthoai.Text = "";
            }
            str               = "select tenkhach from khach_hang where makhach =N'" + cmbMaKH.SelectedValue + "'";
            txtTenKH.Text     = DAO.GetFieldValues(str);
            str               = "select diachi from khach_hang where makhach =N'" + cmbMaKH.SelectedValue + "'";
            txtDiachi.Text    = DAO.GetFieldValues(str);
            str               = "select dienthoai from khach_hang where makhach =N'" + cmbMaKH.SelectedValue + "'";
            txtDienthoai.Text = DAO.GetFieldValues(str);
        }
Example #15
0
        private void cboMaNCC_SelectedIndexChanged(object sender, EventArgs e)
        {
            string str;

            if (cboMaNCC.Text == "")
            {
                txtTenNCC.Text    = "";
                txtDiachi.Text    = "";
                mskDienthoai.Text = "";
            }
            //Khi chọn Mã nhà cung cấp này thì các thông tin của nhà cung cấp sẽ hiện ra
            str               = "Select TenNCC from nha_cc where MaNCC = N'" + cboMaNCC.SelectedValue + "'";
            txtTenNCC.Text    = DAO.GetFieldValues(str);
            str               = "Select DiaChi from nha_cc where MaNCC = N'" + cboMaNCC.SelectedValue + "'";
            txtDiachi.Text    = DAO.GetFieldValues(str);
            str               = "Select DienThoai from nha_cc where MaNCC= N'" + cboMaNCC.SelectedValue + "'";
            mskDienthoai.Text = DAO.GetFieldValues(str);
        }
Example #16
0
        private void btDangnhap_Click(object sender, EventArgs e)
        {
            if (txtTaikhoan.Text == "")
            {
                MessageBox.Show("Bạn chưa nhập tài khoản");
                txtTaikhoan.Focus();
                return;
            }
            if (txtMatkhau.Text == "")
            {
                MessageBox.Show("Bạn chưa nhập mật khẩu");
                txtMatkhau.Focus();
                return;
            }
            DAO.OpenConnection();

            {
                DataTable tk, tk1;
                //string sql = "select count(*) from taikhoan where taikhoan='" + txtTaikhoan.Text + "' and matkhau='" + txtMatkhau.Text + "'";

                string sql1 = "select * from taikhoan where taikhoan='" + txtTaikhoan.Text + "' and matkhau='" + txtMatkhau.Text + "'";
                DAO.OpenConnection();
                tk = DAO.GetDataToTable(sql1);
                //tk1 = DAO.GetDataToTable(sql);
                // SqlCommand cmd = new SqlCommand(sql, DAO.Conn);
                // SqlDataReader reader = cmd.ExecuteReader();
                if (tk.Rows.Count > 0)
                {
                    this.Hide();
                    Form main = new frmmain();
                    main.Show();
                }
                else
                {
                    string sql = "select matkhau from taikhoan where taikhoan='" + txtTaikhoan.Text + "'";
                    if (txtMatkhau.Text != DAO.GetFieldValues(sql).ToString())
                    {
                        MessageBox.Show("bạn nhập sai mật khẩu hoặc tài khoản không tồn tại,hãy nhập lại");
                        txtMatkhau.Text  = "";
                        txtTaikhoan.Text = "";
                    }
                }
            }
        }
Example #17
0
        private void bt_thongke_Click(object sender, EventArgs e)
        {
            DAO.OpenConnection();
            if (comboBox1.SelectedIndex == -1)
            {
                MessageBox.Show("Bạn chưa nhập tháng");
                comboBox1.Focus();
                return;
            }
            if (comboBox2.SelectedIndex == -1)
            {
                MessageBox.Show("Bạn chưa nhập năm");
                comboBox2.Focus();
                return;
            }
            string sql = "select sum(thanhtien) as tong_tien,DM_binh_ga.dongiaban," +
                         "dm_binh_ga.mabinh,tenbinh,sum(chi_tiet_hoa_don_ban.soluong) as so_luong, ngayban " +

                         "from chi_tiet_Hoa_don_ban join dm_binh_ga on " +
                         "chi_tiet_hoa_don_ban.mabinh = dm_binh_ga.mabinh join hoa_don_ban on hoa_don_ban.sohdb = chi_tiet_hoa_don_ban.sohdb " +
                         " where MONTH(ngayban)=" + comboBox1.SelectedValue + " and YEAR(ngayban)=" + comboBox2.SelectedValue +

                         " group BY dm_binh_ga.mabinh,tenbinh,DM_binh_ga.dongiaban,ngayban ";

            BCDT = DAO.GetDataToTable(sql);
            if (BCDT.Rows.Count == 0)
            {
                MessageBox.Show("không có bản ghi nào thỏa mãn điều kiện", "thông báo",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                MessageBox.Show("có" + BCDT.Rows.Count + "bản ghi thỏa mãn điều kiện", "thông báo",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            DAO.loatdata(sql, dataGridViewdoanhthu);



            labeldoanhthu.Text = DAO.GetFieldValues("SELECT SUM(thanhtien) FROM dbo.Chi_tiet_hoa_don_ban JOIN dbo.Hoa_don_ban ON hoa_don_ban.sohdb = chi_tiet_hoa_don_ban.sohdb  " +
                                                    " where MONTH(ngayban)=" + comboBox1.SelectedValue + " and YEAR(ngayban)=" + comboBox2.SelectedValue);
            DAO.CloseConnection();
        }
Example #18
0
        private void GridViewBinhGas_CellClick_1(object sender, DataGridViewCellEventArgs e)
        {
            DAO.OpenConnection();
            if (btnThem.Enabled == false)
            {
                MessageBox.Show("Đang ở chế độ thêm mới!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtMaBinh.Focus();
                return;
            }

            txtMaBinh.Text     = GridViewBinhGas.CurrentRow.Cells["Mabinh"].Value.ToString();
            txtTenBinh.Text    = GridViewBinhGas.CurrentRow.Cells["Tenbinh"].Value.ToString();
            txtSoLuong.Text    = GridViewBinhGas.CurrentRow.Cells["Soluong"].Value.ToString();
            txtDonGiaNhap.Text = GridViewBinhGas.CurrentRow.Cells["Dongianhap"].Value.ToString();
            txtDonGiaBan.Text  = GridViewBinhGas.CurrentRow.Cells["Dongiaban"].Value.ToString();
            txtTGBH.Text       = GridViewBinhGas.CurrentRow.Cells["Thoigianbaohanh"].Value.ToString();
            txtAnh.Text        = GridViewBinhGas.CurrentRow.Cells["Anh"].Value.ToString();
            txtGhichu.Text     = GridViewBinhGas.CurrentRow.Cells["Ghichu"].Value.ToString();
            cmbKhoiLuong.Text  = GridViewBinhGas.CurrentRow.Cells["Makhoiluong"].Value.ToString();
            cmbMau.Text        = GridViewBinhGas.CurrentRow.Cells["Mamau"].Value.ToString();
            cmbLoaiGas.Text    = GridViewBinhGas.CurrentRow.Cells["Maloai"].Value.ToString();
            cmbNuocSX.Text     = GridViewBinhGas.CurrentRow.Cells["manuocSX"].Value.ToString();

            if (!String.IsNullOrEmpty(txtAnh.Text))
            {
                picAnh.Image = Image.FromFile(txtAnh.Text);
            }

            string sql;
            double gianhap, giaban;

            gianhap = Convert.ToDouble(DAO.GetFieldValues("Select Dongianhap from DM_Binh_ga where Mabinh = N'" + txtMaBinh.Text.Trim() + "'"));
            giaban  = (gianhap * 110) / 100;
            sql     = "UPDATE DM_Binh_ga SET Dongiaban =" + giaban + "where Mabinh =N'" + txtMaBinh.Text.Trim() + "'";
            DAO.RunSql(sql);
            txtDonGiaBan.Text = giaban.ToString();

            btnSua.Enabled    = true;
            btnXoa.Enabled    = true;
            txtMaBinh.Enabled = true;
            DAO.CloseConnection();
        }
Example #19
0
        private void btnLuu_Click_1(object sender, EventArgs e)
        {
            string sql;
            double sl, SLcon, tong, Tongmoi;

            //double giaban, giabanmoi;
            DAO.OpenConnection();
            sql = "SELECT SoHDB FROM Hoa_don_ban WHERE SoHDB=N'" + txtSoHDB.Text + "'";
            if (!DAO.CheckKey(sql))
            {
                if (txtNgayBan.Text.Length == 0)
                {
                    MessageBox.Show("Bạn phải nhập ngày bán", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txtNgayBan.Focus();
                    return;
                }
                if (cmbMaNV.Text.Length == 0)
                {
                    MessageBox.Show("Bạn phải nhập nhân viên", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    cmbMaNV.Focus();
                    return;
                }
                if (cmbMaKH.Text.Length == 0)
                {
                    MessageBox.Show("Bạn phải nhập khách hàng", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    cmbMaKH.Focus();
                    return;
                }
                sql = "INSERT INTO hoa_don_ban(SoHDB, MaNV, Ngayban, makhach, TongTien) VALUES(N'" + txtSoHDB.Text.Trim() + "', N'" + cmbMaNV.SelectedValue + "', N'" +

                      txtNgayBan.Text.Trim() + "',N'" +
                      cmbMaKH.SelectedValue + "'," + txtTongtien.Text + ")";
                //MessageBox.Show(sql);
                DAO.RunSql(sql);
            }
            // Lưu thông tin của các mặt hàng
            if (cmbMabinh.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn phải nhập mã hàng", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                cmbMabinh.Focus();
                return;
            }
            if ((txtSoluong.Text.Trim().Length == 0) || (txtSoluong.Text == "0"))
            {
                MessageBox.Show("Bạn phải nhập số lượng", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtSoluong.Text = "";
                txtSoluong.Focus();
                return;
            }
            if (txtGiamgia.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn phải nhập giảm giá", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtGiamgia.Focus();
                return;
            }
            sql = "SELECT Mabinh FROM Chi_tiet_hoa_don_ban WHERE Mabinh=N'" + cmbMabinh.SelectedValue + "' AND SoHDB = N'" + txtSoHDB.Text.Trim() + "'";
            if (DAO.CheckKey(sql))
            {
                MessageBox.Show("Mã hàng này đã có, bạn phải nhập mã khác", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                ResetValuesHang();
                cmbMabinh.Focus();
                return;
            }
            // Kiểm tra xem số lượng hàng trong kho còn đủ để cung cấp không?
            sl = Convert.ToDouble(DAO.GetFieldValues("SELECT SoLuong FROM DM_Binh_ga WHERE Mabinh = N'" + cmbMabinh.SelectedValue + "'"));
            if (Convert.ToDouble(txtSoluong.Text) > sl)
            {
                MessageBox.Show("Số lượng mặt hàng này chỉ còn " + sl, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtSoluong.Text = "";
                txtSoluong.Focus();
                return;
            }
            sql = "INSERT INTO Chi_tiet_hoa_don_ban(SoHDB,Mabinh,Soluong, Giamgia,Thanhtien) VALUES(N'" + txtSoHDB.Text + "',N'"
                  + cmbMabinh.SelectedValue + "'," + txtSoluong.Text + "," + txtGiamgia.Text + "," + txtThanhtien.Text + ")";
            //MessageBox.Show(sql);
            DAO.RunSql(sql);
            Load_DataGridViewChitiet();
            // Cập nhật lại số lượng của mặt hàng vào bảng DM_Binh_ga
            SLcon = sl - Convert.ToDouble(txtSoluong.Text);
            sql   = "UPDATE DM_Binh_ga SET Soluong =" + SLcon + " WHERE Mabinh= N'" + cmbMabinh.SelectedValue + "'";
            DAO.RunSql(sql);

            //Cập nhật lại tổng tiền cho hóa đơn bán


            tong    = Int32.Parse(DAO.GetFieldValues("SELECT tongtien FROM hoa_don_ban WHERE SoHDB = N'" + txtSoHDB.Text + "'"));
            Tongmoi = tong + Convert.ToDouble(txtThanhtien.Text);
            sql     = "UPDATE Hoa_don_ban SET Tongtien =" + Tongmoi + " WHERE SoHDB = N'" + txtSoHDB.Text + "'";
            DAO.RunSql(sql);
            txtTongtien.Text = Tongmoi.ToString();
            labelChuyen.Text = "Bằng chữ: " + DAO.ChuyenSoSangChu(Tongmoi.ToString());
            ResetValuesHang();

            //btnInhoadon = true;
        }
Example #20
0
        private void btnLuu_Click(object sender, EventArgs e)
        {
            DAO.OpenConnection();
            string sql;
            double sl, SLcon, tong, Tongmoi;

            sql = "SELECT SoHDN FROM hoa_don_nhap WHERE SoHDN=N'" + txtSoHDN.Text + "'";
            if (!DAO.CheckKey(sql))
            {
                // Số hóa đơn nhập chưa có, tiến hành lưu các thông tin chung
                // SoHDNhap được sinh tự động do đó không có trường hợp trùng khóa
                if (cboManhanvien.Text.Length == 0)
                {
                    MessageBox.Show("Bạn phải nhập mã nhân viên", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    cboManhanvien.Focus();
                    return;
                }
                if (txtNgaynhap.Text.Length == 0)
                {
                    MessageBox.Show("Bạn phải nhập ngày nhập hàng", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txtNgaynhap.Focus();
                    return;
                }
                if (cboMaNCC.Text.Length == 0)
                {
                    MessageBox.Show("Bạn phải nhập mã nhà cung cấp", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    cboMaNCC.Focus();
                    return;
                }
                sql = "INSERT INTO hoa_don_nhap(SoHDN, MaNV, NgayNhap, MaNCC, TongTien) VALUES (N'" + txtSoHDN.Text.Trim() + "',N'" + cboManhanvien.SelectedValue + "',N'" +
                      DAO.ConvertDateTime(txtNgaynhap.Text.Trim()) + "',N'" +
                      cboMaNCC.SelectedValue + "'," + txtTongtien.Text + ")";

                DAO.RunSql(sql);
            }
            // Lưu thông tin của các mặt hàng
            if (cboMabinh.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn phải nhập mã bình", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                cboMabinh.Focus();
                return;
            }
            if ((txtSoluong.Text.Trim().Length == 0) || (txtSoluong.Text == "0"))
            {
                MessageBox.Show("Bạn phải nhập số lượng", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtSoluong.Text = "";
                txtSoluong.Focus();
                return;
            }
            if (txtGiamgia.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn phải nhập giảm giá", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtGiamgia.Focus();
                return;
            }
            if (txtDongia.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn phải nhập đơn giá nhập", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtDongia.Focus();
                return;
            }
            sql = "SELECT Mabinh FROM chi_tiet_hoa_don_nhap WHERE Mabinh=N'" + cboMabinh.SelectedValue + "' AND SoHDN = N'" + txtSoHDN.Text.Trim() + "'";
            if (DAO.CheckKey(sql))
            {
                MessageBox.Show("Mã bình này đã có, bạn phải nhập mã bình khác", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                ResetValuesHang();
                cboMabinh.Focus();
                return;
            }
            DAO.OpenConnection();
            sql = "INSERT INTO chi_tiet_hoa_don_nhap VALUES(N'" + txtSoHDN.Text.Trim() + "',N'" + cboMabinh.SelectedValue + "'," + txtSoluong.Text + "," + txtDongia.Text + "," + txtGiamgia.Text + "," + txtThanhtien.Text + ")";

            DAO.RunSql(sql);
            LoadDataGridView();


            //cap nhat

            double dgnhap = Convert.ToDouble(txtDongia.Text); // đơn giá nhập

            sl = Convert.ToDouble(DAO.GetFieldValues("SELECT SoLuong FROM DM_binh_ga WHERE mabinh = N'" + cboMabinh.SelectedValue + "'"));
            double slmoi = Convert.ToDouble(txtSoluong.Text);


            sql = "UPDATE DM_binh_ga SET DonGiaNhap=" + dgnhap + "WHERE Mabinh= N'" + cboMabinh.SelectedValue + "'";
            DAO.RunSql(sql);
            sql = "UPDATE DM_binh_ga SET DonGiaBan=" + dgnhap * 1.1 + "WHERE Mabinh= N'" + cboMabinh.SelectedValue + "'";
            DAO.RunSql(sql);

            // Cập nhật lại số lượng ga vào bảng DM Binh ga
            SLcon = sl + slmoi;
            sql   = "UPDATE DM_binh_ga  SET SoLuong =" + SLcon + " WHERE Mabinh= N'" + cboMabinh.SelectedValue + "'";
            DAO.RunSql(sql);

            //Cập nhật lại tổng tiền cho hóa đơn nhập

            tong = Int32.Parse(DAO.GetFieldValues("SELECT TongTien FROM hoa_don_nhap WHERE SoHDN = N'" + txtSoHDN.Text + "'"));

            Tongmoi = tong + Convert.ToDouble(txtThanhtien.Text);
            sql     = "UPDATE hoa_don_nhap SET TongTien =" + Tongmoi + " WHERE SoHDN = N'" + txtSoHDN.Text + "'";
            DAO.RunSql(sql);


            txtTongtien.Text = Tongmoi.ToString();
            lblBangchu.Text  = "Bằng chữ: " + DAO.ChuyenSoSangChu(Tongmoi.ToString());

            LoadDataGridView();
            DAO.CloseConnection();
        }