Exemplo n.º 1
0
        public static bool ThemCTHD(string sStoredProcedue, CTHD_DTO cthd)
        {
            try
            {
                SqlCommand cmd = new SqlCommand();
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = sStoredProcedue;
                cmd.Connection  = KetNoi();

                cmd.Parameters.AddWithValue("@sohd", cthd.SoHD);
                cmd.Parameters.AddWithValue("@tensp", cthd.TenSP);
                cmd.Parameters.AddWithValue("@soluong", cthd.SoLuong);
                cmd.Parameters.AddWithValue("@trigia", (Decimal)cthd.TriGia);


                if (cmd.ExecuteNonQuery() != 0)
                {
                    return(true);
                }
            }
            catch
            {
            }
            return(false);
        }
Exemplo n.º 2
0
        // Lấy danh sách tất cả nhân viên
        public static List <CTHD_DTO> LayDSCTHD()
        {
            //select n.*,c.tenncc from hang n, nhacungcap c where n.mancc=c.mancc
            string sTruyVan = @"select n.*,h.tenh from cthd n, hang h where n.mah=h.mah";

            con = DataProvider.MoKetNoi();
            DataTable dt = DataProvider.TruyVanLayDuLieu(sTruyVan, con);

            if (dt.Rows.Count == 0)
            {
                return(null);
            }
            List <CTHD_DTO> lstCTHD = new List <DTO.CTHD_DTO>();

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                CTHD_DTO cthd = new CTHD_DTO();
                cthd.SMaHD    = dt.Rows[i]["mahd"].ToString();
                cthd.SMaHang  = dt.Rows[i]["mah"].ToString();
                cthd.SSoLuong = int.Parse(dt.Rows[i]["soluong"].ToString());
                cthd.SDonGia  = float.Parse(dt.Rows[i]["dongia"].ToString());
                cthd.SGiamGia = dt.Rows[i]["giamgia"].ToString();
                cthd.STenHang = dt.Rows[i]["tenh"].ToString();
                lstCTHD.Add(cthd);
            }
            DataProvider.DongKetNoi(con);
            return(lstCTHD);
        }
Exemplo n.º 3
0
        private void btnThemMon_Click(object sender, EventArgs e)
        {
            if (txtSoLuong.Text == "")
            {
                MessageBox.Show("Vui lòng nhập số lượng!");
            }
            //Them mon vao cthd
            CTHD_DTO cthd = new CTHD_DTO(int.Parse(lbMHD.Text), lbMon.Text, float.Parse(lbDonGia.Text), int.Parse(txtSoLuong.Text));
            bool     kq   = CTHD_BUS.ThemCTHD(cthd);

            if (kq == false)
            {
                MessageBox.Show("loi!");
            }
            else
            {
                dataGridView3.DataSource = CTHD_BUS.LoadCTHDTheoMHD(int.Parse(lbMHD.Text));
            }
            //hien thi ds
            //cap nhat tong tien
            float tongtien = 0;
            int   dong     = dataGridView3.RowCount;

            for (int i = 0; i < dong; i++)
            {
                tongtien += float.Parse(dataGridView3.Rows[i].Cells[1].Value.ToString()) * float.Parse(dataGridView3.Rows[i].Cells[2].Value.ToString());
            }
            txtTongTien.Text = tongtien.ToString();
        }
Exemplo n.º 4
0
        public bool Insert(CTHD_DTO cthd)
        {
            try
            {
                con.Open();

                string SQL = "Insert into CTHD values(" + cthd.SOHD + "," + cthd.MASP + ","
                             + cthd.SL + ",'" + cthd.GIA + "')";


                SqlCommand cmd = new SqlCommand(SQL, con);
                if (cmd.ExecuteNonQuery() > 0)
                {
                    return(true);
                }
            }

            catch (Exception e)
            { }

            finally
            {
                con.Close();
            }

            return(false);
        }
Exemplo n.º 5
0
        private void bthThem_Click(object sender, EventArgs e)
        {
            // Kiểm tra dữ liệu có bị bỏ trống
            if (numSoLuong.Text == "")
            {
                MessageBox.Show("Vui lòng nhập đầy đủ dữ liệu!");
                return;
            }


            CTHD_DTO cthd = new CTHD_DTO();

            cthd.SMaHD    = cboMaHD.SelectedValue.ToString();
            cthd.SMaHang  = cboMaHang.SelectedValue.ToString();
            cthd.SSoLuong = int.Parse(numSoLuong.Text.ToString());
            cthd.SDonGia  = float.Parse(txtDonGia.Text.ToString());
            cthd.SGiamGia = txtGiamGia.Text;


            if (CTHD_BLL.ThemCTHD(cthd) == false)
            {
                MessageBox.Show("Không thêm được.");
                return;
            }

            HienThiDSCTHDDatagrid();

            MessageBox.Show("Đã thêm chi tiết hóa đơn thành công.");
        }
Exemplo n.º 6
0
        private void btnXoa_Click(object sender, EventArgs e)
        {
            if (cboMaHD.Text == "")
            {
                MessageBox.Show("Vui lòng chọn mã chi tiết cần xóa!");
                return;
            }


            CTHD_DTO cthd = new CTHD_DTO();

            cthd.SMaHD    = cboMaHD.SelectedValue.ToString();
            cthd.SMaHang  = cboMaHang.SelectedValue.ToString();
            cthd.SSoLuong = int.Parse(numSoLuong.Text.ToString());
            cthd.SDonGia  = float.Parse(txtDonGia.Text.ToString());
            cthd.SGiamGia = txtGiamGia.Text;

            if (CTHD_BLL.XoaCTHD(cthd) == false)
            {
                MessageBox.Show("Không xóa được.");
                return;
            }

            HienThiDSCTHDDatagrid();

            MessageBox.Show("Đã xoa thành công.");
        }
Exemplo n.º 7
0
        private void btnSua_Click(object sender, EventArgs e)
        {
            // kiểm tra mã có tồn tại
            if (cboMaHD.Text == "")
            {
                MessageBox.Show("Vui lòng chọn mã chi tiết hóa đơn!");
                return;
            }
            CTHD_DTO cthd = new CTHD_DTO();

            cthd.SMaHD    = cboMaHD.SelectedValue.ToString();
            cthd.SMaHang  = cboMaHang.SelectedValue.ToString();
            cthd.SSoLuong = int.Parse(numSoLuong.Text.ToString());
            cthd.SDonGia  = float.Parse(txtDonGia.Text.ToString());
            cthd.SGiamGia = txtGiamGia.Text;

            if (CTHD_BLL.SuaCTHD(cthd) == true)
            {
                HienThiDSCTHDDatagrid();
                MessageBox.Show("Đã cập nhật thông tin chi tiết hóa đơn.");
            }
            else
            {
                MessageBox.Show("Không cập nhật được.");
            }
        }
Exemplo n.º 8
0
        private void dataCTHD_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                DataGridViewRow row  = dataCTHD.CurrentRow;
                CTHD_DTO        cthd = new CTHD_DTO();
                cthd.SoHD    = int.Parse(row.Cells[0].Value.ToString());
                cthd.TenSP   = row.Cells[1].Value.ToString();
                cthd.SoLuong = int.Parse(row.Cells[2].Value.ToString());
                cthd.TriGia  = int.Parse(row.Cells[3].Value.ToString());

                if (BLL.CTHD_BLL.SuaCTHD(cthd))
                {
                    MessageBox.Show("Sửa thành công", "Thông báo", MessageBoxButtons.OK);
                    MyStatus(cthd.SoHD.ToString());
                }
                else
                {
                    MessageBox.Show("Sửa thành công", "Thông báo", MessageBoxButtons.OK);
                }
                LoadCTHDTheoSoHD(cthd.SoHD);
            }
            catch
            {
            }
            UpdateCTHD();
        }
Exemplo n.º 9
0
        public static bool XoaCTHD(CTHD_DTO cthd)
        {
            string sTruyVan = string.Format(@"delete from cthd where mahd=N'{0}'", cthd.SMaHD);

            con = DataProvider.MoKetNoi();
            bool kq = DataProvider.TruyVanKhongLayDuLieu(sTruyVan, con);

            DataProvider.DongKetNoi(con);
            return(kq);
        }
Exemplo n.º 10
0
        public static bool ThemCTHD(CTHD_DTO cthd)
        {
            string sTruyVan = string.Format(@"insert into cthd values('{0}',N'{1}','{2}','{3}',N'{4}')", cthd.SMaHD, cthd.SMaHang, cthd.SSoLuong, cthd.SDonGia, cthd.SGiamGia);

            con = DataProvider.MoKetNoi();
            bool kq = DataProvider.TruyVanKhongLayDuLieu(sTruyVan, con);

            DataProvider.DongKetNoi(con);
            return(kq);
        }
Exemplo n.º 11
0
        public static bool SuaCTHD(CTHD_DTO cthd)
        {
            //(@"update hdnhang set mancc=N'{0}', manv='{1}', sotien='{2}', datra=N'{3}', conno=N'{4}' where shhd='{5}'", hd.SMaNCC, hd.SMaNV, hd.SSoTien, hd.SDaTra, hd.SConNo, hd.SSHHD);
            string sTruyVan = string.Format(@"update cthd set mah='{0}', soluong='{1}', dongia='{2}', giamgia=N'{3}' where mahd='{4}'", cthd.SMaHang, cthd.SSoLuong, cthd.SDonGia, cthd.SGiamGia, cthd.SMaHD);

            con = DataProvider.MoKetNoi();
            bool kq = DataProvider.TruyVanKhongLayDuLieu(sTruyVan, con);

            DataProvider.DongKetNoi(con);
            return(kq);
        }
Exemplo n.º 12
0
        public static List <CTHD_DTO> LayCTHD(int sohd)
        {
            List <CTHD_DTO> cthd = new List <CTHD_DTO>();

            try
            {
                SqlDataReader reader = DataProvider.LayCTHD("LayCTHDTheoSoHD", sohd);
                while (reader.Read())
                {
                    CTHD_DTO ct = new CTHD_DTO();
                    ct.SoHD    = reader.GetInt32(0);
                    ct.TenSP   = reader.GetString(1);
                    ct.SoLuong = reader.GetByte(2);
                    ct.TriGia  = (int)reader.GetDecimal(3);
                    cthd.Add(ct);
                }
            }
            catch
            {
            }

            return(cthd);
        }
Exemplo n.º 13
0
        public static bool ThemCTHD(CTHD_DTO cthd)
        {
            SqlConnection cnn = ConnectToSQL.HamKetNoi();
            string        str = @"INSERT INTO CTHD(Mahoadon, Tenmon, Dongia, Soluong) VALUES (@Mahoadon, @Tenmon, @Dongia, @Soluong)";
            SqlCommand    cmd = new SqlCommand(str, cnn);

            cmd.CommandType = CommandType.Text;
            cmd.Parameters.Add("@Mahoadon", SqlDbType.Int);
            cmd.Parameters.Add("@Tenmon", SqlDbType.NVarChar, 50);
            cmd.Parameters.Add("@Dongia", SqlDbType.Float);
            cmd.Parameters.Add("@Soluong", SqlDbType.Int);


            cmd.Parameters["@Mahoadon"].Value = cthd.Mahoadon;
            cmd.Parameters["@Tenmon"].Value   = cthd.Tenmon;
            cmd.Parameters["@Dongia"].Value   = cthd.Dongia;
            cmd.Parameters["@Soluong"].Value  = cthd.Soluong;

            cnn.Open();
            cmd.ExecuteNonQuery();
            cnn.Close();

            return(true);
        }
Exemplo n.º 14
0
        private void btnLuuCTHD_Click(object sender, EventArgs e)
        {
            if (status == "ThêmCTHD")
            {
                CTHD_DTO cthd = new CTHD_DTO();
                cthd.SoHD = int.Parse(cbbSoHD_CTHD.Text.Trim());
                //MessageBox.Show(cbbSoHD_CTHD.Text);
                cthd.TenSP = cbbTenSP_CTHD.Text;
                if (txtSoLuong_CTHD.Text.Trim() == "")
                {
                    MessageBox.Show("Phải nhập số lượng sản phẩm", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtSoLuong_CTHD.Focus();
                    return;
                }
                cthd.SoLuong = int.Parse(txtSoLuong_CTHD.Text);
                cthd.TriGia  = 0;
                if (cthd.SoLuong <= 0)
                {
                    MessageBox.Show("Số lượng phải lớn hơn 0", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                if (BLL.CTHD_BLL.ThemCTHD(cthd))
                {
                    MessageBox.Show("Thêm thành công", "Thông báo", MessageBoxButtons.OK);
                    LoadCTHDTheoSoHD(cthd.SoHD);
                    UpdateCTHD();

                    MyStatus(cthd.SoHD.ToString());
                }
                else
                {
                    MessageBox.Show("Thêm thất bại, CTHD đã tồn tại hoặc số lượng quá mức", "Thông báo", MessageBoxButtons.OK);
                }
                LockInsertCTHD();
            }
            else if (status == "SửaCTHD")
            {
                try
                {
                    //DataGridViewRow row = dataCTHD.CurrentRow;
                    CTHD_DTO cthd = new CTHD_DTO();
                    cthd.SoHD    = int.Parse(cbbSoHD_CTHD.Text);
                    cthd.TenSP   = cbbTenSP_CTHD.Text;
                    cthd.SoLuong = int.Parse(txtSoLuong_CTHD.Text);
                    cthd.TriGia  = int.Parse(txtGiaCTHD.Text);

                    if (BLL.CTHD_BLL.SuaCTHD(cthd))
                    {
                        MessageBox.Show("Sửa thành công", "Thông báo", MessageBoxButtons.OK);
                        LockInsertCTHD();

                        MyStatus(cthd.SoHD.ToString());
                    }
                    else
                    {
                        MessageBox.Show("Sửa thành công", "Thông báo", MessageBoxButtons.OK);
                    }
                    LoadCTHDTheoSoHD(cthd.SoHD);
                    LockInsertCTHD();
                }
                catch
                {
                }
                UpdateCTHD();
            }
        }
Exemplo n.º 15
0
 public bool Insert(CTHD_DTO cthd)
 {
     return(cthd_dal.Insert(cthd));
 }
Exemplo n.º 16
0
 public static bool SuaCTHD(CTHD_DTO cthd)
 {
     return(DataProvider.ThemCTHD("SuaCTHD", cthd));
 }
Exemplo n.º 17
0
        private void btnThemLinhKien_Click(object sender, EventArgs e)
        {
            int MASP = sp_BUS.getMASP(txtTenSanPham.Text);
            int MAHD = int.Parse(txtIDHD.Text);
            int SL   = int.Parse(txtSoLuong.Text);

            decimal Gia = decimal.Parse(txtThanhTien.Text);

            int     _SL      = cthd_BUS.GetSL(MAHD, MASP) + SL;
            decimal _GiaTien = cthd_BUS.GetTien(MAHD, MASP) + Gia;

            CTHD_DTO cthd_DTO = new CTHD_DTO(MAHD, MASP, SL, Gia);

            if (txtLoai.Text != "Phụ tùng")
            {
                if (cthd_BUS.Insert(cthd_DTO))
                {
                    loadCTHD();
                    loadSP();
                }
                else
                {
                    if (cthd_BUS.Update(MAHD, MASP, _SL, _GiaTien))
                    {
                        loadCTHD();
                        loadSP();
                    }
                    else
                    {
                        MessageBox.Show("Thêm thất bại!");
                    }
                }
            }
            else
            {
                int SLKho = int.Parse(txtTonKho.Text);
                if (SL <= SLKho)
                {
                    if (cthd_BUS.Insert(cthd_DTO))
                    {
                        loadCTHD();
                        UpdateSLKho(MASP, -SL);
                        loadSP();
                    }
                    else
                    {
                        if (cthd_BUS.Update(MAHD, MASP, _SL, _GiaTien))
                        {
                            loadCTHD();
                            UpdateSLKho(MASP, -SL);
                            loadSP();
                        }
                        else
                        {
                            MessageBox.Show("Thêm thất bại!");
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Không đủ hàng trong kho!");
                }
            }
        }
Exemplo n.º 18
0
 public static bool ThemCTHD(CTHD_DTO cthd)
 {
     return(DAL.CTHD_DAL.ThemCTHD(cthd));
 }
Exemplo n.º 19
0
 public static bool SuaCTHD(CTHD_DTO cthd)
 {
     return(DAL.CTHD_DAL.SuaCTHD(cthd));
 }
Exemplo n.º 20
0
 public static bool XoaCTHD(CTHD_DTO cthd)
 {
     return(CTHD_DAL.XoaCTHD(cthd));
 }