Ejemplo n.º 1
0
        /// <summary>
        /// Lấy danh sách Hàng bán
        /// </summary>
        /// <param name="FK_iHoadonbanhangID">Mã hóa đơn bán hàng</param>
        /// <param name="FK_iHanghoaID">Mã hàng hóa</param>
        /// <returns>List<tblHangban></returns>
        public List <tblHangban> tblHangban_Select(int FK_iHoadonbanhangID, int FK_iHanghoaID)
        {
            List <tblHangban> listHangban = new List <tblHangban>();

            using (SqlConnection cnn = new SqlConnection(connectionString))
            {
                using (SqlCommand cmd = new SqlCommand("sp_tblHangban_Select", cnn))
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@FK_iHoadonbanhangID", FK_iHoadonbanhangID);
                    cmd.Parameters.AddWithValue("@FK_iHanghoaID", FK_iHanghoaID);
                    cnn.Open();
                    using (SqlDataReader rd = cmd.ExecuteReader())
                    {
                        if (rd.HasRows)
                        {
                            while (rd.Read())
                            {
                                tblHangban hangban = new tblHangban();
                                hangban.iHoadonbanhangID = Convert.ToInt32(rd["FK_iHoadonbanhangID"].ToString());
                                hangban.iHanghoaID       = Convert.ToInt32(rd["FK_iHanghoaID"].ToString());
                                hangban.iSoluongban      = Convert.ToInt32(rd["iSoluongban"].ToString());
                                hangban.iGiaban          = Convert.ToInt32(rd["iGiaban"].ToString());
                                hangban.iThanhtien       = Convert.ToInt32(rd["iThanhtien"].ToString());
                                listHangban.Add(hangban);
                            }
                            rd.Close();
                        }
                        cnn.Close();
                        return(listHangban);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private void buttonTao_Click(object sender, EventArgs e)
        {
            tblHoadonbanhang hoadonban = new tblHoadonbanhang();

            hoadonban.FK_iNhanvienID = Convert.ToInt32(txtNhanvienID.Text.Trim());
            hoadonban.sTenKhachhang  = txtTenKhachhang.Text.Trim();
            hoadonban.sDiachi        = txtDiachi.Text.Trim();
            hoadonban.sSdt           = txtSdt.Text.Trim();
            hoadonban.dThoigianban   = DateTime.Today;
            hoadonban.iTongtien      = Convert.ToInt32(txtTongtien.Text.Trim());

            if (Mahoadon == 0)
            {
                hoadonban.PK_iHoadonbanhangID = new XuLy_tblHoadonbanhang().tblHoadonbanhang_Insert(hoadonban);
                foreach (DataRow r in table.Rows)
                {
                    tblHangban h = new tblHangban();
                    h.iHoadonbanhangID = hoadonban.PK_iHoadonbanhangID;
                    h.iHanghoaID       = Convert.ToInt32(r["iHanghoaID"]);
                    h.iSoluongban      = Convert.ToInt32(r["iSoluongban"]);
                    h.iGiaban          = Convert.ToInt32(r["iDongia"]);
                    h.iThanhtien       = Convert.ToInt32(r["iThanhtien"]);
                    new XuLy_tblHangban().tblHangban_Insert(h);
                }
                MessageBox.Show("Tạo thành công!");
            }
            else
            {
                hoadonban.PK_iHoadonbanhangID = Mahoadon;
                new XuLy_tblHoadonbanhang().tblHoadonbanhang_Update(hoadonban);

                List <tblHangban> listHangban = new XuLy_tblHangban().tblHangban_Select(Mahoadon, 0);
                foreach (tblHangban hb in listHangban)
                {
                    new XuLy_tblHangban().tblHangban_Delete(Mahoadon, hb.iHanghoaID);
                }
                //new XuLy_tblHangban().tblHangban_Delete(hoadonban.PK_iHoadonbanhangID, 0);
                foreach (DataRow r in table.Rows)
                {
                    tblHangban h = new tblHangban();
                    h.iHoadonbanhangID = hoadonban.PK_iHoadonbanhangID;
                    h.iHanghoaID       = Convert.ToInt32(r["iHanghoaID"]);
                    h.iSoluongban      = Convert.ToInt32(r["iSoluongban"]);
                    h.iGiaban          = Convert.ToInt32(r["iDongia"]);
                    h.iThanhtien       = Convert.ToInt32(r["iThanhtien"]);
                    new XuLy_tblHangban().tblHangban_Insert(h);
                }
                MessageBox.Show("Sửa thành công.");
                this.Close();
            }
            buttonBoqua_Click(sender, e);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Thêm Hàng bán
 /// </summary>
 /// <param name="hangban">tblHangban</param>
 /// <returns>bool</returns>
 public bool tblHangban_Insert(tblHangban hangban)
 {
     using (SqlConnection cnn = new SqlConnection(connectionString))
     {
         using (SqlCommand cmd = new SqlCommand("sp_tblHangban_Insert", cnn))
         {
             cmd.CommandType = CommandType.StoredProcedure;
             cmd.Parameters.AddWithValue("@FK_iHoadonbanhangID", hangban.iHoadonbanhangID);
             cmd.Parameters.AddWithValue("@FK_iHanghoaID", hangban.iHanghoaID);
             cmd.Parameters.AddWithValue("@iSoluongban", hangban.iSoluongban);
             cmd.Parameters.AddWithValue("@iGiaban", hangban.iGiaban);
             cmd.Parameters.AddWithValue("@iThanhtien", hangban.iThanhtien);
             cnn.Open();
             int i = cmd.ExecuteNonQuery();
             cnn.Close();
             return(i > 0);
         }
     }
 }