Пример #1
0
        private void metroButton1_Click(object sender, EventArgs e)
        {
            Person person = new Person
            {
                Name    = txtName.Text,
                Phone   = txtphone.Text,
                Fax     = txtFax.Text,
                Website = txtwebsite.Text,
                Type    = TypeOfPerson.Customer
            };

            MyValidationContext vContext = CustomValidation.IsValid <Person>(person);

            if (vContext.IsValid)
            {
                context.People.Add(person);
                if (context.SaveChanges() > 0)
                {
                    MessageBox.Show("successfull Add Customer", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    GetCustomers();
                    ControlHelpers.EmptyGroupBox(this.groupForm);
                }
            }
            else
            {
                foreach (var item in vContext.results)
                {
                    MessageBox.Show(item.ErrorMessage, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Пример #2
0
        private void metroButton2_Click(object sender, EventArgs e)
        {
            try
            {
                Person person = context.People.FirstOrDefault(a => a.ID == selectedPerson.ID);
                person.Name    = txtName.Text;
                person.Fax     = txtFax.Text;
                person.Phone   = txtphone.Text;
                person.Website = txtwebsite.Text;

                MyValidationContext vContext = CustomValidation.IsValid <Person>(person);
                if (vContext.IsValid)
                {
                    context.Entry(person).State = System.Data.Entity.EntityState.Modified;
                    if (context.SaveChanges() > 0)
                    {
                        MessageBox.Show("successfull Edit Customer", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        GetCustomers();
                        ControlHelpers.EmptyGroupBox(this.groupForm);
                    }
                }
                else
                {
                    foreach (var item in vContext.results)
                    {
                        MessageBox.Show(item.ErrorMessage, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
            catch
            {
                MessageBox.Show("Invild Operation");
            }
        }
Пример #3
0
        private void metroButton1_Click(object sender, EventArgs e)
        {
            WareHouseTransformationLogs logs = new WareHouseTransformationLogs();

            logs.DestinationStoreID   = Convert.ToInt32(StoreCombo.SelectedValue);
            logs.DestinationStoreName = StoreCombo.Text;
            logs.SourceStoreID        = _dataStoreViewModel.StoreID;
            logs.SourceStorageName    = _dataStoreViewModel.SourceStorage;
            logs.ProductName          = _dataStoreViewModel.Name;
            logs.Quantity             = _dataStoreViewModel.Qtu;
            logs.ExpireDate           = _dataStoreViewModel.ExpireDate;
            logs.ProductionDate       = _dataStoreViewModel.ProductDate;
            logs.TransfromationDate   = DateTime.Now;


            MyValidationContext con = CustomValidation.IsValid <WareHouseTransformationLogs>(logs);

            if (con.IsValid)
            {
                double       qtu   = Convert.ToDouble(QtuNumber.Value);
                ProductStore store = context.ProductStores.SingleOrDefault(a => a.ID == _dataStoreViewModel.ID);
                store.Qtu -= qtu;

                context.ProductStores.Add(new ProductStore()
                {
                    ExpireDate  = _dataStoreViewModel.ExpireDate,
                    ProductDate = _dataStoreViewModel.ProductDate,
                    ProductID   = _dataStoreViewModel.ProductID,
                    Qtu         = qtu,
                    StoreID     = Convert.ToInt32(StoreCombo.SelectedValue),
                });
                context.Logs.Add(logs);
                if (context.SaveChanges() > 0)
                {
                    MessageBox.Show("Successfull Move to Another Storage ", "Store", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            else
            {
                foreach (var item in con.results)
                {
                    MessageBox.Show(item.ErrorMessage);
                }
            }
        }