예제 #1
0
파일: XUATHANG.cs 프로젝트: DUDY206/BANHANG
        private void btn_XUATHANG_Click(object sender, EventArgs e)
        {
            if (kiemtradayduthongtin())
            {
                MessageBox.Show("Phai dien day du thong tin");
            }
            else if (soLuongHangNhap == true)
            {
                MessageBoxButtons buttons = MessageBoxButtons.YesNo;
                DialogResult      result  = MessageBox.Show("???????", "XAC NHAN PHIEU XUAT", buttons);
                if (result == DialogResult.Yes)
                {
                    string query = "";
                    if (idNguoiNhan == "")
                    {
                        query += "INSERT INTO NGUOIMUA VALUES('" + tenNguoiNhan_txt + "','" + sdtNguoiNhan_txt + "','" + diaChiNguoiNhan + "')\n";
                        con.ExecuteQuery(query);
                        query       = "";
                        idNguoiNhan = con.getOneID("SELECT ident_current('NGUOIMUA')");
                        //THEM NGUOI MUA
                    }

                    query += "INSERT INTO BANHANG VALUES(" + idNguoiGui + "," + idNguoiNhan + "," + giamGiatxt + ",GETDATE(),";
                    if (cbx1.Checked == true)
                    {
                        query += "0)\n";
                    }
                    else
                    {
                        query += "1)\n";
                    }
                    con.ExecuteQuery(query);
                    query = "";
                    //THEM BANHANG

                    idBanHang = con.getOneID("SELECT ident_current('BANHANG')");
                    query    += "INSERT INTO THUTIEN VALUES(" + idBanHang + ",'" + nganHang_txt + "','" + tienCoctxt + "',GETDATE())\n";

                    //THEM THU TIEN
                    for (int i = 0; i < dgv_MuaHang.Rows.Count; i++)
                    {
                        if (dgv_MuaHang.Rows[i].Cells[2].Value != null && dgv_MuaHang.Rows[i].Cells[3].Value != null)
                        {
                            query += "INSERT INTO PHIEUXUAT VALUES(" + dgv_MuaHang.Rows[i].Cells[0].Value.ToString().Trim() + "," + laysochinhxac(dgv_MuaHang.Rows[i].Cells[2].Value.ToString()) + "," + laysochinhxac(dgv_MuaHang.Rows[i].Cells[3].Value.ToString()) + "," + idBanHang + ")\n";
                        }
                    }
                    con.ExecuteQuery(query);
                    query = "";
                    BILL bill = new BILL(TenNguoiGui.Text, sdtNguoiGui_txt, tienCoctxt, tenNguoiNhan_txt, sdtNguoiNhan_txt, diaChiNguoiNhan);
                    bill.Show();
                    MessageBox.Show("THEM PHIEU XUAT THANG CONG");
                    ResetForm();
                }
            }
        }
예제 #2
0
파일: XUATHANG.cs 프로젝트: DUDY206/BANHANG
        private void btn_UPDATE_Click(object sender, EventArgs e)
        {
            if (kiemtradayduthongtin())
            {
                MessageBox.Show("Phai dien day du thong tin 1");
            }
            else if (soLuongHangNhap == true)
            {
                MessageBoxButtons buttons = MessageBoxButtons.YesNo;
                DialogResult      result  = MessageBox.Show("???????", "XAC NHAN PHIEU XUAT", buttons);
                if (result == DialogResult.Yes)
                {
                    string query = "";
                    if (idNguoiNhan == "")
                    {
                        query += "INSERT INTO NGUOIMUA VALUES('" + tenNguoiNhan_txt + "','" + sdtNguoiNhan_txt + "','" + diaChiNguoiNhan + "')\n";
                        con.ExecuteQuery(query);
                        idNguoiNhan = con.getOneID("SELECT ident_current('NGUOIMUA')");
                        query       = "";

                        //THEM NGUOI MUA
                    }



                    query += "UPDATE BANHANG SET NGUOIBAN_ID = '" + idNguoiGui + "',NGUOIMUA_ID = '" + idNguoiNhan + "',GIAMGIA = '" + giamGiatxt + "',TRANGTHAI = '";
                    if (cbx1.Checked == true)
                    {
                        query += "0'";
                    }
                    else
                    {
                        query += "1'";
                    }
                    query += " WHERE ID = " + idBanHang + "\n";

                    //SUA BANHANG

                    query += "UPDATE THUTIEN SET PHUONGTHUCTHANHTOAN = '" + nganHang_txt + "',SOTIEN = '" + tienCoctxt + "' WHERE BANHANG_ID = '" + idBanHang + "' AND ID = (SELECT MIN(ID) FROM THUTIEN WHERE BANHANG_ID = '" + idBanHang + "')\n";

                    //THEM THU TIEN -- 0k
                    for (int i = 0; i < dgv_MuaHang.Rows.Count; i++)
                    {
                        if (giaBanHang_cu[i] != "" && soLuongHangBan_cu[i] != "")
                        {
                            con.ExecuteQuery("DELETE top(1)  FROM PHIEUXUAT WHERE MABANHANG = '" + idBanHang + "'");
                        }
                    }
                    //XOA NHAP HANG CU

                    for (int i = 0; i < dgv_MuaHang.Rows.Count; i++)
                    {
                        if ((dgv_MuaHang.Rows[i].Cells[2].Value != null && dgv_MuaHang.Rows[i].Cells[3].Value != null) && (dgv_MuaHang.Rows[i].Cells[2].Value.ToString().Trim() != "" && dgv_MuaHang.Rows[i].Cells[3].Value.ToString().Trim() != ""))
                        {
                            query += "INSERT INTO PHIEUXUAT VALUES(" + dgv_MuaHang.Rows[i].Cells[0].Value.ToString().Trim() + "," + laysochinhxac(dgv_MuaHang.Rows[i].Cells[2].Value.ToString()) + "," + laysochinhxac(dgv_MuaHang.Rows[i].Cells[3].Value.ToString()) + "," + idBanHang + ")\n";
                        }
                    }

                    con.ExecuteQuery(query);

                    BILL bill = new BILL(TenNguoiGui.Text, sdtNguoiGui_txt, tienCoctxt, tenNguoiNhan_txt, sdtNguoiNhan_txt, diaChiNguoiNhan);
                    bill.Show();
                    MessageBox.Show("SUA PHIEU XUAT THANG CONG");
                    ResetForm();
                }
            }
        }