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

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

            GUI.CApp.TraducirForm(this);
        }

        public override void Init(object[] pArgs)
        {
            base.Init(pArgs);
            rowDesde.Properties.Value = DateTime.Today;
            rowHasta.Properties.Value = DateTime.Today;

            Utils.QueryParams qp = new LLNet.Utils.QueryParams();
            qp.AddReplaceParam("DESDE", Convert.ToDateTime(rowDesde.Properties.Value).ToString("dd/MM/yyyy"));
            qp.AddReplaceParam("HASTA", Convert.ToDateTime(rowHasta.Properties.Value).ToString("dd/MM/yyyy"));
            dsPDV1.TDA_V_VENTAS_USUARIO.Clear();
            Utils.Helpers.Merge(GUI.CApp.bll.getTypedDataSet(dsPDV1.GetType(), dsPDV1.TDA_V_VENTAS_USUARIO.TableName, qp), dsPDV1);

        }

        private void frmVendorSales_Load(object sender, EventArgs e)
        {
        }

        private void btnSalir_Click(object sender, EventArgs e)
        {
            Program.CloseWindow(this);
        }

        private void frmVendorSales_KeyDown(object sender, KeyEventArgs e)
        {
            switch (e.KeyCode)
            {
                case Keys.Escape :
                    btnSalir_Click(null, null);
                    break;
                case Keys.F10 :
                    btnImprimir.PerformClick();
                    break;
            }
        }

        private void repDesde_DateTimeChanged(object sender, EventArgs e)
        {
            Utils.QueryParams qp = new LLNet.Utils.QueryParams();
            qp.AddReplaceParam("DESDE", ((DevExpress.XtraEditors.DateEdit)sender).DateTime.ToString("dd/MM/yyyy"));
            qp.AddReplaceParam("HASTA", Convert.ToDateTime(rowHasta.Properties.Value).ToString("dd/MM/yyyy"));
            dsPDV1.TDA_V_VENTAS_USUARIO.Clear();
            Utils.Helpers.Merge(GUI.CApp.bll.getTypedDataSet(dsPDV1.GetType(), dsPDV1.TDA_V_VENTAS_USUARIO.TableName, qp), dsPDV1);
        }

        private void datHasta_DateTimeChanged(object sender, EventArgs e)
        {
            Utils.QueryParams qp = new LLNet.Utils.QueryParams();
            qp.AddReplaceParam("DESDE", Convert.ToDateTime(rowDesde.Properties.Value).ToString("dd/MM/yyyy"));
            qp.AddReplaceParam("HASTA", ((DevExpress.XtraEditors.DateEdit)sender).DateTime.ToString("dd/MM/yyyy"));
            dsPDV1.TDA_V_VENTAS_USUARIO.Clear();
            Utils.Helpers.Merge(GUI.CApp.bll.getTypedDataSet(dsPDV1.GetType(), dsPDV1.TDA_V_VENTAS_USUARIO.TableName, qp), dsPDV1);
        }

        private void btnImprimir_Click(object sender, EventArgs e)
        {
            DevExpress.XtraPrinting.PageHeaderArea headerArea;
            DevExpress.XtraPrinting.PageFooterArea footerArea;

            DevExpress.XtraPrinting.PageHeaderFooter header;

            headerArea = new DevExpress.XtraPrinting.PageHeaderArea();
            headerArea.Content.Add("Ventas por Vendedor");
            headerArea.Font = new Font("Arial", 12, System.Drawing.FontStyle.Bold);
            headerArea.LineAlignment = DevExpress.XtraPrinting.BrickAlignment.Near;

            footerArea = new DevExpress.XtraPrinting.PageFooterArea();
            footerArea.LineAlignment = DevExpress.XtraPrinting.BrickAlignment.Far;
            footerArea.Content.Add("");
            footerArea.Content.Add("");
            footerArea.Content.Add("[Date Printed][Time Printed]");

            header = new DevExpress.XtraPrinting.PageHeaderFooter(headerArea, footerArea);
            printableComponentLink1.PageHeaderFooter = header;

            printableComponentLink1.CreateDocument();
            printableComponentLink1.ShowPreview();
        }
    }
}