Beispiel #1
0
 public frmStocks()
 {
     InitializeComponent();
     //Load
     Load += (sender, e) =>
     {
         BindingGridView();
     };
     //Add button click
     ucActionButton.AddButtonClick += (sender, e) =>
     {
         frmStock frm = new frmStock();
         frm.OnSaved += t =>
         {
             var stock = t as Stock;
             unitOfWork.StockService.Create(stock);
             unitOfWork.Save();
             //reload gridview
             BindingGridView();
             frm.Close();
         };
         frm.ShowDialog();
     };
     //Edit button click
     ucActionButton.EditButtonClick += (sender, e) =>
     {
         frmStock frm = new frmStock();
         //send data
         frm.stock    = unitOfWork.StockService.Find(stockId);
         frm.OnSaved += t =>
         {
             var stock = t as Stock;
             unitOfWork.StockService.Update(stock);
             unitOfWork.Save();
             //reload gridview
             BindingGridView();
             frm.Close();
         };
         frm.ShowDialog();
     };
     //Delete button click
     ucActionButton.DeleteButtonClick += (sender, e) =>
     {
         var messageBox = MessageBox.Show("Bạn chắc chắn muốn xóa kho hàng này # : " + stockId, "Thông báo", MessageBoxButtons.OKCancel);
         if (messageBox == DialogResult.OK)
         {
             unitOfWork.StockService.Delete(stockId);
             unitOfWork.Save();
             //reload gridview
             BindingGridView();
         }
     };
 }
Beispiel #2
0
        public frmReceipt()
        {
            InitializeComponent();
            //Load
            Load += (sender, e) =>
            {
                if (receiptNote == null)
                {
                    receiptNote = new ReceiptNote {
                        Date = DateTime.Now
                    }
                }
                ;
                //bind combobox
                LoadStaff();
                LoadSupplier();
                LoadStock();
                //bind gridview
                LoadRepositoryLookupEdit();
                listReceiptNoteDetails = receiptNote.ReceiptNoteDetails.ToList();
                //bind gridview to static list
                gcReceiptNoteDetails.DataSource = listReceiptNoteDetails;
            };
            //Add item gridview
            gvReceiptNoteDetails.DoubleClick += (sender, e) =>
            {
                listReceiptNoteDetails.Add(new ReceiptNoteDetail());
                gcReceiptNoteDetails.RefreshDataSource();
            };
            //Remove item gridview
            gvReceiptNoteDetails.KeyDown += (sender, e) =>
            {
                if (e.KeyValue == 46) //keyboard delete
                {
                    var currentItem = gvReceiptNoteDetails.GetFocusedRow() as ReceiptNoteDetail;
                    //delete from list
                    listReceiptNoteDetails.Remove(currentItem);
                    //rebinding gridview
                    gcReceiptNoteDetails.RefreshDataSource();
                }
            };
            //Produce add button click
            btnProduceAdd.Click += (sender, e) =>
            {
                frmProduce frm = new frmProduce();
                frm.OnSaved += t =>
                {
                    var produce = t as Produce;
                    unitOfWork.ProduceService.Create(produce);
                    unitOfWork.Save();
                    //reload repository produce
                    LoadRepositoryLookupEdit();
                    frm.Close();
                };
                frm.ShowDialog();
            };
            //Staff add button click
            btnStaffAdd.Click += (sender, e) =>
            {
                frmStaff frm = new frmStaff();
                frm.OnSaved += t =>
                {
                    unitOfWork.StaffService.Create(t as Staff);
                    unitOfWork.Save();
                    //reload combobox
                    LoadStaff();
                    frm.Close();
                };
                frm.ShowDialog();
            };
            //Supplier add button click
            btnSupplierAdd.Click += (sender, e) =>
            {
                frmSupplier frm = new frmSupplier();
                frm.OnSaved += t =>
                {
                    unitOfWork.SupplierService.Create(t as Supplier);
                    unitOfWork.Save();
                    //reload combobox
                    LoadSupplier();
                    frm.Close();
                };
                frm.ShowDialog();
            };
            //Stock add button click
            btnStockAdd.Click += (sender, e) =>
            {
                frmStock frm = new frmStock();
                frm.OnSaved += t =>
                {
                    unitOfWork.StockService.Create(t as Stock);
                    unitOfWork.Save();
                    //reload combobox
                    LoadStock();
                    frm.Close();
                };
                frm.ShowDialog();
            };
            //Save button click
            ucActionResultButton.SaveButtonClick += (sender, e) =>
            {
                if (dxValidationProvider.Validate())
                {
                    var listItem = gvReceiptNoteDetails.DataSource as List <ReceiptNoteDetail>;
                    if (listItem.Count > 0)
                    {
                        receiptNote.ReceiptNoteDetails = listItem;
                        OnSaved(receiptNote);
                    }
                }
            };
            //Cancel button click
            ucActionResultButton.CancelButtonClick += (sender, e) =>
            {
                this.Close();
            };

            //validate row item
            gvReceiptNoteDetails.ValidateRow += (sender, e) =>
            {
                GridView view = sender as GridView;
                //GridColumn colProduceId = view.Columns[0];
                GridColumn colQuantity = view.Columns[1];
                GridColumn colPrice    = view.Columns[2];

                //validate for quanity > 1
                var quanity = (int)view.GetRowCellValue(e.RowHandle, colQuantity);
                if (quanity < 1)
                {
                    e.Valid = false;
                    view.SetColumnError(colQuantity, "Số lượng nhập phải lớn hơn 0");
                    return;
                }
                var price = (decimal)view.GetRowCellValue(e.RowHandle, colPrice);
                if (price < 1000)
                {
                    e.Valid = false;
                    view.SetColumnError(colPrice, "Giá sản phẩm phải lớn hơn 1000đ");
                    return;
                }
            };
        }