using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using C1.Data;

namespace ClientApp
{
    /// <summary>
    /// Summary description for Form1.
    /// </summary>
    public class Form1 : System.Windows.Forms.Form
    {
        private C1.Data.C1DataSet c1DataSet1;
        private System.Windows.Forms.Label label2;
        private System.Windows.Forms.Label label3;
        private System.Windows.Forms.Button buttonShowItems;
        private C1.Win.C1TrueDBGrid.C1TrueDBGrid gridOrders;
        private C1.Win.C1TrueDBGrid.C1TrueDBGrid gridCustomers;
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.Container components = null;

        public Form1()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //
            // TODO: Add any constructor code after InitializeComponent call
            //
        }

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (components != null)
                {
                    components.Dispose();
                }
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
            this.c1DataSet1 = new C1.Data.C1DataSet();
            this.gridCustomers = new C1.Win.C1TrueDBGrid.C1TrueDBGrid();
            this.label2 = new System.Windows.Forms.Label();
            this.label3 = new System.Windows.Forms.Label();
            this.gridOrders = new C1.Win.C1TrueDBGrid.C1TrueDBGrid();
            this.buttonShowItems = new System.Windows.Forms.Button();
            ((System.ComponentModel.ISupportInitialize)(this.c1DataSet1)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.gridCustomers)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.gridOrders)).BeginInit();
            this.SuspendLayout();
            // 
            // c1DataSet1
            // 
            this.c1DataSet1.BindingContextCtrl = null;
            this.c1DataSet1.DataLibrary = "DataLibrary1";
            this.c1DataSet1.DataLibraryUrl = "";
            this.c1DataSet1.DataSetDef = "DataSet";
            this.c1DataSet1.Locale = new System.Globalization.CultureInfo("en-US");
            this.c1DataSet1.SchemaClassName = "DataLibrary1.DataClass";
            this.c1DataSet1.SchemaDef = null;
            this.c1DataSet1.SuppressNotifications = false;
            // 
            // gridCustomers
            // 
            this.gridCustomers.AllowFilter = true;
            this.gridCustomers.AllowRowSizing = C1.Win.C1TrueDBGrid.RowSizingEnum.AllRows;
            this.gridCustomers.AllowSort = true;
            this.gridCustomers.CaptionHeight = 17;
            this.gridCustomers.CollapseColor = System.Drawing.Color.Black;
            this.gridCustomers.DataChanged = false;
            this.gridCustomers.DataMember = "_Customers";
            this.gridCustomers.DataSource = this.c1DataSet1;
            this.gridCustomers.BackColor = System.Drawing.Color.Empty;
            this.gridCustomers.ExpandColor = System.Drawing.Color.Black;
            this.gridCustomers.Images.Add(((System.Drawing.Bitmap)(resources.GetObject("resource.Images"))));
            this.gridCustomers.Location = new System.Drawing.Point(8, 32);
            this.gridCustomers.MarqueeStyle = C1.Win.C1TrueDBGrid.MarqueeEnum.DottedCellBorder;
            this.gridCustomers.Name = "gridCustomers";
            this.gridCustomers.PreviewInfo.Location = new System.Drawing.Point(0, 0);
            this.gridCustomers.PreviewInfo.Size = new System.Drawing.Size(0, 0);
            this.gridCustomers.PreviewInfo.ZoomFactor = 75;
            this.gridCustomers.RecordSelectorWidth = 16;
            this.gridCustomers.RowHeight = 15;
            this.gridCustomers.RowSubDividerColor = System.Drawing.Color.DarkGray;
            this.gridCustomers.ScrollTips = false;
            this.gridCustomers.Size = new System.Drawing.Size(136, 216);
            this.gridCustomers.TabIndex = 1;
            this.gridCustomers.Text = "c1TrueDBGrid1";
            this.gridCustomers.PropBag = ((string)(resources.GetObject("gridCustomers.PropBag")));
            // 
            // label2
            // 
            this.label2.Location = new System.Drawing.Point(8, 8);
            this.label2.Name = "label2";
            this.label2.TabIndex = 2;
            this.label2.Text = "Customer:";
            // 
            // label3
            // 
            this.label3.Location = new System.Drawing.Point(160, 8);
            this.label3.Name = "label3";
            this.label3.TabIndex = 3;
            this.label3.Text = "Orders:";
            // 
            // gridOrders
            // 
            this.gridOrders.AllowFilter = true;
            this.gridOrders.AllowRowSizing = C1.Win.C1TrueDBGrid.RowSizingEnum.AllRows;
            this.gridOrders.AllowSort = true;
            this.gridOrders.CaptionHeight = 17;
            this.gridOrders.CollapseColor = System.Drawing.Color.Black;
            this.gridOrders.DataChanged = false;
            this.gridOrders.DataMember = "_Customers.Customers - Orders";
            this.gridOrders.DataSource = this.c1DataSet1;
            this.gridOrders.BackColor = System.Drawing.Color.Empty;
            this.gridOrders.ExpandColor = System.Drawing.Color.Black;
            this.gridOrders.Images.Add(((System.Drawing.Bitmap)(resources.GetObject("resource.Images1"))));
            this.gridOrders.Location = new System.Drawing.Point(160, 32);
            this.gridOrders.MarqueeStyle = C1.Win.C1TrueDBGrid.MarqueeEnum.DottedCellBorder;
            this.gridOrders.Name = "gridOrders";
            this.gridOrders.PreviewInfo.Location = new System.Drawing.Point(0, 0);
            this.gridOrders.PreviewInfo.Size = new System.Drawing.Size(0, 0);
            this.gridOrders.PreviewInfo.ZoomFactor = 75;
            this.gridOrders.RecordSelectorWidth = 16;
            this.gridOrders.RowHeight = 15;
            this.gridOrders.RowSubDividerColor = System.Drawing.Color.DarkGray;
            this.gridOrders.ScrollTips = false;
            this.gridOrders.Size = new System.Drawing.Size(472, 216);
            this.gridOrders.TabIndex = 4;
            this.gridOrders.Text = "c1TrueDBGrid2";
            this.gridOrders.PropBag = ((string)(resources.GetObject("gridOrders.PropBag")));
            // 
            // buttonShowItems
            // 
            this.buttonShowItems.Location = new System.Drawing.Point(8, 264);
            this.buttonShowItems.Name = "buttonShowItems";
            this.buttonShowItems.Size = new System.Drawing.Size(280, 23);
            this.buttonShowItems.TabIndex = 6;
            this.buttonShowItems.Text = "Edit selected order (open a modeless form)";
            this.buttonShowItems.Click += new System.EventHandler(this.buttonShowItems_Click);
            // 
            // Form1
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(648, 301);
            this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                          this.buttonShowItems,
                                                                          this.gridOrders,
                                                                          this.label3,
                                                                          this.label2,
                                                                          this.gridCustomers});
            this.Name = "Form1";
            this.Text = "Resolving Concurrency Conflicts";
            ((System.ComponentModel.ISupportInitialize)(this.c1DataSet1)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.gridCustomers)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.gridOrders)).EndInit();
            this.ResumeLayout(false);

        }
        #endregion

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }

        private void buttonShowItems_Click(object sender, System.EventArgs e)
        {
            ViewOrderForm form = new ViewOrderForm();

            int rowIndex = gridCustomers.Row;
            if (rowIndex == -1)
                return;

            C1DataRow row = c1DataSet1.Tables["Customers"].Rows[rowIndex];
            if (row == null)
                return;

            C1DataRow[] orders = row.GetChildRows();
            int orderIndex = gridOrders.Row;
            if (orders.Length > orderIndex)
            {
                int orderId = System.Convert.ToInt32(orders[orderIndex]["OrderID"]);
                form.OrderID = orderId;
                form.Show();
            }
        }
    }
}
