diff --git a/Estadiscticas.Designer.cs b/Estadiscticas.Designer.cs index d54e503..3b0372d 100644 --- a/Estadiscticas.Designer.cs +++ b/Estadiscticas.Designer.cs @@ -28,12 +28,248 @@ /// private void InitializeComponent() { - this.components = new System.ComponentModel.Container(); + this.dtpBuscar = new System.Windows.Forms.DateTimePicker(); + this.dgvDia = new System.Windows.Forms.DataGridView(); + this.Producto = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Precio = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Cantidad = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Total = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.btnBuscar = new System.Windows.Forms.Button(); + this.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.dgvMes = new System.Windows.Forms.DataGridView(); + this.dataGridViewTextBoxColumn1 = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.dataGridViewTextBoxColumn2 = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.dataGridViewTextBoxColumn3 = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.dataGridViewTextBoxColumn4 = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.lbProductDia = new System.Windows.Forms.Label(); + this.lbVendedorDia = new System.Windows.Forms.Label(); + this.lbTotalDia = new System.Windows.Forms.Label(); + this.lbTotalMes = new System.Windows.Forms.Label(); + this.lbVendedorMes = new System.Windows.Forms.Label(); + this.lbProductoMes = new System.Windows.Forms.Label(); + ((System.ComponentModel.ISupportInitialize)(this.dgvDia)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.dgvMes)).BeginInit(); + this.SuspendLayout(); + // + // dtpBuscar + // + this.dtpBuscar.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.dtpBuscar.Location = new System.Drawing.Point(12, 12); + this.dtpBuscar.Name = "dtpBuscar"; + this.dtpBuscar.Size = new System.Drawing.Size(257, 22); + this.dtpBuscar.TabIndex = 0; + // + // dgvDia + // + this.dgvDia.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dgvDia.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.Producto, + this.Precio, + this.Cantidad, + this.Total}); + this.dgvDia.Location = new System.Drawing.Point(9, 56); + this.dgvDia.Name = "dgvDia"; + this.dgvDia.Size = new System.Drawing.Size(443, 150); + this.dgvDia.TabIndex = 1; + // + // Producto + // + this.Producto.HeaderText = "Producto"; + this.Producto.Name = "Producto"; + this.Producto.ReadOnly = true; + // + // Precio + // + this.Precio.HeaderText = "Precio"; + this.Precio.Name = "Precio"; + this.Precio.ReadOnly = true; + // + // Cantidad + // + this.Cantidad.HeaderText = "Cantidad"; + this.Cantidad.Name = "Cantidad"; + this.Cantidad.ReadOnly = true; + // + // Total + // + this.Total.HeaderText = "Total"; + this.Total.Name = "Total"; + // + // btnBuscar + // + this.btnBuscar.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.btnBuscar.Location = new System.Drawing.Point(299, 11); + this.btnBuscar.Name = "btnBuscar"; + this.btnBuscar.Size = new System.Drawing.Size(75, 23); + this.btnBuscar.TabIndex = 2; + this.btnBuscar.Text = "Buscar"; + this.btnBuscar.UseVisualStyleBackColor = true; + this.btnBuscar.Click += new System.EventHandler(this.btnBuscar_Click); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.label1.Location = new System.Drawing.Point(12, 37); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(109, 16); + this.label1.TabIndex = 3; + this.label1.Text = "Resumen del dia"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.label2.Location = new System.Drawing.Point(15, 268); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(116, 16); + this.label2.TabIndex = 4; + this.label2.Text = "Resumen del mes"; + // + // dgvMes + // + this.dgvMes.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dgvMes.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.dataGridViewTextBoxColumn1, + this.dataGridViewTextBoxColumn2, + this.dataGridViewTextBoxColumn3, + this.dataGridViewTextBoxColumn4}); + this.dgvMes.Location = new System.Drawing.Point(12, 288); + this.dgvMes.Name = "dgvMes"; + this.dgvMes.Size = new System.Drawing.Size(443, 150); + this.dgvMes.TabIndex = 5; + // + // dataGridViewTextBoxColumn1 + // + this.dataGridViewTextBoxColumn1.HeaderText = "Producto"; + this.dataGridViewTextBoxColumn1.Name = "dataGridViewTextBoxColumn1"; + this.dataGridViewTextBoxColumn1.ReadOnly = true; + // + // dataGridViewTextBoxColumn2 + // + this.dataGridViewTextBoxColumn2.HeaderText = "Precio"; + this.dataGridViewTextBoxColumn2.Name = "dataGridViewTextBoxColumn2"; + this.dataGridViewTextBoxColumn2.ReadOnly = true; + // + // dataGridViewTextBoxColumn3 + // + this.dataGridViewTextBoxColumn3.HeaderText = "Cantidad"; + this.dataGridViewTextBoxColumn3.Name = "dataGridViewTextBoxColumn3"; + this.dataGridViewTextBoxColumn3.ReadOnly = true; + // + // dataGridViewTextBoxColumn4 + // + this.dataGridViewTextBoxColumn4.HeaderText = "Total"; + this.dataGridViewTextBoxColumn4.Name = "dataGridViewTextBoxColumn4"; + // + // lbProductDia + // + this.lbProductDia.AutoSize = true; + this.lbProductDia.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.lbProductDia.Location = new System.Drawing.Point(502, 89); + this.lbProductDia.Name = "lbProductDia"; + this.lbProductDia.Size = new System.Drawing.Size(145, 16); + this.lbProductDia.TabIndex = 6; + this.lbProductDia.Text = "Producto mas vendido:"; + // + // lbVendedorDia + // + this.lbVendedorDia.AutoSize = true; + this.lbVendedorDia.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.lbVendedorDia.Location = new System.Drawing.Point(502, 149); + this.lbVendedorDia.Name = "lbVendedorDia"; + this.lbVendedorDia.Size = new System.Drawing.Size(108, 16); + this.lbVendedorDia.TabIndex = 7; + this.lbVendedorDia.Text = "Mejor vendedos:"; + // + // lbTotalDia + // + this.lbTotalDia.AutoSize = true; + this.lbTotalDia.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.lbTotalDia.Location = new System.Drawing.Point(318, 213); + this.lbTotalDia.Name = "lbTotalDia"; + this.lbTotalDia.Size = new System.Drawing.Size(85, 16); + this.lbTotalDia.TabIndex = 8; + this.lbTotalDia.Text = "Total del dia:"; + // + // lbTotalMes + // + this.lbTotalMes.AutoSize = true; + this.lbTotalMes.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.lbTotalMes.Location = new System.Drawing.Point(318, 441); + this.lbTotalMes.Name = "lbTotalMes"; + this.lbTotalMes.Size = new System.Drawing.Size(92, 16); + this.lbTotalMes.TabIndex = 9; + this.lbTotalMes.Text = "Total del Mes:"; + // + // lbVendedorMes + // + this.lbVendedorMes.AutoSize = true; + this.lbVendedorMes.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.lbVendedorMes.Location = new System.Drawing.Point(502, 383); + this.lbVendedorMes.Name = "lbVendedorMes"; + this.lbVendedorMes.Size = new System.Drawing.Size(108, 16); + this.lbVendedorMes.TabIndex = 11; + this.lbVendedorMes.Text = "Mejor vendedos:"; + // + // lbProductoMes + // + this.lbProductoMes.AutoSize = true; + this.lbProductoMes.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.lbProductoMes.Location = new System.Drawing.Point(502, 324); + this.lbProductoMes.Name = "lbProductoMes"; + this.lbProductoMes.Size = new System.Drawing.Size(145, 16); + this.lbProductoMes.TabIndex = 10; + this.lbProductoMes.Text = "Producto mas vendido:"; + // + // Estadiscticas + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); + this.ClientSize = new System.Drawing.Size(800, 482); + this.Controls.Add(this.lbVendedorMes); + this.Controls.Add(this.lbProductoMes); + this.Controls.Add(this.lbTotalMes); + this.Controls.Add(this.lbTotalDia); + this.Controls.Add(this.lbVendedorDia); + this.Controls.Add(this.lbProductDia); + this.Controls.Add(this.dgvMes); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Controls.Add(this.btnBuscar); + this.Controls.Add(this.dgvDia); + this.Controls.Add(this.dtpBuscar); + this.Name = "Estadiscticas"; this.Text = "Estadiscticas"; + ((System.ComponentModel.ISupportInitialize)(this.dgvDia)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.dgvMes)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + } #endregion + + private System.Windows.Forms.DateTimePicker dtpBuscar; + private System.Windows.Forms.DataGridView dgvDia; + private System.Windows.Forms.DataGridViewTextBoxColumn Producto; + private System.Windows.Forms.DataGridViewTextBoxColumn Precio; + private System.Windows.Forms.DataGridViewTextBoxColumn Cantidad; + private System.Windows.Forms.DataGridViewTextBoxColumn Total; + private System.Windows.Forms.Button btnBuscar; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.DataGridView dgvMes; + private System.Windows.Forms.DataGridViewTextBoxColumn dataGridViewTextBoxColumn1; + private System.Windows.Forms.DataGridViewTextBoxColumn dataGridViewTextBoxColumn2; + private System.Windows.Forms.DataGridViewTextBoxColumn dataGridViewTextBoxColumn3; + private System.Windows.Forms.DataGridViewTextBoxColumn dataGridViewTextBoxColumn4; + private System.Windows.Forms.Label lbProductDia; + private System.Windows.Forms.Label lbVendedorDia; + private System.Windows.Forms.Label lbTotalDia; + private System.Windows.Forms.Label lbTotalMes; + private System.Windows.Forms.Label lbVendedorMes; + private System.Windows.Forms.Label lbProductoMes; } } \ No newline at end of file diff --git a/Estadiscticas.cs b/Estadiscticas.cs index 40898b5..86f69e2 100644 --- a/Estadiscticas.cs +++ b/Estadiscticas.cs @@ -1,8 +1,11 @@ -using System; +using compabetov2.database; +using compabetov2.database.modelos; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; +using System.Globalization; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -12,9 +15,167 @@ namespace compabetov2 { public partial class Estadiscticas : Form { + Dictionary>> resumen; public Estadiscticas() { InitializeComponent(); + darFormatoDTP(); } + + private void darFormatoDTP() + { + dtpBuscar.Format = DateTimePickerFormat.Custom; + dtpBuscar.CustomFormat = "dd/MM/yyyy"; + } + + private void btnBuscar_Click(object sender, EventArgs e) + { + string fechaBuscaStr = dtpBuscar.Text; + + DateTime.TryParseExact(fechaBuscaStr, "dd/MM/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime fechaBuscar); + resumen = service.estadisticas(fechaBuscar); + List productosMes = estadisticasMes(); + Dictionary estadisticas = new Dictionary + { + { "mes", new Dictionary{ + { "productos", productosMes }, + { "productoMasVendido", prodctoMasVendidoMes(productosMes) }, + { "mejorVendedor", mejorVenderdorMes() }, + } } + }; + mostrarDatos(estadisticas); + } + + private void mostrarDatos(Dictionary estadisticas) + { + + List detallesMes = estadisticas["mes"]["productos"]; + decimal totalVendidoMes = 0; + foreach (DetalleVentaModel producto in detallesMes) + { + totalVendidoMes += producto.cantidad * producto.producto.precion; + // Crear una nueva fila + DataGridViewRow nuevaFila = new DataGridViewRow(); + + // Crear celdas para la nueva fila + DataGridViewCell productoN = new DataGridViewTextBoxCell(); + DataGridViewCell precio = new DataGridViewTextBoxCell(); + DataGridViewCell cantidad = new DataGridViewTextBoxCell(); + DataGridViewCell total = new DataGridViewTextBoxCell(); + + // Establecer los valores de las celdas (puedes ajustar según tu necesidad) + productoN.Value = $"{producto.producto.nombre}"; + precio.Value = $"{producto.producto.precion}"; + cantidad.Value = $"{producto.cantidad}"; + total.Value = $"{producto.cantidad * producto.producto.precion}"; + + // Agregar las celdas a la fila + nuevaFila.Cells.Add(productoN); + nuevaFila.Cells.Add(precio); + nuevaFila.Cells.Add(cantidad); + nuevaFila.Cells.Add(total); + + // Agregar la nueva fila al DataGridView + dgvMes.Rows.Add(nuevaFila); + } + + lbTotalMes.Text = $"Total de mes: ${totalVendidoMes}"; + lbProductoMes.Text = $"Producto mas vendido: {estadisticas["mes"]["productoMasVendido"]}"; + lbVendedorMes.Text = $"Mejor vendedor: {estadisticas["mes"]["mejorVendedor"]}"; + } + + private List estadisticasMes() + { + List> mes = resumen["mes"]; + + List detallesMes = new List(); + foreach (Dictionary venta_y_detalles in mes) + { + foreach (DetalleVentaModel detallesVenta in venta_y_detalles["detalles"]) + { + int totalElementos = detallesMes.Count; + int contador = 0; + for(int i = 0; i <= totalElementos; i++) { + contador++; + if (i == totalElementos) + { + detallesMes.Add(detallesVenta); + break; + } + + DetalleVentaModel producto = detallesMes[i]; + + if (producto.producto.nombre.Equals(detallesVenta.producto.nombre)) + { + producto.cantidad += detallesVenta.cantidad; + break; + } + + //si no existe el producto lo agrega + + } + + if(contador == 0) + { + detallesMes.Add(detallesVenta); + } + + } + } + return detallesMes; + } + + private string mejorVenderdorMes() + { + List> mes = resumen["mes"]; + string mejorVendedor = ""; + int contadorNumeroVentas = 0; + + Dictionary empleados = new Dictionary(); + foreach(Dictionary venta_y_detalle in mes) + { + VentaModel venta = venta_y_detalle["venta"]; + + if (empleados.ContainsKey(venta.responzable)) + { + empleados[venta.responzable] += 1; + } + else + { + empleados.Add(venta.responzable, 1); + } + } + + foreach(string empleado in empleados.Keys) + { + if (empleados[empleado] > contadorNumeroVentas) + { + contadorNumeroVentas = empleados[empleado]; + mejorVendedor = empleado; + } + } + + return mejorVendedor; + } + + private string prodctoMasVendidoMes(List productosMes) + { + string productoMasVendido = ""; + int cantidadProducto = 0; + Dictionary productosNombres = new Dictionary(); + + foreach(DetalleVentaModel producto in productosMes) + { + if(producto.cantidad > cantidadProducto) + { + productoMasVendido = producto.producto.nombre; + cantidadProducto = producto.cantidad; + + } + } + return productoMasVendido; + } + + } } diff --git a/Estadiscticas.resx b/Estadiscticas.resx index 1af7de1..3d753bc 100644 --- a/Estadiscticas.resx +++ b/Estadiscticas.resx @@ -117,4 +117,28 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + \ No newline at end of file diff --git a/Principal/MenuPrincipal.Designer.cs b/Principal/MenuPrincipal.Designer.cs index 44645df..215a542 100644 --- a/Principal/MenuPrincipal.Designer.cs +++ b/Principal/MenuPrincipal.Designer.cs @@ -72,9 +72,9 @@ this.panel1.Controls.Add(this.pictureBox1); this.panel1.Dock = System.Windows.Forms.DockStyle.Fill; this.panel1.Location = new System.Drawing.Point(0, 0); - this.panel1.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.panel1.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.panel1.Name = "panel1"; - this.panel1.Size = new System.Drawing.Size(1924, 938); + this.panel1.Size = new System.Drawing.Size(1294, 627); this.panel1.TabIndex = 4; this.panel1.Paint += new System.Windows.Forms.PaintEventHandler(this.panel1_Paint); // @@ -83,9 +83,10 @@ this.lblfecha.AutoSize = true; this.lblfecha.Font = new System.Drawing.Font("Microsoft Sans Serif", 30F); this.lblfecha.ForeColor = System.Drawing.Color.Navy; - this.lblfecha.Location = new System.Drawing.Point(776, 112); + this.lblfecha.Location = new System.Drawing.Point(582, 91); + this.lblfecha.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); this.lblfecha.Name = "lblfecha"; - this.lblfecha.Size = new System.Drawing.Size(159, 58); + this.lblfecha.Size = new System.Drawing.Size(126, 46); this.lblfecha.TabIndex = 9; this.lblfecha.Text = "label2"; this.lblfecha.TextAlign = System.Drawing.ContentAlignment.TopCenter; @@ -96,9 +97,10 @@ this.lblhora.AutoSize = true; this.lblhora.Font = new System.Drawing.Font("Microsoft Sans Serif", 60F); this.lblhora.ForeColor = System.Drawing.Color.MediumBlue; - this.lblhora.Location = new System.Drawing.Point(953, -6); + this.lblhora.Location = new System.Drawing.Point(715, -5); + this.lblhora.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); this.lblhora.Name = "lblhora"; - this.lblhora.Size = new System.Drawing.Size(318, 113); + this.lblhora.Size = new System.Drawing.Size(249, 91); this.lblhora.TabIndex = 8; this.lblhora.Text = "label1"; this.lblhora.Click += new System.EventHandler(this.lblhora_Click); @@ -112,26 +114,26 @@ this.flowLayoutPanel1.Controls.Add(this.button3); this.flowLayoutPanel1.Controls.Add(this.button5); this.flowLayoutPanel1.Location = new System.Drawing.Point(-1, 2); - this.flowLayoutPanel1.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.flowLayoutPanel1.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.flowLayoutPanel1.Name = "flowLayoutPanel1"; - this.flowLayoutPanel1.Size = new System.Drawing.Size(324, 1061); + this.flowLayoutPanel1.Size = new System.Drawing.Size(243, 862); this.flowLayoutPanel1.TabIndex = 7; // // panel2 // this.panel2.BackColor = System.Drawing.Color.Transparent; this.panel2.Controls.Add(this.pictureBox7); - this.panel2.Location = new System.Drawing.Point(3, 2); - this.panel2.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.panel2.Location = new System.Drawing.Point(2, 2); + this.panel2.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.panel2.Name = "panel2"; - this.panel2.Size = new System.Drawing.Size(312, 263); + this.panel2.Size = new System.Drawing.Size(234, 214); this.panel2.TabIndex = 8; // // pictureBox7 // this.pictureBox7.Image = global::compabetov2.Properties.Resources.HomeroMenu; - this.pictureBox7.Location = new System.Drawing.Point(64, 34); - this.pictureBox7.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.pictureBox7.Location = new System.Drawing.Point(48, 28); + this.pictureBox7.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.pictureBox7.Name = "pictureBox7"; this.pictureBox7.Size = new System.Drawing.Size(190, 197); this.pictureBox7.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; @@ -147,11 +149,11 @@ this.button1.ForeColor = System.Drawing.SystemColors.ButtonHighlight; this.button1.Image = global::compabetov2.Properties.Resources.Menui1; this.button1.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft; - this.button1.Location = new System.Drawing.Point(3, 269); - this.button1.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.button1.Location = new System.Drawing.Point(2, 220); + this.button1.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.button1.Name = "button1"; - this.button1.Padding = new System.Windows.Forms.Padding(51, 0, 0, 0); - this.button1.Size = new System.Drawing.Size(312, 114); + this.button1.Padding = new System.Windows.Forms.Padding(38, 0, 0, 0); + this.button1.Size = new System.Drawing.Size(234, 93); this.button1.TabIndex = 8; this.button1.Text = "Menú"; this.button1.UseVisualStyleBackColor = false; @@ -166,11 +168,11 @@ this.button2.ForeColor = System.Drawing.SystemColors.ButtonHighlight; this.button2.Image = global::compabetov2.Properties.Resources.estadisticasi; this.button2.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft; - this.button2.Location = new System.Drawing.Point(3, 387); - this.button2.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.button2.Location = new System.Drawing.Point(2, 317); + this.button2.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.button2.Name = "button2"; - this.button2.Padding = new System.Windows.Forms.Padding(51, 0, 0, 0); - this.button2.Size = new System.Drawing.Size(312, 114); + this.button2.Padding = new System.Windows.Forms.Padding(38, 0, 0, 0); + this.button2.Size = new System.Drawing.Size(234, 93); this.button2.TabIndex = 9; this.button2.Text = "Estadisticas"; this.button2.UseVisualStyleBackColor = false; @@ -185,11 +187,11 @@ this.button3.ForeColor = System.Drawing.SystemColors.ButtonHighlight; this.button3.Image = global::compabetov2.Properties.Resources.productoi; this.button3.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft; - this.button3.Location = new System.Drawing.Point(3, 505); - this.button3.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.button3.Location = new System.Drawing.Point(2, 414); + this.button3.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.button3.Name = "button3"; - this.button3.Padding = new System.Windows.Forms.Padding(51, 0, 0, 0); - this.button3.Size = new System.Drawing.Size(312, 114); + this.button3.Padding = new System.Windows.Forms.Padding(38, 0, 0, 0); + this.button3.Size = new System.Drawing.Size(234, 93); this.button3.TabIndex = 10; this.button3.Text = "Productos"; this.button3.UseVisualStyleBackColor = false; @@ -203,11 +205,11 @@ this.button5.ForeColor = System.Drawing.SystemColors.ButtonHighlight; this.button5.Image = global::compabetov2.Properties.Resources.sesionc; this.button5.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft; - this.button5.Location = new System.Drawing.Point(3, 623); - this.button5.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.button5.Location = new System.Drawing.Point(2, 511); + this.button5.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.button5.Name = "button5"; - this.button5.Padding = new System.Windows.Forms.Padding(51, 0, 0, 0); - this.button5.Size = new System.Drawing.Size(312, 114); + this.button5.Padding = new System.Windows.Forms.Padding(38, 0, 0, 0); + this.button5.Size = new System.Drawing.Size(234, 93); this.button5.TabIndex = 12; this.button5.Text = "Salir"; this.button5.UseVisualStyleBackColor = false; @@ -216,10 +218,10 @@ // pictureBox4 // this.pictureBox4.Image = global::compabetov2.Properties.Resources.inventario; - this.pictureBox4.Location = new System.Drawing.Point(1451, 603); - this.pictureBox4.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.pictureBox4.Location = new System.Drawing.Point(1088, 490); + this.pictureBox4.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.pictureBox4.Name = "pictureBox4"; - this.pictureBox4.Size = new System.Drawing.Size(293, 282); + this.pictureBox4.Size = new System.Drawing.Size(220, 229); this.pictureBox4.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage; this.pictureBox4.TabIndex = 6; this.pictureBox4.TabStop = false; @@ -228,10 +230,10 @@ // pictureBox5 // this.pictureBox5.Image = global::compabetov2.Properties.Resources.Cuentas; - this.pictureBox5.Location = new System.Drawing.Point(584, 603); - this.pictureBox5.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.pictureBox5.Location = new System.Drawing.Point(438, 490); + this.pictureBox5.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.pictureBox5.Name = "pictureBox5"; - this.pictureBox5.Size = new System.Drawing.Size(293, 282); + this.pictureBox5.Size = new System.Drawing.Size(220, 229); this.pictureBox5.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage; this.pictureBox5.TabIndex = 5; this.pictureBox5.TabStop = false; @@ -240,10 +242,10 @@ // pictureBox6 // this.pictureBox6.Image = global::compabetov2.Properties.Resources.mermas; - this.pictureBox6.Location = new System.Drawing.Point(1013, 603); - this.pictureBox6.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.pictureBox6.Location = new System.Drawing.Point(760, 490); + this.pictureBox6.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.pictureBox6.Name = "pictureBox6"; - this.pictureBox6.Size = new System.Drawing.Size(293, 282); + this.pictureBox6.Size = new System.Drawing.Size(220, 229); this.pictureBox6.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage; this.pictureBox6.TabIndex = 4; this.pictureBox6.TabStop = false; @@ -252,10 +254,10 @@ // pictureBox3 // this.pictureBox3.Image = global::compabetov2.Properties.Resources.Envios; - this.pictureBox3.Location = new System.Drawing.Point(1451, 209); - this.pictureBox3.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.pictureBox3.Location = new System.Drawing.Point(1088, 170); + this.pictureBox3.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.pictureBox3.Name = "pictureBox3"; - this.pictureBox3.Size = new System.Drawing.Size(293, 282); + this.pictureBox3.Size = new System.Drawing.Size(220, 229); this.pictureBox3.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage; this.pictureBox3.TabIndex = 3; this.pictureBox3.TabStop = false; @@ -264,10 +266,10 @@ // pictureBox2 // this.pictureBox2.Image = global::compabetov2.Properties.Resources.Vender; - this.pictureBox2.Location = new System.Drawing.Point(584, 209); - this.pictureBox2.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.pictureBox2.Location = new System.Drawing.Point(438, 170); + this.pictureBox2.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.pictureBox2.Name = "pictureBox2"; - this.pictureBox2.Size = new System.Drawing.Size(293, 282); + this.pictureBox2.Size = new System.Drawing.Size(220, 229); this.pictureBox2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage; this.pictureBox2.TabIndex = 2; this.pictureBox2.TabStop = false; @@ -276,10 +278,10 @@ // pictureBox1 // this.pictureBox1.Image = global::compabetov2.Properties.Resources.Personal; - this.pictureBox1.Location = new System.Drawing.Point(1013, 209); - this.pictureBox1.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.pictureBox1.Location = new System.Drawing.Point(760, 170); + this.pictureBox1.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.pictureBox1.Name = "pictureBox1"; - this.pictureBox1.Size = new System.Drawing.Size(293, 282); + this.pictureBox1.Size = new System.Drawing.Size(220, 229); this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage; this.pictureBox1.TabIndex = 1; this.pictureBox1.TabStop = false; @@ -292,13 +294,12 @@ // // MenuPrincipal // - this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(1924, 938); + this.ClientSize = new System.Drawing.Size(1294, 627); this.ControlBox = false; this.Controls.Add(this.panel1); this.IsMdiContainer = true; - this.Margin = new System.Windows.Forms.Padding(4); this.Name = "MenuPrincipal"; this.WindowState = System.Windows.Forms.FormWindowState.Maximized; this.Load += new System.EventHandler(this.MenuPrincipal_Load); diff --git a/Principal/MenuPrincipal.cs b/Principal/MenuPrincipal.cs index 6742d12..0d55162 100644 --- a/Principal/MenuPrincipal.cs +++ b/Principal/MenuPrincipal.cs @@ -171,7 +171,8 @@ namespace compabetov2 private void button2_Click(object sender, EventArgs e) { - + Estadiscticas estadiscticas = new Estadiscticas(); + estadiscticas.Show(); } diff --git a/Ventas/vender.cs b/Ventas/vender.cs index c37bc00..a0fc6a4 100644 --- a/Ventas/vender.cs +++ b/Ventas/vender.cs @@ -38,7 +38,7 @@ namespace compabetov2 llenarLayout(); llenarComBox(); this.loginPrincipal = loginPrincipal; - } + } private void llenarComBox() { @@ -422,7 +422,9 @@ namespace compabetov2 List detalleVentas = listaProductosVenta(); if (detalleVentas.Count > 0) { - VentaModel ventaModel = new VentaModel(total); + VentaModel ventaModel = new VentaModel(total,-1,"", + responsablecb.Text.Equals("") ? loginPrincipal.usuario : responsablecb.Text + ); if (service.crearVentaDAO(ventaModel, detalleVentas)) { diff --git a/bin/Debug/compabetov2.exe b/bin/Debug/compabetov2.exe index 9ee3eeb..a24b32f 100644 Binary files a/bin/Debug/compabetov2.exe and b/bin/Debug/compabetov2.exe differ diff --git a/bin/Debug/compabetov2.pdb b/bin/Debug/compabetov2.pdb index 7dd5cdb..81f3c25 100644 Binary files a/bin/Debug/compabetov2.pdb and b/bin/Debug/compabetov2.pdb differ diff --git a/bin/Debug/data.db b/bin/Debug/data.db index d662dbe..35c296f 100644 Binary files a/bin/Debug/data.db and b/bin/Debug/data.db differ diff --git a/compabetov2.csproj b/compabetov2.csproj index 52cefaa..1775b77 100644 --- a/compabetov2.csproj +++ b/compabetov2.csproj @@ -126,6 +126,12 @@ EditarEmpleado1.cs + + Form + + + Estadiscticas.cs + Form @@ -248,6 +254,9 @@ EditarEmpleado1.cs + + Estadiscticas.cs + ActualizarMerma.cs diff --git a/database/DAO.cs b/database/DAO.cs index c3a4782..df8c748 100644 --- a/database/DAO.cs +++ b/database/DAO.cs @@ -777,7 +777,7 @@ namespace compabetov2.database { try { - string sqlVenta = "INSERT INTO venta (fecha, total) VALUES(@fecha, @total);"; + string sqlVenta = "INSERT INTO venta (fecha, total,responzable) VALUES(@fecha, @total,@responzable);"; string sqlDetalle = "INSERT INTO detalle_venta (fk_venta, fk_producto, cantidad) VALUES(@idVenta, @idProducto, @cantidada);"; string sqlIdVenta = "SELECT idVenta FROM venta ORDER BY idVenta DESC LIMIT 1"; string sqlProductoStock = "SELECT stock FROM Producto WHERE idproducto = @idproducto"; @@ -787,6 +787,7 @@ namespace compabetov2.database SQLiteCommand commandVenta = new SQLiteCommand(sqlVenta, conexion); commandVenta.Parameters.AddWithValue("@fecha", DateTime.Now.ToString()); commandVenta.Parameters.AddWithValue("@total", venta.total); + commandVenta.Parameters.AddWithValue("@responzable", venta.responzable); commandVenta.ExecuteNonQuery(); SQLiteCommand commandConsulta = new SQLiteCommand(sqlIdVenta, conexion); @@ -1137,7 +1138,7 @@ namespace compabetov2.database } - public static SQLiteDataReader filtrarVentaFechaMesDAO(DateTime fecha) + public static SQLiteDataReader conseguirVentasMesDAO(DateTime fecha) { SQLiteDataReader reader = null; var db_conexion = new Conexion(); @@ -1147,9 +1148,9 @@ namespace compabetov2.database conexion.Open(); - string sql = "SELECT * FROM venta WHERE fecha LIKE '%@fecha%'"; + string sql = "SELECT * FROM venta WHERE fecha LIKE @fecha"; SQLiteCommand command = new SQLiteCommand(sql, conexion); - command.Parameters.AddWithValue("@fecha", $"{fecha.Month}/{fecha.Year}"); + command.Parameters.AddWithValue("@fecha", $"%{fecha.Month}/{fecha.Year}%"); reader = command.ExecuteReader(); return reader; @@ -1162,7 +1163,32 @@ namespace compabetov2.database } } - public static Dictionary filtrarVentaFechaMes(DateTime fecha) + public static SQLiteDataReader conseguirDetalleVenta(VentaModel venta) + { + SQLiteDataReader reader = null; + var db_conexion = new Conexion(); + try + { + SQLiteConnection conexion = db_conexion.get_connection(); + + conexion.Open(); + + string sql = "select * from detalle_venta dv, Producto p WHERE dv.fk_producto = p.idproducto and dv.fk_venta = @idVenta"; + SQLiteCommand command = new SQLiteCommand(sql, conexion); + command.Parameters.AddWithValue("@idVenta", venta.id); + reader = command.ExecuteReader(); + + return reader; + + } + catch (SQLiteException ex) + { + MessageBox.Show(ex.Message); + return reader; + } + } + + /*public static SQLiteDataReader filtrarVentaFechaMes(DateTime fecha) { Dictionary estadisticas = new Dictionary(); SQLiteDataReader reader = DAO.filtrarVentaFechaMesDAO(fecha); @@ -1191,7 +1217,7 @@ namespace compabetov2.database estadisticas.Add("ventasMes", totalMes); return estadisticas; - } + }*/ public static bool crearEnvio(Envio envio, List detallesEnvio) { diff --git a/database/modelos/DetalleVentaModel.cs b/database/modelos/DetalleVentaModel.cs index e102b67..ef7554c 100644 --- a/database/modelos/DetalleVentaModel.cs +++ b/database/modelos/DetalleVentaModel.cs @@ -8,7 +8,7 @@ namespace compabetov2.database.modelos { public class DetalleVentaModel { - public int id; + public int idVenta; public int cantidad; public Producto producto; @@ -16,7 +16,7 @@ namespace compabetov2.database.modelos { this.cantidad = cantidad; this.producto = producto; - this.id = id; + this.idVenta = id; } } } diff --git a/database/modelos/VentaModel.cs b/database/modelos/VentaModel.cs index b110e17..9a5889d 100644 --- a/database/modelos/VentaModel.cs +++ b/database/modelos/VentaModel.cs @@ -11,11 +11,13 @@ namespace compabetov2.database.modelos public int id; public string fecha; public decimal total; + public string responzable; - public VentaModel(decimal total = 0, int id = -1, string fecha = "") { + public VentaModel(decimal total = 0, int id = -1, string fecha = "", string responzable = "") { this.id = id; this.fecha = fecha; this.total = total; + this.responzable = responzable; } } } diff --git a/database/service.cs b/database/service.cs index f0f3d29..5da2b38 100644 --- a/database/service.cs +++ b/database/service.cs @@ -283,7 +283,7 @@ namespace compabetov2.database return DAO.saldarCuentaDAO(cuenta, detallesCuentas); } - public static Dictionary filtrarVentaFechaMes(DateTime fecha) + /*public static Dictionary filtrarVentaFechaMes(DateTime fecha) { Dictionary estadisticas = new Dictionary(); SQLiteDataReader reader = DAO.filtrarVentaFechaMesDAO(fecha); @@ -312,7 +312,7 @@ namespace compabetov2.database MessageBox.Show($"{totalDia} -- {totalMes}"); return estadisticas; - } + }*/ public static bool crearEnvio(Envio envio, List detallesEnvio) { @@ -378,5 +378,66 @@ namespace compabetov2.database { return DAO.concluirEnvioDAO(envio, detallesEnvio); } + + public static Dictionary>> estadisticas(DateTime fecha) + { + Dictionary>> resumen = new Dictionary>>(); + List> listMes = new List>(); + List> listDia = new List>(); + SQLiteDataReader readerVentas = DAO.conseguirVentasMesDAO(fecha); + string formato = "dd/MM/yyyy"; + + while (readerVentas.Read()) + { + Dictionary dicVenta = new Dictionary(); + + VentaModel venta = new VentaModel( + readerVentas.GetDecimal(2), + (int)readerVentas.GetInt64(0), + readerVentas.GetString(1), + readerVentas.GetString(3) + ); + + List detallesVenta = new List(); + SQLiteDataReader readerDetalleVenta = DAO.conseguirDetalleVenta(venta); + while (readerDetalleVenta.Read()) + { + DetalleVentaModel detalleVenta = new DetalleVentaModel( + (int)readerDetalleVenta.GetInt64(2), + new Producto( + (int)readerDetalleVenta.GetInt64(1), + readerDetalleVenta["nombre"].ToString(), + readerDetalleVenta["descripcion"].ToString(), + readerDetalleVenta.GetDecimal(6), + readerDetalleVenta["img"].ToString(), + (int)readerDetalleVenta.GetInt64(8) + ), + (int)readerDetalleVenta.GetInt64(0) + ) ; + detallesVenta.Add( detalleVenta ); + } + + dicVenta.Add("venta", venta); + dicVenta.Add("detalles", detallesVenta as List); + + string[] fecha_hora = venta.fecha.Split(' '); + string fechaVentaStr = fecha_hora[0]; + + DateTime.TryParseExact(fechaVentaStr, formato, CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime fechaVenta); + if (fecha.Day == fechaVenta.Day) + { + listDia.Add(dicVenta); + } + + listMes.Add(dicVenta); + } + + + + resumen.Add("mes", listMes); + resumen.Add("dia", listDia); + + return resumen; + } } } diff --git a/obj/Debug/DesignTimeResolveAssemblyReferences.cache b/obj/Debug/DesignTimeResolveAssemblyReferences.cache index 10a1a65..4382aa9 100644 Binary files a/obj/Debug/DesignTimeResolveAssemblyReferences.cache and b/obj/Debug/DesignTimeResolveAssemblyReferences.cache differ diff --git a/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache b/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache index 5f3125c..d031cc8 100644 Binary files a/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache and b/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache differ diff --git a/obj/Debug/compabetov2.csproj.AssemblyReference.cache b/obj/Debug/compabetov2.csproj.AssemblyReference.cache index a98f1ed..eff9318 100644 Binary files a/obj/Debug/compabetov2.csproj.AssemblyReference.cache and b/obj/Debug/compabetov2.csproj.AssemblyReference.cache differ diff --git a/obj/Debug/compabetov2.csproj.CoreCompileInputs.cache b/obj/Debug/compabetov2.csproj.CoreCompileInputs.cache index c2ae66d..d707aad 100644 --- a/obj/Debug/compabetov2.csproj.CoreCompileInputs.cache +++ b/obj/Debug/compabetov2.csproj.CoreCompileInputs.cache @@ -1 +1 @@ -8c55401a55ae9b86950368a6d6d466458a0cd51b6070f789aecfd894857df381 +8e6b3a0fad2ff0f974b5aeba910c4d36ca0face95e575d08e0cf8d0719fce555 diff --git a/obj/Debug/compabetov2.csproj.FileListAbsolute.txt b/obj/Debug/compabetov2.csproj.FileListAbsolute.txt index 6a6abc5..59a21d5 100644 --- a/obj/Debug/compabetov2.csproj.FileListAbsolute.txt +++ b/obj/Debug/compabetov2.csproj.FileListAbsolute.txt @@ -125,3 +125,4 @@ C:\Users\Googl\Documents\compabetoOG\obj\Debug\compabetov2.AgregarLogin1.resourc C:\Users\carsu\Source\Repos\compabetoOG\obj\Debug\compabetov2.Empleados.AgregarEmpleado1.resources C:\Users\carsu\Source\Repos\compabetoOG\obj\Debug\compabetov2.AgregarLogin1.resources C:\Users\carsu\Source\Repos\compabetoOG\obj\Debug\compabetov2.Empleados.EditarEmpleado1.resources +C:\Users\carsu\source\repos\compabetoOG\obj\Debug\compabetov2.Estadiscticas.resources diff --git a/obj/Debug/compabetov2.csproj.GenerateResource.cache b/obj/Debug/compabetov2.csproj.GenerateResource.cache index afff78d..63d063b 100644 Binary files a/obj/Debug/compabetov2.csproj.GenerateResource.cache and b/obj/Debug/compabetov2.csproj.GenerateResource.cache differ diff --git a/obj/Debug/compabetov2.exe b/obj/Debug/compabetov2.exe index 9ee3eeb..a24b32f 100644 Binary files a/obj/Debug/compabetov2.exe and b/obj/Debug/compabetov2.exe differ diff --git a/obj/Debug/compabetov2.pdb b/obj/Debug/compabetov2.pdb index 7dd5cdb..81f3c25 100644 Binary files a/obj/Debug/compabetov2.pdb and b/obj/Debug/compabetov2.pdb differ