Exemple #1
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            //nho them try catch
            try
            {
                int ID = Convert.ToInt32(lblMaMon.Text);
                string Ten = lblName.Text;
                float SoLuong = float.Parse(txtSoLuong.Value.ToString());
                string DonVi = dgvThucDon.SelectedRows[0].Cells[2].Value.ToString();
                float Gia = float.Parse(dgvThucDon.SelectedRows[0].Cells[3].Value.ToString()) ;
                checkso(richTextBoxExGiamGia);
                float GiamGia = a;
                float TongTien = Gia* SoLuong - GiamGia;
                if (MaHoaDon != 0)
                {
                    //neu chua co mon thi insert con neu khong thi update
                    //Kiem tra mon an co cung maMonAn va MaHoaDon
                    HoaDon.model.Load load = new HoaDon.model.Load();
                    DataTable dt = load.LoadMonAn(MaHoaDon, ID);
                    if (dt.Rows.Count == 0)
                    {
                        //InsertMonAn
                        BanHang.Model.Insert insert = new BanHang.Model.Insert();
                        insert.InsertHoaDonChiTiet(MaHoaDon, ID, Ten, SoLuong, DonVi, Gia, GiamGia, TongTien);
                        LoadChiTietHoaDon(MaHoaDon);
                    }
                    else
                    {
                        //Update
                        int MaChiTietHoaDon = Convert.ToInt32(dt.Rows[0][0].ToString());

                        BanHang.Model.Update update = new BanHang.Model.Update();
                        update.UpdateChiTietHoaDon(MaChiTietHoaDon, SoLuong, GiamGia);
                        LoadChiTietHoaDon(MaHoaDon);
                    }
                    resetThucDon();
                    LayHangTrongKho(ID, SoLuong);
                    LoadSoLuongSanPham();
                    loadThucDon();
                }
                else
                {
                    MessageBox.Show("Bạn chưa chọn bàn");
                }

            }
            catch (Exception)
            {

            }
        }
Exemple #2
0
        private void dgvThucDon_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {

                int ID = Convert.ToInt32(dgvThucDon.SelectedRows[0].Cells[0].Value.ToString());
                string Ten = dgvThucDon.SelectedRows[0].Cells[1].Value.ToString();
                float SoLuong =  1;
                string DonVi = dgvThucDon.SelectedRows[0].Cells[2].Value.ToString();
                float Gia = float.Parse(dgvThucDon.SelectedRows[0].Cells[3].Value.ToString());
                float GiamGia = 0;
                float TongTien = Gia * SoLuong - GiamGia;
                if (LayHangTrongKho(ID, SoLuong) == 1)
                {
                    if (MaHoaDon != 0)
                    {
                        //neu chua co mon thi insert con neu khong thi update
                        //Kiem tra mon an co cung maMonAn va MaHoaDon
                        HoaDon.model.Load load = new HoaDon.model.Load();
                        DataTable dt = load.LoadMonAn(MaHoaDon, ID);
                        if (dt.Rows.Count == 0)
                        {
                            //InsertMonAn
                            BanHang.Model.Insert insert = new BanHang.Model.Insert();
                            insert.InsertHoaDonChiTiet(MaHoaDon, ID, Ten, SoLuong, DonVi, Gia, GiamGia, TongTien);
                            LoadChiTietHoaDon(MaHoaDon);

                        }
                        else
                        {
                            //Update
                            int MaChiTietHoaDon = Convert.ToInt32(dt.Rows[0][0].ToString());

                            BanHang.Model.Update update = new BanHang.Model.Update();
                            update.UpdateChiTietHoaDon(MaChiTietHoaDon, SoLuong, GiamGia);
                            LoadChiTietHoaDon(MaHoaDon);
                        }
                }
                }
                else
                {
                    MessageBox.Show("Bạn chưa chọn hàng hoặc hết đồ");
                }
            }
            catch (Exception)
            {

            }
            LoadSoLuongSanPham();
            loadThucDon();
            resetThucDon();
        }