using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace LLNet.Tienda.MainForms.Forms
{
    public partial class frmResumenJornada : LLNet.GUI.FormBases.frmBase
    {
        public frmResumenJornada()
        {
            InitializeComponent();

            GUI.CApp.TraducirForm(this);
        }

        private void gridControl1_Click(object sender, EventArgs e)
        {

        }

        private void frmResumenJornada_Load(object sender, EventArgs e)
        {
            Utils.QueryParams qParams = new LLNet.Utils.QueryParams();
            qParams.AddReplaceParam("USUARIO", GUI.CApp.usuario);
            qParams.AddReplaceParam("JORNADA", Program.Jornada.ToString());
            qParams.AddReplaceParam("FORMATO", "NVL(cg_f_parameter_value('FCCJ'),'20')");
            GUI.CApp.bll.ExecuteSql("CierreCaja", qParams, "PDV").ToString();
            Utils.Helpers.Merge(GUI.CApp.bll.getTypedDataSet(dsPDV1.GetType(), dsPDV1.JORNADA.TableName, qParams), dsPDV1);
        }

        public override void Init(object[] pArgs)
        {
            base.Init(pArgs);
            // Formateando columnas
            this.gridControl1.Styles.AddReplace("CenterStyle", new DevExpress.Utils.ViewStyleEx("CenterStyle", "", "", true, false, false, DevExpress.Utils.HorzAlignment.Center, DevExpress.Utils.VertAlignment.Center, null, System.Drawing.SystemColors.Window, System.Drawing.SystemColors.WindowText, System.Drawing.Color.Empty, System.Drawing.Drawing2D.LinearGradientMode.Horizontal));
            this.gridControl1.Styles.AddReplace("RightStyle", new DevExpress.Utils.ViewStyleEx("RightStyle", "", "", true, false, false, DevExpress.Utils.HorzAlignment.Far, DevExpress.Utils.VertAlignment.Center, null, System.Drawing.SystemColors.Window, System.Drawing.SystemColors.WindowText, System.Drawing.Color.Empty, System.Drawing.Drawing2D.LinearGradientMode.Horizontal));
            this.gridControl1.Styles.AddReplace("LeftStyle", new DevExpress.Utils.ViewStyleEx("LeftStyle", "", "", true, false, false, DevExpress.Utils.HorzAlignment.Near, DevExpress.Utils.VertAlignment.Center, null, System.Drawing.SystemColors.Window, System.Drawing.SystemColors.WindowText, System.Drawing.Color.Empty, System.Drawing.Drawing2D.LinearGradientMode.Horizontal));

        }

        private void gridView1_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
        {
            if (this.dsPDV1.JORNADA.Rows[e.RowHandle]["TAMAŅO"].ToString() == "12" || this.dsPDV1.JORNADA.Rows[e.RowHandle]["ATRIBUTOS"].ToString().IndexOf("B") >= 0)
                e.Appearance.Font = new Font("Microsft Sans Serif", 8, (System.Drawing.FontStyle)5);
            if (e.Column.VisibleIndex == 0)
                e.Appearance.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Near;
            else if (e.Column.VisibleIndex == 1 || e.Column.VisibleIndex == 2 || e.Column.VisibleIndex == 3 || e.Column.VisibleIndex == 4)
                switch (this.dsPDV1.JORNADA.Rows[e.RowHandle]["ALINEACION"].ToString())
                {
                    case "1":
                        e.Appearance.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;
                        break;
                    case "2":
                        e.Appearance.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Near;
                        break;
                    case "3":
                        e.Appearance.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Far;
                        break;
                }

        }

        private void Margenes(string p_tipo, DevExpress.XtraPrinting.PrintableComponentLink p_link, DevExpress.XtraGrid.GridControl p_grid, DevExpress.XtraGrid.Views.Grid.GridView p_grid_view)
        {
            int v_ancho_grid = p_grid.Width;
            DockStyle p_dock_style = p_grid.Dock;
            int v_ancho;
            LLNet.Utils.QueryParams qParams = new LLNet.Utils.QueryParams();
            switch (p_tipo)
            {
                case "0":
                case "2":
                    p_grid_view.OptionsPrint.AutoWidth = false;
                    p_grid_view.OptionsPrint.PrintHorzLines = false;
                    p_grid.Dock = DockStyle.None;
                    // Verificando si el grid esta agrupado			
                    try
                    {
                        qParams.AddReplaceParam("RV_DOMAIN", "TIPO IMPRESORA");
                        qParams.AddReplaceParam("RV_LOW_VALUE", p_tipo.ToString());
                        v_ancho = System.Convert.ToInt32(GUI.CApp.bll.GetSingleValue("CG_REF_CODES.RV_MPNC01", qParams, "General").ToString());
                        v_ancho = v_ancho * 4;
                    }
                    catch
                    {
                        v_ancho = 260;
                    }
                    p_grid.Width = v_ancho;			// 64.1 mm 58.1 mm
                    p_link.Margins.Left = 22;		//  5.5 mm
                    p_link.Margins.Right = 25;	//  6.4 mm
                    p_link.Margins.Top = 106;		// 27.0 mm
                    p_link.Margins.Bottom = 70;	// 17.5 mm
                    break;
                case "1":
                default:
                    p_grid_view.OptionsPrint.AutoWidth = true;
                    p_grid_view.OptionsPrint.PrintHorzLines = false;
                    p_link.Margins.Left = 75;
                    p_link.Margins.Right = 75;
                    p_link.Margins.Top = 100;
                    p_link.Margins.Bottom = 75;
                    break;
            }
            p_link.CreateDocument();
            p_link.ShowPreviewDialog();
            p_grid.Width = v_ancho_grid;
            p_grid.Dock = p_dock_style;
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            Margenes("0", this.printableComponentLink1, this.gridControl1, this.gridView1);
            DialogResult = DialogResult.OK;
        }

        private void panelControl1_Paint(object sender, PaintEventArgs e)
        {

        }

        private void simpleButton2_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
        }

        private void frmResumenJornada_KeyDown(object sender, KeyEventArgs e)
        {
            switch (e.KeyCode)
            { 
                case Keys.F12:
                    simpleButton1_Click(null, null);
                    break;
                case Keys.Escape:
                    simpleButton2_Click(null, null);
                    break;
            }
        }
    }
}

