public bool Insert_HDVP(CT_HOADONVIENPHI hdvp)
        {
            try
            {
                SqlConnection con = new SqlConnection(db.connectionStr);
                SqlCommand    cmd = new SqlCommand("insert_CTHDVienPhi", con);
                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Parameters.Add("@hd_id", SqlDbType.NVarChar, 15);
                cmd.Parameters.Add("@pcd_id", SqlDbType.Int);
                cmd.Parameters.Add("@cls_id", SqlDbType.Int);
                cmd.Parameters.Add("@solg", SqlDbType.Int);
                cmd.Parameters.Add("@dongia", SqlDbType.Float);
                cmd.Parameters.Add("@thanhtien", SqlDbType.Float);

                cmd.Parameters["@hd_id"].Value     = hdvp.Hd_id;
                cmd.Parameters["@pcd_id"].Value    = hdvp.Pcd_id;
                cmd.Parameters["@cls_id"].Value    = hdvp.Cls_id;
                cmd.Parameters["@solg"].Value      = hdvp.Solg;
                cmd.Parameters["@dongia"].Value    = hdvp.Dongia;
                cmd.Parameters["@thanhtien"].Value = hdvp.Thanhtien;

                con.Open();
                int result = cmd.ExecuteNonQuery();
                con.Close();
                return(result > 0);
            }
            catch
            {
            }
            return(false);
        }
Example #2
0
        private void btnTTLai_Click(object sender, EventArgs e)
        {
            bool b = false;

            if (daoXT.KiemTraHoaDonDaHuy(lbId_TNHAN.Text) == "Đã hủy")
            {
                string  hd_id  = daoXT.get_ID_auto();
                HOA_DON hoadon = layTTHD(hd_id, daoXT.KiemTraHoaDonDaTT(lbId_TNHAN.Text) + 1, "Đã thanh toán");
                daoHD.Insert_HoaDon(hoadon);
                if (dtCTCLS.Rows.Count != 0)
                {
                    for (int i = 0; i < dtCTCLS.Rows.Count; i++)
                    {
                        string hd        = hd_id;
                        int    cls       = int.Parse(dtCTCLS.Rows[i]["CLS_ID"].ToString());
                        int    pcd       = int.Parse(dtCTCLS.Rows[i]["PCD_ID"].ToString());
                        int    solg      = int.Parse(dtCTCLS.Rows[i]["CTCLS_SOLUONG"].ToString());
                        float  gia       = float.Parse(dtCTCLS.Rows[i]["CLS_DONGIA"].ToString());
                        float  thanhtien = solg * gia;

                        CT_HOADONVIENPHI hdvp = new CT_HOADONVIENPHI(pcd, cls, hd, solg, gia, thanhtien);
                        if (daoXT.Insert_HDVP(hdvp))
                        {
                            b = true;
                        }
                    }
                }

                if (dtCTKHO.Rows.Count != 0)
                {
                    for (int i = 0; i < dtCTKHO.Rows.Count; i++)
                    {
                        string   hd           = hd_id;
                        string   kho          = dtCTKHO.Rows[i]["KHO_ID"].ToString();
                        int      ngvu         = int.Parse(dtCTKHO.Rows[i]["NGV_ID"].ToString());
                        string   vattu        = dtCTKHO.Rows[i]["VT_ID"].ToString();
                        DateTime thoidiem     = DateTime.Parse(dtCTKHO.Rows[i]["KCT_THOIDIEM"].ToString());
                        string   id_nhapkhoct = dtCTKHO.Rows[i]["ID_NHAPKHOCHITIET"].ToString();
                        int      solg         = int.Parse(dtCTKHO.Rows[i]["KCT_SOLUONG"].ToString());
                        float    gia          = float.Parse(dtCTKHO.Rows[i]["KCT_DONGIA"].ToString());
                        float    thanhtien    = solg * gia;

                        CT_HOADONTHUOC hoadonthuoc = new CT_HOADONTHUOC(hd, kho, vattu, ngvu, thoidiem,
                                                                        id_nhapkhoct, solg, gia, thanhtien);
                        if (daoXT.Insert_HDTHUOC(hoadonthuoc))
                        {
                            b = true;
                        }
                    }
                }
                if (b == true)
                {
                    MessageBox.Show("Thanh toán thành công", "Thông báo");
                }

                gcThanhToan.DataSource = daoXT.getHoaDonDaTT(lbId_TNHAN.Text);
            }
            else
            {
                MessageBox.Show("Hóa đơn này chưa hủy. Hãy hủy để thanh toán lại", "Thông báo");
            }
        }