Esempio n. 1
0
        private void simpleButton3_Click(object sender, EventArgs e)
        {
            DateTime tgketthuc = DateTime.Now;
            float    tt;

            float.TryParse(TextEditTongTien.Text, out tt);
            if (maBan != -1)
            {
                HoaDon_BUS.UpdateKetThucHoaDon(maHD, tt, tgketthuc);
                BanAn_BUS.UpdateTrangThaiBanAn(maBan, 0);
                maBan = -1;
                maHD  = -1;
                UCtrlQLTBanAn_Load(null, null);
                load_GridviewCTHD();
            }
        }
Esempio n. 2
0
        private void btnDongY_Click(object sender, EventArgs e)
        {
            int count = listViewDSBanGhep.Items.Count;

            if (count <= 1)
            {
                MessageBox.Show("Ban phai chon it nhat 2 ban de ghep.");
                return;
            }

            if (indexBan != -1)
            {
                int mabanNew = lsBan[indexBan].MaBan;

                int maHDchon      = int.Parse(listViewDSBanGhep.Items[0].SubItems[2].Text);
                int maBanchon_old = int.Parse(listViewDSBanGhep.Items[0].SubItems[0].Text);
                BanAn_BUS.UpdateTrangThaiBanAn(maBanchon_old, 0);

                //doc lai cthd cua maHDchon de len danh sach kiem tra trung khoa chinh
                DataTable dtCthdChon = ChiTietHoaDon_BUS.SelectTableCTHD(maHDchon);

                for (int i = 1; i < count; i++)
                {
                    int maHDold  = int.Parse(listViewDSBanGhep.Items[i].SubItems[2].Text);
                    int maBanold = int.Parse(listViewDSBanGhep.Items[i].SubItems[0].Text);

                    //giai phong cac ban cu
                    BanAn_BUS.UpdateTrangThaiBanAn(maBanold, 0);

                    //voi moi maHDold, cong don chi tiet hoa don, kiem tra khoa chinh
                    DataTable dtCthdOld = ChiTietHoaDon_BUS.SelectTableCTHD(maHDold);
                    foreach (DataRow row in dtCthdOld.Rows)
                    {
                        int  n         = dtCthdChon.Rows.Count;
                        bool duplicate = false;
                        //chen cac dong cua cthoadon cu vao ct hoa don chung
                        //cong don so luong va thanh tien neu co mon an trung nhau
                        for (int j = 0; j < n; j++)
                        {
                            if ((int)dtCthdChon.Rows[j].ItemArray[1] == (int)row.ItemArray[1])
                            {
                                duplicate = true;
                                int     tongsl = (int)dtCthdChon.Rows[j].ItemArray[2] + (int)row.ItemArray[2];
                                DataRow newRow = dtCthdChon.NewRow();
                                newRow[0] = maHDchon;
                                newRow[1] = (int)dtCthdChon.Rows[j].ItemArray[1];
                                newRow[2] = tongsl;
                                newRow[3] = 0;      //tong tien se duoc tu dong tinh lai khi insert CTHD
                                dtCthdChon.Rows.Add(newRow);
                                dtCthdChon.Rows.RemoveAt(j);
                                break;
                            }
                        }

                        if (!duplicate)
                        {
                            //chen dong
                            DataRow newRow = dtCthdChon.NewRow();
                            newRow[0] = maHDchon;
                            newRow[1] = (int)row.ItemArray[1];
                            newRow[2] = (int)row.ItemArray[2];
                            newRow[3] = (double)row.ItemArray[3];
                            dtCthdChon.Rows.Add(newRow);
                        }
                    }
                    //xoa cthd cu
                    ChiTietHoaDon_BUS.DeleteCTHDtheoMaHD(maHDold);
                    //xoa hoa don cu
                    HoaDon_BUS.DeleteHoaDon(maHDold);
                }       //ket thuc vong lap cho cac ban ghep (tru ban dau)
                //xoa cthd moi (vi dtCthdChon da chua tat ca)       ;   nhu vay toan bo CTHD da dc xoa
                ChiTietHoaDon_BUS.DeleteCTHDtheoMaHD(maHDchon);

                //cap nhat hoa don chung
                HoaDon_BUS.UpdateMaBan(maHDchon, mabanNew);

                BanAn_BUS.UpdateTrangThaiBanAn(mabanNew, 1);
                //insert cac cthd moi
                foreach (DataRow row in dtCthdChon.Rows)
                {
                    ChiTietHoaDon_BUS.insertCTHD((int)row.ItemArray[0], (int)row.ItemArray[1], (int)row.ItemArray[2], Mode);
                }

                reloadListboxBanAn();
                this.Close();
            }
            else
            {
                MessageBox.Show("Vui long chon ban muon ghep den.");
            }
        }