コード例 #1
0
ファイル: frmDrinkEditor.cs プロジェクト: micolous/lloyd
        public frmDrinkEditor(Beverage b )
        {
            InitializeComponent();
            cboAlcoholMode.SelectedIndex = 0;

            this.session.FlushMode = FlushMode.Commit;
            this.transaction = this.session.BeginTransaction();
            this.b = b;

            create_mode = (this.b == null);
            groupSKU.Enabled = !create_mode;

            if (create_mode)
            {
                this.b = new Beverage();
                this.b.IsEnabled = true;

                // hide skus because we can't create them until an object exists.
                dgvSKUs.Enabled = dgvSKUs.Visible = groupSKU.Visible = groupSKU.Enabled = false;
                Height -= groupSKU.Height;

                Text = String.Format(Text, "New Drink");
            }
            else
            {
                txtName.Text = this.b.Name;
                nudVolume.Value = (decimal)this.b.Volume;
                nudAlcohol.Value = (decimal)this.b.PercentAlcohol;

                bsSKU = new BindingSource();

                var ls = session.CreateCriteria(typeof(Sku))
                    .Add(Restrictions.Eq("Beverage", this.b))
                    .List<Sku>();
                bsSKU.DataSource = ls;
                bsSKU.AllowNew = true;

                //bsSKU.ListChanged += new ListChangedEventHandler(bsSKU_ListChanged);
                bsSKU.CurrentChanged += new EventHandler(bsSKU_CurrentChanged);

                dgvSKUs.DataSource = bsSKU;
                //skuBindingSource.Filter = string.Format("Beverage = '{0}'", this.b.Id);
                Text = String.Format(Text, this.b.Name + " (" + this.b.Id + ")");
            }

            saved = true;
        }
コード例 #2
0
ファイル: Factory.cs プロジェクト: micolous/lloyd
        private void PopulateInitialData()
        {
            using (var session = SessionFactory.OpenSession())
            {
                using (var transaction = session.BeginTransaction())
                {
                    var adminUser = new User { Name = "admin", IsEnabled = true, IsAdmin = true, LastAccess = DateTime.Now };
                    adminUser.EncodeAccessKey("0000");
                    session.SaveOrUpdate(adminUser);

                    var testBeverage = new Beverage { Name = "Example Beer", IsEnabled = true, PercentAlcohol = 4.5, Volume = 375 };
                    session.SaveOrUpdate(testBeverage);

                    transaction.Commit();
                }
            }
        }