Beispiel #1
0
 public frmCustomers()
 {
     InitializeComponent();
     //Load
     Load += (sender, e) =>
     {
         BindingGridView();
     };
     //Add button click
     ucActionButton.AddButtonClick += (sender, e) =>
     {
         frmCustomer frm = new frmCustomer();
         frm.OnSaved += t =>
         {
             var customer = (Customer)t;
             unitOfWork.CustomerService.Create(customer);
             unitOfWork.Save();
             //reload gridview
             BindingGridView();
             frm.Close();
         };
         frm.ShowDialog();
     };
     //Edit button click
     ucActionButton.EditButtonClick += (sender, e) =>
     {
         frmCustomer frm = new frmCustomer();
         //send data
         frm.customer = unitOfWork.CustomerService.Find(customerId);
         frm.OnSaved += t =>
         {
             var customer = (Customer)t;
             unitOfWork.CustomerService.Update(customer);
             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 # : " + customerId, "Thông báo", MessageBoxButtons.OKCancel);
         if (messageBox == DialogResult.OK)
         {
             unitOfWork.CustomerService.Delete(customerId);
             unitOfWork.Save();
             //reload gridview
             BindingGridView();
         }
     };
 }
Beispiel #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();
            };
        }