Ejemplo n.º 1
0
 public frmStaffs()
 {
     InitializeComponent();
     //Load
     Load += (sender, e) =>
     {
         BindingGridView();
     };
     //Add button click
     ucActionButton.AddButtonClick += (sender, e) =>
     {
         frmStaff frm = new frmStaff();
         frm.OnSaved += t =>
         {
             var staff = (Staff)t;
             unitOfWork.StaffService.Create(staff);
             unitOfWork.Save();
             //reload gridview
             BindingGridView();
             frm.Close();
         };
         frm.ShowDialog();
     };
     //Edit button click
     ucActionButton.EditButtonClick += (sender, e) =>
     {
         frmStaff frm = new frmStaff();
         //send data
         frm.staff    = unitOfWork.StaffService.Find(staffId);
         frm.OnSaved += t =>
         {
             var staff = (Staff)t;
             unitOfWork.StaffService.Update(staff);
             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 nhân viên này # : " + staffId, "Thông báo", MessageBoxButtons.OKCancel);
         if (messageBox == DialogResult.OK)
         {
             unitOfWork.StaffService.Delete(staffId);
             unitOfWork.Save();
             //reload gridview
             BindingGridView();
         }
     };
 }
Ejemplo n.º 2
0
        public frmDelivery()
        {
            InitializeComponent();
            //Load
            Load += (sender, e) =>
            {
                if (deliveryNote == null)
                {
                    deliveryNote = new DeliveryNote {
                        Date = DateTime.Now
                    }
                }
                ;
                //bind combobox
                LoadStaff();
                LoadStock();
                LoadCustomer();
                //bind repository lookup edit
                LoadRepositoryLookupEdit();
                //bind static list variable
                listDeliveryNoteDetails = deliveryNote.DeliveryNoteDetails.ToList();
                //bind gridview
                gcDeliveryNoteDetails.DataSource = listDeliveryNoteDetails;
            };

            //add item to gridview
            gvDeliveryNoteDetails.DoubleClick += (sender, e) =>
            {
                //add new item to static list variable
                listDeliveryNoteDetails.Add(new DeliveryNoteDetail());
                //refresh data source gridview after add new item
                gcDeliveryNoteDetails.RefreshDataSource();
            };
            //remove item to gridview
            gvDeliveryNoteDetails.KeyDown += (sender, e) =>
            {
                if (e.KeyValue == 46) //keyboard delete
                {
                    var currentItem = gvDeliveryNoteDetails.GetFocusedRow() as DeliveryNoteDetail;
                    listDeliveryNoteDetails.Remove(currentItem);
                    //refresh datasouce gridview
                    gcDeliveryNoteDetails.RefreshDataSource();
                }
            };
            //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();
            };
            //Customer add button click
            btnCustomerAdd.Click += (sender, e) =>
            {
                frmCustomer frm = new frmCustomer();
                frm.OnSaved += t =>
                {
                    unitOfWork.CustomerService.Create(t as Customer);
                    unitOfWork.Save();
                    //reload combobox
                    LoadCustomer();
                    frm.Close();
                };
                frm.ShowDialog();
            };
            //Save button click
            ucActionResultButton.SaveButtonClick += (sender, e) =>
            {
                if (dxValidationProvider.Validate())
                {
                    var listItem = gcDeliveryNoteDetails.DataSource as List <DeliveryNoteDetail>;
                    if (listItem.Count > 0)
                    {
                        deliveryNote.DeliveryNoteDetails = listItem;
                        OnSaved(deliveryNote);
                    }
                }
            };
            //Cancel button click
            ucActionResultButton.CancelButtonClick += (sender, e) =>
            {
                this.Close();
            };
        }
Ejemplo n.º 3
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;
                }
            };
        }