Ejemplo n.º 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            Global.ClearErrors(errorProvider1, textBoxs);
            string stockType = string.Empty;
            string stockUnit = string.Empty;

            //Type RadioBUtton
            if (ingredient.Checked == true)
            {
                stockType = ingredient.Text;
            }
            else if (spice.Checked == true)
            {
                stockType = spice.Text;
            }
            else if (others.Checked == true)
            {
                stockType = others.Text;
            }

            //Unit RadioButton
            if (gram.Checked == true)
            {
                stockUnit = gram.Text;
            }
            else if (miliLiter.Checked == true)
            {
                stockUnit = miliLiter.Text;
            }
            else if (piece.Checked == true)
            {
                stockUnit = piece.Text;
            }

            var stock = new Stock()
            {
                Name          = name.Text,
                Type          = stockType,
                Qty           = quantity.Text,
                Unit          = stockUnit,
                CriticalLevel = criticalLevel.Text,
            };

            List <List <string> > err;

            if (Global.IsValid <Stock>(stock, out err))
            {
                using (var db = new SunwayCafeContext())
                {
                    if (button1.Text == "Update")
                    {
                        var query = db.Stocks.Where(acc => acc.Id == Id).FirstOrDefault();

                        query.Name          = stock.Name;
                        query.Type          = stock.Type;
                        query.Qty           = stock.Qty;
                        query.Unit          = stock.Unit;
                        query.CriticalLevel = stock.CriticalLevel;
                    }
                    else
                    {
                        db.Stocks.Add(stock);
                    }

                    db.SaveChanges();
                }
                stockPageRef.RefreshListView();
                this.Close();
            }
            else
            {
                foreach (var er in err)
                {
                    errorProvider1.SetError(textBoxs[er[0]], er[1]);
                    textBoxs[er[0]].BorderColor = Color.Red;
                }
            }
        }
Ejemplo n.º 2
0
        private void editProfile_Click(object sender, EventArgs e)
        {
            Global.ClearErrors(errorProvider1, textBoxs);
            var account = new Account()
            {
                Username   = username.Text,
                Password   = password.Text,
                Role       = role.Text,
                FamilyName = familyName.Text,
                GivenName  = givenName.Text,
                Gender     = gender.Text,
                Contact    = contact.Text,
                Email      = email.Text,
            };

            List <List <string> > err;

            if (Global.IsValid <Account>(account, out err))
            {
                using (var db = new SunwayCafeContext())
                {
                    if (editProfile.Text == "Add Staff")
                    {
                        db.Accounts.Add(account);
                    }
                    else
                    {
                        var query = db.Accounts.Where(acc => acc.Id == Id).FirstOrDefault();

                        query.Username   = account.Username;
                        query.Password   = account.Password;
                        query.Role       = account.Role;
                        query.FamilyName = account.FamilyName;
                        query.GivenName  = account.GivenName;
                        query.Gender     = account.Gender;
                        query.Contact    = account.Contact;
                        query.Email      = account.Email;
                    }
                    db.SaveChanges();

                    if (accountPageRef == null)
                    {
                        var query = db.Accounts.Where(acc => acc.Id == Id).FirstOrDefault();
                        Global.user.Details = query;
                        profilePageRef.RefreshPage();
                    }
                    else
                    {
                        accountPageRef.RefreshListView();
                    }
                }

                this.Close();
            }
            else
            {
                foreach (var er in err)
                {
                    errorProvider1.SetError(textBoxs[er[0]], er[1]);
                    textBoxs[er[0]].BorderColor = Color.Red;
                }
            }
        }