示例#1
0
        public bool rule_mh(PhieuXuatHangDTO pxh)
        {
            string query = string.Empty;

            query += "Update [QuyDinh] set [QuyDinh].[matHangToiDa] = @soMatHang";
            using (SqlConnection con = new SqlConnection(ConnectionString))
            {
                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.Connection  = con;
                    cmd.CommandType = System.Data.CommandType.Text;
                    cmd.CommandText = query;

                    cmd.Parameters.AddWithValue("@soMatHang", pxh.soMatHang);

                    try
                    {
                        con.Open();
                        cmd.ExecuteNonQuery();
                        con.Close();
                        con.Dispose();
                    }

                    catch (Exception ex)
                    {
                        con.Close();
                        return(false);
                    }
                }
            }
            return(true);
        }
示例#2
0
        public bool xoa_donVi(PhieuXuatHangDTO pxh)
        {
            string query = string.Empty;

            query += "Delete from [DonVi] where [DonVi].[donViTinh] = @donViTinh";
            using (SqlConnection con = new SqlConnection(ConnectionString))
            {
                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.Connection  = con;
                    cmd.CommandType = CommandType.Text;
                    cmd.CommandText = query;

                    cmd.Parameters.AddWithValue("@donViTinh", pxh.donViTinh);

                    try
                    {
                        con.Open();
                        cmd.ExecuteNonQuery();
                        con.Close();
                        con.Dispose();
                    }

                    catch (Exception ex)
                    {
                        con.Close();
                        return(false);
                    }
                }
            }
            return(true);
        }
示例#3
0
        public bool Xoa(PhieuXuatHangDTO pxh)
        {
            string query = string.Empty;

            query += "Delete [PhieuXuatHang] where [PhieuXuatHang].[maPhieuXuatHang] = @maPhieuXuat";
            using (SqlConnection con = new SqlConnection(ConnectionString))
            {
                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.Connection  = con;
                    cmd.CommandType = CommandType.Text;
                    cmd.CommandText = query;

                    cmd.Parameters.AddWithValue("@maPhieuXuat", pxh.maPhieuXuat);

                    try
                    {
                        con.Open();
                        cmd.ExecuteNonQuery();
                        con.Close();
                        con.Dispose();
                    }

                    catch (Exception ex)
                    {
                        con.Close();
                        return(false);
                    }
                }
            }

            return(true);
        }
示例#4
0
        //Phần truy xuất lấy giá trị riêng
        public void mh_combo_box(ComboBox box, PhieuXuatHangDTO pxh)
        {
            string query = string.Empty;

            query += "select [MatHang].[tenMatHang] from [MatHang] where [MatHang].[maDaiLy] = @maDaiLy";
            using (SqlConnection con = new SqlConnection(ConnectionString))
            {
                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.Connection  = con;
                    cmd.CommandType = System.Data.CommandType.Text;
                    cmd.CommandText = query;

                    cmd.Parameters.AddWithValue("@maDaiLy", pxh.maDaiLy);

                    try
                    {
                        con.Open();
                        SqlDataReader reader = cmd.ExecuteReader();
                        while (reader.Read())
                        {
                            box.Items.Add(reader[0]);
                        }
                        con.Close();
                        con.Dispose();
                    }
                    catch (Exception ex)
                    {
                        con.Close();
                    }
                }
            }
        }
示例#5
0
        public string getDonVi(PhieuXuatHangDTO pxh)
        {
            string donVi;

            donVi = pxhDAL.getDonViTinh(pxh);
            return(donVi);
        }
示例#6
0
        public string getName(PhieuXuatHangDTO pxh)
        {
            string name;

            name = pxhDAL.getTenDaiLy(pxh);
            return(name);
        }
示例#7
0
        public bool xoa_mh_all(PhieuXuatHangDTO pxh)
        {
            string query = string.Empty;

            query += "delete from [PhieuXuatHang] where [tenMatHang] = @tenMatHang ";
            query += "delete from [MatHang] where [tenMatHang] = @tenMatHang";
            using (SqlConnection con = new SqlConnection(ConnectionString))
            {
                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.Connection  = con;
                    cmd.CommandType = System.Data.CommandType.Text;
                    cmd.CommandText = query;

                    cmd.Parameters.AddWithValue("@tenMatHang", pxh.tenMatHang);

                    try
                    {
                        con.Open();
                        cmd.ExecuteNonQuery();
                        con.Close();
                        con.Dispose();
                    }

                    catch (Exception ex)
                    {
                        con.Close();
                        return(false);
                    }
                }
            }

            return(true);
        }
示例#8
0
        public bool sua_donViToiDa(PhieuXuatHangDTO pxh)
        {
            string query = string.Empty;

            query += "update [QuyDinh] set [QuyDinh].[donViToiDa] = @donViToiDa";
            using (SqlConnection con = new SqlConnection(ConnectionString))
            {
                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.Connection  = con;
                    cmd.CommandType = CommandType.Text;
                    cmd.CommandText = query;

                    cmd.Parameters.AddWithValue("@donViToiDa", pxh.donViToiDa);

                    try
                    {
                        con.Open();
                        cmd.ExecuteNonQuery();
                        con.Close();
                        con.Dispose();
                    }

                    catch (Exception ex)
                    {
                        con.Close();
                        return(false);
                    }
                }
            }
            return(true);
        }
示例#9
0
 private void matHang_txt_Click(object sender, EventArgs e)
 {
     matHang_txt.Items.Clear();
     if (maDaiLy_txt.Text.Trim().Length != 0)
     {
         PhieuXuatHangDTO pxh = new PhieuXuatHangDTO();
         pxh.maDaiLy = int.Parse(maDaiLy_txt.Text);
         pxhBus.add_combo_mh(matHang_txt, pxh);
     }
 }
示例#10
0
        private void matHang_txt_SelectedIndexChanged(object sender, EventArgs e)
        {
            PhieuXuatHangDTO pxh = new PhieuXuatHangDTO();

            if (matHang_txt.Text.Trim().Length > 0)
            {
                pxh.tenMatHang     = matHang_txt.Text;
                donViTinh_txt.Text = pxhBus.getDonVi(pxh);
                donGia_txt.Text    = pxhBus.getDonGia(pxh).ToString();
            }
        }
示例#11
0
        private void sua_donViMax_Click(object sender, EventArgs e)
        {
            PhieuXuatHangDTO pxh = new PhieuXuatHangDTO();

            pxh.donViToiDa = int.Parse(donViMax_txt.Text);
            bool kq = pxhBUS.donViToiDa(pxh);

            if (kq == true)
            {
                MessageBox.Show("Sửa Thành Công");
            }
            else
            {
                MessageBox.Show("Sửa Thất Bại");
            }
        }
示例#12
0
        public bool sua(PhieuXuatHangDTO pxh)
        {
            string query = string.Empty;

            query += "Update [PhieuXuatHang] Set ";
            query += "[maDaiLy]  = @maDaiLy, ";
            query += "[ngayLapPhieuXuathang] = @ngayLapPhieuXuatHang, ";
            query += "[tenMatHang] = @tenMatHang, ";
            query += "[soLuong] = @soLuong, ";
            query += "[thanhTien] = @thanhTien, ";
            query += "[donViTinh] = @donViTinh, ";
            query += "[donGia] = @donGia ";
            query += "where [maPhieuXuathang] = @maPhieuXuatHang";
            using (SqlConnection con = new SqlConnection(ConnectionString))
            {
                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.Connection  = con;
                    cmd.CommandType = CommandType.Text;
                    cmd.CommandText = query;

                    cmd.Parameters.AddWithValue("@maDaiLy", pxh.maDaiLy);
                    cmd.Parameters.AddWithValue("@ngayLapPhieuXuatHang", pxh.ngayLapPhieu);
                    cmd.Parameters.AddWithValue("@tenMatHang", pxh.tenMatHang);
                    cmd.Parameters.AddWithValue("@soLuong", pxh.soLuong);
                    cmd.Parameters.AddWithValue("@thanhTien", pxh.donGia * pxh.soLuong);
                    cmd.Parameters.AddWithValue("@donViTinh", pxh.donViTinh);
                    cmd.Parameters.AddWithValue("@donGia", pxh.donGia);
                    cmd.Parameters.AddWithValue("@maPhieuXuathang", pxh.maPhieuXuat);

                    try
                    {
                        con.Open();
                        cmd.ExecuteNonQuery();
                        con.Close();
                        con.Dispose();
                    }

                    catch (Exception Ex)
                    {
                        con.Close();
                        return(false);
                    }
                }
            }
            return(true);
        }
示例#13
0
        private void xoa_btn_Click(object sender, EventArgs e)
        {
            PhieuXuatHangDTO pxh = new PhieuXuatHangDTO();

            pxh.donViTinh = donVi_txt.Text;
            bool kq = pxhBUS.xoa_donVi(pxh);

            if (kq == true)
            {
                MessageBox.Show("Xóa thành công");
                donViGrid.DataSource = pxhBUS.load_donVi();
            }
            else
            {
                MessageBox.Show("Xóa thất bại");
            }
        }
示例#14
0
        private void button3_Click(object sender, EventArgs e)
        {
            PhieuXuatHangDTO pxh = new PhieuXuatHangDTO();

            pxh.soMatHang = int.Parse(matHangMax_txt.Text);

            bool kq = pxhBus.rule_mhMax(pxh);

            if (kq == true)
            {
                MessageBox.Show("Sửa thành công");
            }
            else
            {
                MessageBox.Show("Sửa thất bại");
            }
        }
示例#15
0
        private void button4_Click(object sender, EventArgs e)
        {
            PhieuXuatHangDTO pxh = new PhieuXuatHangDTO();

            pxh.tenMatHang = matHang_txt.Text;
            pxh.donViTinh  = donViTinh_txt.Text;
            pxh.donGia     = int.Parse(donGia_txt.Text);
            bool kq = pxhBus.sua_mh(pxh);

            if (kq == true)
            {
                MessageBox.Show("Sửa thành công");
            }
            else
            {
                MessageBox.Show("Sửa thất bại");
            }
        }
示例#16
0
        private void button1_Click(object sender, EventArgs e)
        {
            PhieuXuatHangDTO pxh = new PhieuXuatHangDTO();

            pxh.maDaiLy    = int.Parse(maDaiLy_txt.Text);
            pxh.tenMatHang = matHang_txt.Text;
            pxh.donViTinh  = donViTinh_txt.Text;
            pxh.donGia     = int.Parse(donGia_txt.Text);
            bool kq = pxhBus.them_mh(pxh);

            if (kq == false)
            {
                MessageBox.Show("Thêm mặt hàng thất bại");
            }
            else
            {
                MessageBox.Show("Thêm mặt hàng thành công");
            }
        }
示例#17
0
        private void maDaiLy_txt_TextChanged(object sender, EventArgs e)
        {
            matHang_txt.Items.Clear();
            PhieuXuatHangDTO pxh = new PhieuXuatHangDTO();

            if (maDaiLy_txt.Text.Trim().Length > 0 && maDaiLy_txt.Text.Length > 0)
            {
                pxh.maDaiLy = int.Parse(maDaiLy_txt.Text);
                pxhBus.add_combo_mh(matHang_txt, pxh);
                tenDaiLy_txt.Text = pxhBus.getName(pxh);
            }
            else
            {
                tenDaiLy_txt.Text = string.Empty;
                tenDaiLy_txt.Clear();
                donViTinh_txt.Clear();
                donGia_txt.Clear();
                matHang_txt.Text = string.Empty;
            }
        }
示例#18
0
        public bool Them(PhieuXuatHangDTO pxh)
        {
            string query = string.Empty;

            query += "Insert into [PhieuXuatHang]([maPhieuXuatHang], [maDaiLy], [ngayLapPhieuXuatHang],[tenMatHang],[donViTinh], [soLuong], [donGia], [thanhTien] )";
            query += "values(@maPhieuXuatHang , @maDaiLy , @ngayLapPhieuXuatHang, @tenMatHang, " +
                     "(select [MatHang].[donViTinh] from [MatHang] where [MatHang].[tenMatHang] = @tenMatHang ), " +
                     "@soLuong, " +
                     "(select [MatHang].[donGia] from [MatHang] where [MatHang].[tenMatHang] = @tenMatHang ), " +
                     "@soLuong * (select [MatHang].[donGia] from [MatHang] where [MatHang].[tenMatHang] = @tenMatHang ))";
            using (SqlConnection con = new SqlConnection(ConnectionString)) {
                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.Connection  = con;
                    cmd.CommandType = System.Data.CommandType.Text;
                    cmd.CommandText = query;

                    cmd.Parameters.AddWithValue("@maPhieuXuatHang", pxh.maPhieuXuat);
                    cmd.Parameters.AddWithValue("@maDaiLy", pxh.maDaiLy);
                    cmd.Parameters.AddWithValue("@ngayLapPhieuXuatHang", pxh.ngayLapPhieu);
                    cmd.Parameters.AddWithValue("@tenMatHang", pxh.tenMatHang);
                    cmd.Parameters.AddWithValue("@soLuong", pxh.soLuong);

                    try
                    {
                        con.Open();
                        cmd.ExecuteNonQuery();
                        con.Close();
                        con.Dispose();
                    }
                    catch (Exception ex)
                    {
                        con.Close();
                        return(false);
                    }
                }
            }
            return(true);
        }
示例#19
0
        public bool sua_mh(PhieuXuatHangDTO pxh)
        {
            string query = string.Empty;

            query += "update [MatHang] ";
            query += "set [MatHang].[donViTinh] = @donViTinh , ";
            query += "[MatHang].[donGia] = @donGia ";
            query += "where [MatHang].[tenMatHang] = @tenMatHang";
            using (SqlConnection con = new SqlConnection(ConnectionString))
            {
                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.Connection  = con;
                    cmd.CommandType = CommandType.Text;
                    cmd.CommandText = query;

                    cmd.Parameters.AddWithValue("@donViTinh", pxh.donViTinh);
                    cmd.Parameters.AddWithValue("@donGia", pxh.donGia);
                    cmd.Parameters.AddWithValue("@tenMatHang", pxh.tenMatHang);

                    try
                    {
                        con.Open();
                        cmd.ExecuteNonQuery();
                        con.Close();
                        con.Dispose();
                    }

                    catch (Exception ex)
                    {
                        con.Close();
                        return(false);
                    }
                }
            }
            return(true);
        }
示例#20
0
        private void button2_Click(object sender, EventArgs e)
        {
            PhieuXuatHangDTO pxh = new PhieuXuatHangDTO();

            pxh.tenMatHang = matHang_txt.Text;

            if ((maDaiLy_txt.Text.Length == 0) || (maDaiLy_txt.Text.Trim().Length == 0))
            {
                DialogResult result = MessageBox.Show("Bạn có chắc muốn xóa mặt hàng này khỏi tất cả đại lý ? ", "Warning!!", MessageBoxButtons.YesNo);
                if (result == DialogResult.Yes)
                {
                    bool kq = pxhBus.xoa_mh_all(pxh);
                    if (kq == true)
                    {
                        MessageBox.Show("Xóa Thành công");
                    }
                    else
                    {
                        MessageBox.Show("Xóa thất bại");
                    }
                }
            }
            else
            {
                pxh.maDaiLy = int.Parse(maDaiLy_txt.Text);
                bool kq = pxhBus.xoa_mh(pxh);
                if (kq == true)
                {
                    MessageBox.Show("Xóa Thành công");
                }
                else
                {
                    MessageBox.Show("Xóa thất bại");
                }
            }
        }
示例#21
0
        public int getDonGia(PhieuXuatHangDTO pxh)
        {
            int    donGia;
            string query = string.Empty;

            query += "Select [MatHang].[donGia] from [MatHang] where [MatHang].[tenMatHang] = @tenMatHang";
            using (SqlConnection con = new SqlConnection(ConnectionString))
            {
                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.Connection  = con;
                    cmd.CommandType = CommandType.Text;
                    cmd.CommandText = query;

                    cmd.Parameters.AddWithValue("@tenMatHang", pxh.tenMatHang);
                    con.Open();
                    donGia = (int)cmd.ExecuteScalar();
                    con.Close();
                    con.Dispose();
                }
            }

            return(donGia);
        }
示例#22
0
        public string getTenDaiLy(PhieuXuatHangDTO pxh)
        {
            string name  = string.Empty;
            string query = string.Empty;

            query += "Select [DaiLy].[tenDaiLy] from [DaiLy] where [DaiLy].[maDaiLy] = @maDaiLy";
            using (SqlConnection con = new SqlConnection(ConnectionString))
            {
                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.Connection  = con;
                    cmd.CommandType = CommandType.Text;
                    cmd.CommandText = query;

                    cmd.Parameters.AddWithValue("@maDaiLy", pxh.maDaiLy);
                    con.Open();
                    name = (string)cmd.ExecuteScalar();
                    con.Close();
                    con.Dispose();
                }
            }

            return(name);
        }
示例#23
0
        public bool them_mh(PhieuXuatHangDTO pxh)
        {
            string query = string.Empty;

            query += "insert into MatHang([maDaiLy] ,[tenMatHang], [donViTinh], [donGia]) ";
            query += "values(@maDaiLy , @tenMatHang, @donViTinh , @donGia)";
            using (SqlConnection con = new SqlConnection(ConnectionString))
            {
                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.Connection  = con;
                    cmd.CommandType = System.Data.CommandType.Text;
                    cmd.CommandText = query;

                    cmd.Parameters.AddWithValue("@maDaiLy", pxh.maDaiLy);
                    cmd.Parameters.AddWithValue("@tenMatHang", pxh.tenMatHang);
                    cmd.Parameters.AddWithValue("@donViTinh", pxh.donViTinh);
                    cmd.Parameters.AddWithValue("@donGia", pxh.donGia);

                    try
                    {
                        con.Open();
                        cmd.ExecuteNonQuery();
                        con.Close();
                        con.Dispose();
                    }
                    catch (Exception ex)
                    {
                        con.Close();
                        return(false);
                    }
                }
            }

            return(true);
        }
示例#24
0
        public bool sua(PhieuXuatHangDTO pxh)
        {
            bool re = pxhDAL.sua(pxh);

            return(re);
        }
示例#25
0
        public bool donViToiDa(PhieuXuatHangDTO pxh)
        {
            bool re = pxhDAL.sua_donViToiDa(pxh);

            return(re);
        }
示例#26
0
        public bool rule_mhMax(PhieuXuatHangDTO pxh)
        {
            bool re = pxhDAL.rule_mh(pxh);

            return(re);
        }
示例#27
0
        public bool xoa_mh(PhieuXuatHangDTO pxh)
        {
            bool re = pxhDAL.xoa_mh(pxh);

            return(re);
        }
示例#28
0
        public bool them(PhieuXuatHangDTO pxh)
        {
            bool re = pxhDAL.Them(pxh);

            return(re);
        }
示例#29
0
        private void Ok_Click(object sender, EventArgs e)
        {
            if (function.Text == "Thêm")
            {
                PhieuXuatHangDTO pxh = new PhieuXuatHangDTO();
                pxh.maPhieuXuat  = int.Parse(maPhieuXuat.Text);
                pxh.ngayLapPhieu = date_txt.Value;
                pxh.maDaiLy      = int.Parse(maDaiLy_txt.Text);
                pxh.tenMatHang   = matHang_txt.Text;
                pxh.soLuong      = int.Parse(soLuong_txt.Text);
                bool kq = pxhBus.them(pxh);
                if (kq == false)
                {
                    MessageBox.Show("Thêm phiếu xuất hàng thất bại");
                }
                else
                {
                    MessageBox.Show("Thêm phiếu xuất hàng thành công");
                }
            }

            if (function.Text == "Xóa")
            {
                maPhieuXuat.Enabled = true;
                PhieuXuatHangDTO pxh = new PhieuXuatHangDTO();
                pxh.maPhieuXuat = int.Parse(maPhieuXuat.Text);
                bool kq = pxhBus.xoa(pxh);
                if (kq == true)
                {
                    MessageBox.Show("Xóa Thành Công");
                }
                else
                {
                    MessageBox.Show("Xóa Thất Bại");
                }
            }

            if (function.Text == "Sửa")
            {
                PhieuXuatHangDTO pxh = new PhieuXuatHangDTO();
                pxh.maPhieuXuat  = int.Parse(maPhieuXuat.Text);
                pxh.maDaiLy      = int.Parse(maDaiLy_txt.Text);
                pxh.ngayLapPhieu = date_txt.Value;
                pxh.tenMatHang   = matHang_txt.Text;
                pxh.soLuong      = int.Parse(soLuong_txt.Text);
                pxh.donViTinh    = donViTinh_txt.Text;
                pxh.donGia       = int.Parse(donGia_txt.Text);
                bool kq = pxhBus.sua(pxh);
                if (kq == true)
                {
                    MessageBox.Show("Sửa Thành Công");
                }
                else
                {
                    MessageBox.Show("Sửa Thất Bại");
                }
                dataGridView1.DataSource = pxhBus.load_pxh();
            }
            RefreshAll();
            DisableEdit();
            dataGridView1.DataSource = pxhBus.load_pxh();
        }
示例#30
0
        public bool them_donVi(PhieuXuatHangDTO pxh)
        {
            bool re = pxhDAL.them_donVi(pxh);

            return(re);
        }