Exemplo n.º 1
0
        void Accept()
        {
            try
            {
                if (!CheckValidate())
                {
                    return;
                }

                MessageBoxResult result = NoteBox.Show("Bạn có muốn tạo hóa đơn này hay không?", "Thông báo", NoteBoxLevel.Question);
                if (result != MessageBoxResult.Yes)
                {
                    return;
                }

                // insert vao bảng sale header

                Sale_Header_Controller  _Sale_Header_Controller = new Sale_Header_Controller();
                List <Sale_Detail_Info> _Sale_Detail_Info       = new List <Sale_Detail_Info>();

                Sale_Header_Info _Sale_Header_Info = Get_Sale_Header(ref _Sale_Detail_Info);

                if (_Sale_Header_Info == null)
                {
                    NoteBox.Show("Lỗi rồi Nắng ơi", "", NoteBoxLevel.Error);
                    return;
                }

                decimal _id = 0;

                if (_Sale_Header_Controller.Sale_Header_Insert(_Sale_Header_Info, ref _id))
                {
                    #region insert vào bảng thu chi
                    ThuChi_Controller _ThuChi_Controller = new ThuChi_Controller();
                    ThuChi_Info       _ThuChi_Info       = Get_ThuChi();
                    _ThuChi_Info.Customer_Id = _Sale_Header_Info.Customer_Id;
                    if (_ThuChi_Info == null)
                    {
                        NoteBox.Show("Lỗi rồi Nắng ơi", "", NoteBoxLevel.Error);
                        _Sale_Header_Controller.Sale_Header_Delete(_id);
                        return;
                    }
                    if (!_ThuChi_Controller.ThuChi_Insert(_ThuChi_Info))
                    {
                        NoteBox.Show("Lỗi rồi Nắng ơi", "", NoteBoxLevel.Error);
                        _Sale_Header_Controller.Sale_Header_Delete(_id);
                        return;
                    }
                    #endregion

                    foreach (Sale_Detail_Info item in _Sale_Detail_Info)
                    {
                        _Sale_Header_Controller.Sale_Detail_Insert(item, _id);
                        _ThuChi_Controller.Update_Product_Sale_Count(item.Product_Id, item.Count, item.Color_Id);
                    }

                    Export();

                    NoteBox.Show("Tạo hóa đơn thành công");
                    this.Close();
                }
                else
                {
                    NoteBox.Show("Lỗi rồi", "", NoteBoxLevel.Error);
                    return;
                }
            }
            catch (Exception ex)
            {
                CommonData.log.Error(ex.ToString());
            }
        }
Exemplo n.º 2
0
        void Accept()
        {
            try
            {
                if (!CheckValidate_F())
                {
                    return;
                }

                #region  Insert vào bảng Items trước, trả ra mã ID vừa nhập

                Product_Info _Product_Info = Get_ItemInfo_FromControl();
                if (ckb_Is_XuatDu.IsChecked == true)
                {
                    _Product_Info.Is_XuatDu = 1;
                }
                else
                {
                    _Product_Info.Is_XuatDu = 0;
                }

                Product_Controller _Product_Controller = new Product_Controller();
                ThuChi_Controller  _ThuChi_Controller  = new ThuChi_Controller();
                if (!_Product_Controller.Product_Insert(_Product_Info, ref c_id_insert))
                {
                    NoteBox.Show("Lỗi rồi Nắng ơi", "", NoteBoxLevel.Error);
                    return;
                }
                else
                {
                    #region insert vào bảng thu chi
                    ThuChi_Info _ThuChi_Info = Get_ThuChi();
                    if (_ThuChi_Info == null)
                    {
                        NoteBox.Show("Lỗi rồi Nắng ơi", "", NoteBoxLevel.Error);
                        _Product_Controller.Product_Delete(c_id_insert);
                        return;
                    }
                    if (!_ThuChi_Controller.ThuChi_Insert(_ThuChi_Info))
                    {
                        NoteBox.Show("Lỗi rồi Nắng ơi", "", NoteBoxLevel.Error);
                        _Product_Controller.Product_Delete(c_id_insert);
                        return;
                    }
                    #endregion

                    foreach (Product_Detail_Info item in c_lst_Products_Detail)
                    {
                        item.Product_Id = c_id_insert;

                        if (!_Product_Controller.Product_Detail_Insert(item))
                        {
                            NoteBox.Show("Lỗi rồi", "", NoteBoxLevel.Error);
                            _Product_Controller.Product_Detail_Delete(c_id_insert);
                            _Product_Controller.Product_Delete(c_id_insert);
                            return;
                        }
                    }

                    NoteBox.Show("Thêm mới thành công");
                    this.c_ok = 1;
                    this.Close();
                }


                #endregion
            }
            catch (Exception ex)
            {
                CommonData.log.Error(ex.ToString());
            }
        }