Mini Kabibi Habibi

Current Path : C:/Users/Public/Documents/DXperience 13.1 Demos/WinForms/CS/GridMainDemo/Modules/
Upload File :
Current File : C:/Users/Public/Documents/DXperience 13.1 Demos/WinForms/CS/GridMainDemo/Modules/Styles.cs

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.OleDb;
using DevExpress.Utils;
using DevExpress.XtraGrid.Views.Base;

namespace DevExpress.XtraGrid.Demos {
    /// <summary>
    /// Summary description for Styles.
    /// </summary>
    public partial class Styles : TutorialControl {
        public Styles() {
            //
            // Required for Windows Form Designer support
            //
            CreateWaitDialog();
            InitializeComponent();

            InitNWindData();
            InitAppearance();
            //
            // TODO: Add any constructor code after InitializeComponent call
            //
        }
        DevExpress.XtraGrid.Design.XAppearances xapp;
        bool styleUpdate = false;

        protected override bool AllowAppearanceGroup { get { return false; } }
        public override DevExpress.XtraGrid.Views.Base.BaseView ExportView { get { return CurrentGrid.MainView; } 
        }
        #region Init

        private void Styles_Load(object sender, System.EventArgs e) {
            xapp = new DevExpress.XtraGrid.Design.XAppearances(System.Environment.GetFolderPath(System.Environment.SpecialFolder.System) + "\\DevExpress.XtraGrid.Appearances.xml ");
            InitStyles();
        }
        private GridControl CurrentGrid {
            get {
                switch(xtcViews.SelectedTabPageIndex) {
                    case 1:
                        return gridControl2;
                    case 2:
                        return gridControl3;
                }
                return gridControl1;
            }
        }
        private DevExpress.XtraGrid.Blending.XtraGridBlending CurrentBlending {
            get {
                switch(xtcViews.SelectedTabPageIndex) {
                    case 1:
                        return xtraGridBlending2;
                    case 2:
                        return xtraGridBlending3;
                }
                return xtraGridBlending1;
            }
        }
        private void InitMenu() {
            GridRibbonMenuManager.InitBlendingMenu(CurrentBlending);
        }
        protected override void InitMDBData(string connectionString) {
            DataSet dataSet = new DataSet();
            OleDbDataAdapter oleDBAdapter = new OleDbDataAdapter("SELECT * FROM Customers", connectionString);

            SetWaitDialogCaption(Properties.Resources.LoadingCustomers);
            oleDBAdapter.Fill(dataSet, "Customers");
            gridControl2.DataSource = dataSet.Tables["Customers"];
        }
        protected override void InitXMLData(string dataFileName) {
            DataSet dataSet = new DataSet();
            SetWaitDialogCaption(Properties.Resources.LoadingTables);
            dataSet.ReadXml(dataFileName);

            gridControl2.DataSource = dataSet.Tables["Customers"];

        }
        protected override void InitNWindData() {
            base.InitNWindData();
            InitData();
        }
        private void InitData() {
            DataSet dataSet;
            string DBFileName = DevExpress.Utils.FilesHelper.FindingFileName(Application.StartupPath, "Data\\Cars.xml");
            if(DBFileName != "") {
                dataSet = new DataSet();
                SetWaitDialogCaption(Properties.Resources.LoadingCars);
                dataSet.ReadXml(DBFileName);
                gridControl1.DataSource = dataSet.Tables[0].DefaultView;
            }
            DBFileName = DevExpress.Utils.FilesHelper.FindingFileName(Application.StartupPath, "Data\\DXProducts.xml");
            if(DBFileName != "") {
                dataSet = new DataSet();
                SetWaitDialogCaption(Properties.Resources.LoadingDXProducts);
                dataSet.ReadXml(DBFileName);
                gridControl3.DataSource = dataSet.Tables[0].DefaultView;
            }
        }

        private void InitStyles() {
            try {
                cbeStyles.Properties.Items.Clear();
                cbeStyles.Properties.Items.AddRange(xapp.FormatNames);
                gridControl1.Tag = 1;
                gridControl2.Tag = 4;
                gridControl3.Tag = 5;
                cbeStyles.SelectedIndex = Convert.ToInt32(CurrentGrid.Tag);
                xapp.LoadScheme(cbeStyles.Properties.Items[Convert.ToInt32(gridControl1.Tag)].ToString(), gridControl1.MainView);
                xapp.LoadScheme(cbeStyles.Properties.Items[Convert.ToInt32(gridControl2.Tag)].ToString(), gridControl2.MainView);
                xapp.LoadScheme(cbeStyles.Properties.Items[Convert.ToInt32(gridControl3.Tag)].ToString(), gridControl3.MainView);
            }
            catch { }
        }
        private void InitAppearance() {
            gridControl2.ForceInitialize();
            gridControl3.ForceInitialize();
            gridView1.ExpandAllGroups();
            string[] s1 = new string[]{"", "AK", "BC", "CA", "Co. Cork", "DF", "ID",
										  "Isle of Wight", "Lara", "MT", "NM", "Nueva Esparta", "OR", "Quebec",
										  "RJ", "SP", "Tachira", "WA", "WY"};
            string[] s2 = new String[]{"Argentina", "Austria", "Belgium", "Brazil", 
										  "Canada", "Denmark", "F inland", "France", "Germany", "Ireland", "Italy", 
										  "Mexico", "Norway", "Poland", "Portugal", "Spain", "Sweden", "Switzerland", 
										  "UK", "USA", "Venezuela"};
            foreach(string s in s1) repositoryItemComboBox1.Items.Add(s);
            foreach(string s in s2) repositoryItemComboBox2.Items.Add(s);
            cardView1.FocusedRowHandle = 13;
        }
        #endregion
        #region Editing
        private void cbeStyles_SelectedIndexChanged(object sender, System.EventArgs e) {
            if(styleUpdate) return;
            if(cbeStyles.EditValue != null) {
                xapp.LoadScheme(cbeStyles.EditValue.ToString(), CurrentGrid.MainView);
                if(CurrentBlending != null && CurrentBlending.Enabled)
                    CurrentBlending.RefreshStyles();
                CurrentGrid.Tag = cbeStyles.SelectedIndex;
            }
        }


        private void xtraTabControl1_SelectedPageChanged(object sender, DevExpress.XtraTab.TabPageChangedEventArgs e) {
            InitMenu();
            styleUpdate = true;
            cbeStyles.SelectedIndex = Convert.ToInt32(CurrentGrid.Tag);
            styleUpdate = false;
            RibbonMenuManager.AllowExport(CurrentGrid.MainView);
        }

        private void ceNewStyles_CheckedChanged(object sender, System.EventArgs e) {
            if(xapp != null) xapp.ShowNewStylesOnly = ceNewStyles.Checked;
            cbeStyles.Properties.Items.Clear();
            cbeStyles.Properties.Items.AddRange(xapp.FormatNames);
            cbeStyles.SelectedIndex = Convert.ToInt32(CurrentGrid.Tag);
        }
        protected override void OnSetCaption(string caption) {
            base.OnSetCaption(caption);
            InitMenu();
        }

        private void btnEditAppearances_Click(object sender, System.EventArgs e) {
            Appearances frm = new Appearances(CurrentGrid.MainView, this.FindForm());
            frm.ShowDialog();
        }
        #endregion
        #region Grid events
        private void gridView1_CalcPreviewText(object sender, DevExpress.XtraGrid.Views.Grid.CalcPreviewTextEventArgs e) {
            if(gridView1.GetDataRow(e.RowHandle) != null)
                e.PreviewText = Properties.Resources.DescriptionFor + " " + gridView1.GetDataRow(e.RowHandle)["ContactName"].ToString();
        }
        #endregion
    }
}