StoresAndStockPricingForm.cs :  » Persistence-Frameworks » Ubik » StoresAndStockPricing » Client » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Persistence Frameworks » Ubik 
Ubik » StoresAndStockPricing » Client » StoresAndStockPricingForm.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Ubik.Engine.Client;
using StoresAndStockPricing.Controls;
using StoresAndStockPricing.Model;

namespace StoresAndStockPricing.Client{
  public partial class StoresAndStockPricingForm : Form
  {
    private Session _session;
    BoundComboBoxSource<RetailStore> _viewPriceAtComboSource;
    BoundDataGridViewSource<Manufacturer> _manufacturerGridSource;
    BoundDataGridViewSource<Brand> _brandGridSource;
    BoundDataGridViewSource<StockItemSellingPrice> _stockItemGridSource;

    public StoresAndStockPricingForm()
    {
      InitializeComponent();
    }

    public StoresAndStockPricingForm(Session session, string serverUri)
      : this()
    {
      if (session == null)
        throw new ArgumentNullException("session");

      if (serverUri == null)
        throw new ArgumentNullException("serverUri");

      _session = session;
      _serverUriStatusLabel.Text = serverUri;

      // Bind the "Stock Item Selling Price at" combo box

      _viewPriceAtComboSource = new BoundComboBoxSource<RetailStore>(
        _session,
        delegate(Session s, RetailStore store)
        {
          return store.Name;
        });

      _viewPriceAtComboSource.Filter = "";

      _viewPriceAtCombo.DataSource = _viewPriceAtComboSource;

      // Bind the "Manufacturer" data grid

      _manufacturerGridSource = new BoundDataGridViewSource<Manufacturer>(_session);

      _manufacturerGridSource.Columns.Add(new StringColumn<Manufacturer>(
        _session,
        StoresAndStockPricingFormResources.Manufacturer,
        delegate(Session s, Manufacturer manufacturer)
        {
          return manufacturer.Name;
        }));

      _manufacturerGridSource.Filter = "";

      _manufacturerGrid.BindingSource = _manufacturerGridSource;

      // Bind the "Brand" data grid

      _brandGridSource = new BoundDataGridViewSource<Brand>(_session);

      _brandGridSource.Columns.Add(new StringColumn<Brand>(
        _session,
        StoresAndStockPricingFormResources.Brand,
        delegate(Session s, Brand brand)
        {
          return brand.Name;
        }));

      _brandGrid.BindingSource = _brandGridSource;

      // Bind the "Stock Item" data grid

      _stockItemGridSource = new BoundDataGridViewSource<StockItemSellingPrice>(_session,
        new Type[] { typeof(StockItem), typeof(Brand), typeof(Manufacturer) },
        delegate(Session s, StockItemSellingPrice stockItemSellingPrice, Guid identity)
        {
          return identity == stockItemSellingPrice.StockItem.Identity ||
            identity == stockItemSellingPrice.StockItem.Brand.Identity ||
            identity == stockItemSellingPrice.StockItem.Brand.Manufacturer.Identity;
        });

      _stockItemGridSource.Columns.Add(new StringColumn<StockItemSellingPrice>(
        _session,
        StoresAndStockPricingFormResources.StockItem,
        delegate(Session s, StockItemSellingPrice stockItemSellingPrice)
        {
          return stockItemSellingPrice.StockItem.Name;
        },
        delegate(Session s, StockItemSellingPrice stockItemSellingPrice, string value)
        {
          stockItemSellingPrice.StockItem.Name = value;
        }));

      _stockItemGridSource.Columns.Add(new StringColumn<StockItemSellingPrice>(
        _session,
        StoresAndStockPricingFormResources.SellingPrice,
        delegate(Session s, StockItemSellingPrice stockItemSellingPrice)
        {
          return string.Format("{0:c}", stockItemSellingPrice.SellingPrice);
        }));

      _stockItemGridSource.Columns.Add(new StringColumn<StockItemSellingPrice>(
        _session,
        StoresAndStockPricingFormResources.EffectiveSince,
        delegate(Session s, StockItemSellingPrice stockItemSellingPrice)
        {
          return stockItemSellingPrice.EffectiveSince.ToLocalTime().ToString(); ;
        }));

      _stockItemGridSource.Columns.Add(new StringColumn<StockItemSellingPrice>(
        _session,
        StoresAndStockPricingFormResources.Manufacturer,
        delegate(Session s, StockItemSellingPrice stockItemSellingPrice)
        {
          return stockItemSellingPrice.StockItem.Brand.Manufacturer.Name;
        }));

      _stockItemGridSource.Columns.Add(new StringColumn<StockItemSellingPrice>(
        _session,
        StoresAndStockPricingFormResources.Brand,
        delegate(Session s, StockItemSellingPrice stockItemSellingPrice)
        {
          return stockItemSellingPrice.StockItem.Brand.Name;
        }));

      _stockItemSellingPriceGrid.BindingSource = _stockItemGridSource;

      // Bind Events

      _manufacturerGrid.SelectionChanged += new System.EventHandler(_manufacturerGrid_SelectionChanged);
      _brandGrid.SelectionChanged += new System.EventHandler(_brandGrid_SelectionChanged);
      _viewPriceAtCombo.SelectedValueChanged += new System.EventHandler(_viewPriceAtCombo_SelectedValueChanged);
      _stockItemSellingPriceGrid.SelectionChanged += new EventHandler(_stockItemSellingPriceGrid_SelectionChanged);
    }

    private void _manufacturerGrid_SelectionChanged(object sender, EventArgs e)
    {
      UpdateBrandFilter();

      _manufacturerDetailsButton.Enabled = _manufacturerGrid.SelectedRows.Count == 1;
      _newBrandButton.Enabled = _manufacturerGrid.SelectedRows.Count == 1;
    }

    private void UpdateBrandFilter()
    {
      string filter = "";

      foreach (Manufacturer manufacturer in _manufacturerGrid.GetSelectedItems<Manufacturer>())
      {
        if (filter.Length != 0)
        {
          filter += " || ";
        }

        filter += "Manufacturer = {" + manufacturer.ToString() + "}";
      }

      if (filter.Length > 0)
      {
        _brandGridSource.Filter = filter;
      }
      else
      {
        _brandGridSource.Clear();
      }
    }

    private void _brandGrid_SelectionChanged(object sender, EventArgs e)
    {
      UpdateStockItemFilter();

      _brandDetailsButton.Enabled = _brandGrid.SelectedRows.Count == 1;
      _newStockItemButton.Enabled = _brandGrid.SelectedRows.Count == 1;
    }

    private void UpdateStockItemFilter()
    {
      string filter = "";

      foreach (Brand brand in _brandGrid.GetSelectedItems<Brand>())
      {
        if (filter.Length != 0)
        {
          filter += " || ";
        }

        filter += "RetailStore = {" + _viewPriceAtCombo.GetSelectedItem<RetailStore>().ToString() +
          "} && StockItem.Brand = {" + brand.ToString() + "}";
      }

      if (filter.Length > 0)
      {
        _stockItemGridSource.Filter = filter;
      }
      else
      {
        _stockItemGridSource.Clear();
      }
    }

    private void _newManufacturerButton_Click(object sender, EventArgs e)
    {
      using (Transaction txn = _session.BeginTransaction())
      {
        Manufacturer newManufacturer = new Manufacturer(_session, StoresAndStockPricingFormResources.NewManufacturerName);
        newManufacturer.Insert();

        ManufacturerDetailsForm mdf = new ManufacturerDetailsForm(_session, newManufacturer);
        if (mdf.ShowDialog(this) == DialogResult.OK)
        {
          txn.Commit();

          _manufacturerGrid.SelectItem<Manufacturer>(newManufacturer);
        }
        else
        {
          txn.Abort();
        }
      }
    }

    private void _manufacturerDetailsButton_Click(object sender, EventArgs e)
    {
      using (Transaction txn = _session.BeginTransaction())
      {
        Manufacturer manufacturer = _manufacturerGrid.GetSelectedItem<Manufacturer>();

        ManufacturerDetailsForm mdf = new ManufacturerDetailsForm(_session, manufacturer);
        if (mdf.ShowDialog(this) == DialogResult.OK)
        {
          txn.Commit();
        }
        else
        {
          txn.Abort();
        }
      }
    }

    private void _newBrandButton_Click(object sender, EventArgs e)
    {
      using (Transaction txn = _session.BeginTransaction())
      {
        Brand newBrand = new Brand(_session, StoresAndStockPricingFormResources.NewBrandName, _manufacturerGrid.GetSelectedItem<Manufacturer>());
        newBrand.Insert();

        BrandDetailsForm bdf = new BrandDetailsForm(_session, newBrand);
        if (bdf.ShowDialog(this) == DialogResult.OK)
        {
          txn.Commit();

          _brandGrid.SelectItem<Brand>(newBrand);
        }
        else
        {
          txn.Abort();
        }
      }
    }

    private void _brandDetailsButton_Click(object sender, EventArgs e)
    {
      using (Transaction txn = _session.BeginTransaction())
      {
        Brand brand = _brandGrid.GetSelectedItem<Brand>();

        BrandDetailsForm bdf = new BrandDetailsForm(_session, brand);
        if (bdf.ShowDialog(this) == DialogResult.OK)
        {
          txn.Commit();
        }
        else
        {
          txn.Abort();
        }
      }
    }

    private void _viewPriceAtCombo_SelectedValueChanged(object sender, EventArgs e)
    {
      UpdateStockItemFilter();
    }

    private void _deleteButton_Click(object sender, EventArgs e)
    {
      if (MessageBox.Show(StoresAndStockPricingFormResources.DeleteConfirmation, Text, MessageBoxButtons.YesNo) == DialogResult.Yes)
      {
        using (Transaction txn = _session.BeginTransaction())
        {
          foreach (StockItemSellingPrice selection in _stockItemSellingPriceGrid.GetSelectedItems<StockItemSellingPrice>())
          {
            selection.StockItem.Delete();
          }

          txn.Commit();
        }
      }
    }

    void _stockItemSellingPriceGrid_SelectionChanged(object sender, EventArgs e)
    {
      _deleteButton.Enabled = _stockItemSellingPriceGrid.SelectedRows.Count > 0;
      _schedulePriceChangeButton.Enabled = _stockItemSellingPriceGrid.SelectedRows.Count == 1;
    }

    private void _schedulePriceChangeButton_Click(object sender, EventArgs e)
    {
      using (Transaction txn = _session.BeginTransaction())
      {
        StockItem stockItem = _stockItemSellingPriceGrid.GetSelectedItem<StockItemSellingPrice>().StockItem;
        RetailStoreGroup defaultGroup = _viewPriceAtCombo.GetSelectedItem<RetailStore>().SystemGroup;

        SchedulePriceChangeForm pcf = new SchedulePriceChangeForm(_session, stockItem, defaultGroup);
        if (pcf.ShowDialog(this) == DialogResult.OK)
        {
          txn.Commit();
        }
        else
        {
          txn.Abort();
        }
      }
    }

    private void _newStockItemButton_Click(object sender, EventArgs e)
    {
      StockItem newStockItem;

      using (Transaction txn = _session.BeginTransaction())
      {
        newStockItem = new StockItem(_session,
          StoresAndStockPricingFormResources.NewStockItemName,
          _brandGrid.GetSelectedItem<Brand>());
        newStockItem.Insert();

        newStockItem.ChangeSellingPrice(0M);

        txn.Commit();
      }

      _stockItemSellingPriceGrid.SelectItem<StockItemSellingPrice>(
        newStockItem.GetPriceAt(_viewPriceAtCombo.GetSelectedItem<RetailStore>()));

      _stockItemSellingPriceGrid.CurrentCell =
        _stockItemSellingPriceGrid.SelectedRows[0].Cells[0];
      _stockItemSellingPriceGrid.BeginEdit(true);
    }


  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.