Files
MIP/Mip/frmTlacitStatistiku.cs
Culak-HP\Culak cc7c23eca4 Initial commit
2020-10-10 18:25:36 +02:00

195 lines
19 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Excel = Microsoft.Office.Interop.Excel;
namespace Mip
{
public partial class frmTlacitStatistiku : Form
{
public frmTlacitStatistiku()
{
InitializeComponent();
}
private void button3_Click(object sender, EventArgs e)
{
this.Close();
}
private void frmTlacitStatistiku_Shown(object sender, EventArgs e)
{
string cmd;
cmd = "select distinct year(`tabdopyt`.DatumPrijatiaOBJ) as `Rok` from `tabdopyt`";
DataTable tblRoky;
classSQL.SQL(cmd, out tblRoky);
comboBox1.DataSource = tblRoky;
comboBox1.ValueMember = "Rok";
comboBox1.DisplayMember = "Rok";
}
private void button1_Click(object sender, EventArgs e)
{
string cmd;
cmd = @"select
(select count(`pohlad-statistika-terminy`.IDCPOBJ) from `pohlad-statistika-terminy` where year(`pohlad-statistika-terminy`.DatumPotvrdeny) = " + (Convert.ToInt32(comboBox1.SelectedValue)-1).ToString() + @" and (`pohlad-statistika-terminy`.StatusDopytu != 'Zrušená' or `pohlad-statistika-terminy`.StatusDopytu != 'Zrušený' or `pohlad-statistika-terminy`.StatusDopytu != 'Pozastavená' or `pohlad-statistika-terminy`.StatusDopytu != 'Pozastavený') ) AS `Celkom`,
(select count(`pohlad-statistika-terminy`.IDCPOBJ) from `pohlad-statistika-terminy` where year(`pohlad-statistika-terminy`.DatumPotvrdeny) = " + (Convert.ToInt32(comboBox1.SelectedValue)-1).ToString() + @" and (`pohlad-statistika-terminy`.StatusDopytu != 'Zrušená' or `pohlad-statistika-terminy`.StatusDopytu != 'Zrušený' or `pohlad-statistika-terminy`.StatusDopytu != 'Pozastavená' or `pohlad-statistika-terminy`.StatusDopytu != 'Pozastavený') and `pohlad-statistika-terminy`.`MeskanieExpedicie[dni]` > 0 and `pohlad-statistika-terminy`.`MeskanieExpedicie[dni]` <= 7 ) AS `MeskajuceDo7`,
(select count(`pohlad-statistika-terminy`.IDCPOBJ) from `pohlad-statistika-terminy` where year(`pohlad-statistika-terminy`.DatumPotvrdeny) = " + (Convert.ToInt32(comboBox1.SelectedValue)-1).ToString() + @" and (`pohlad-statistika-terminy`.StatusDopytu != 'Zrušená' or `pohlad-statistika-terminy`.StatusDopytu != 'Zrušený' or `pohlad-statistika-terminy`.StatusDopytu != 'Pozastavená' or `pohlad-statistika-terminy`.StatusDopytu != 'Pozastavený') and `pohlad-statistika-terminy`.`MeskanieExpedicie[dni]` > 7 ) AS `MeskajuceNad7`,
(select count(`pohlad-statistika-terminy`.IDCPOBJ) from `pohlad-statistika-terminy` where year(`pohlad-statistika-terminy`.DatumPotvrdeny) = " + (Convert.ToInt32(comboBox1.SelectedValue)-1).ToString() + @" and (`pohlad-statistika-terminy`.StatusDopytu != 'Zrušená' or `pohlad-statistika-terminy`.StatusDopytu != 'Zrušený' or `pohlad-statistika-terminy`.StatusDopytu != 'Pozastavená' or `pohlad-statistika-terminy`.StatusDopytu != 'Pozastavený') and `pohlad-statistika-terminy`.`MeskanieExpedicie[dni]` <= 0 ) AS `ExpedovaneNacas`";
DataTable tblMinulyRok;
classSQL.SQL(cmd, out tblMinulyRok);
cmd = @"select distinct month(`pohlad-statistika-terminy`.DatumPotvrdeny) AS `Mesiac`,
(SELECT count(`pohlad-statistika-terminy`.IDCPOBJ) from `pohlad-statistika-terminy` where year(`pohlad-statistika-terminy`.DatumPotvrdeny) = " + Convert.ToInt32(comboBox1.SelectedValue).ToString() + @" and month(`pohlad-statistika-terminy`.DatumPotvrdeny) = `Mesiac` and (`pohlad-statistika-terminy`.StatusDopytu != 'Zrušená' or `pohlad-statistika-terminy`.StatusDopytu != 'Zrušený' or `pohlad-statistika-terminy`.StatusDopytu != 'Pozastavená' or `pohlad-statistika-terminy`.StatusDopytu != 'Pozastavený')) AS `Celkovy pocet`,
(select count(`pohlad-statistika-terminy`.IDCPOBJ) from `pohlad-statistika-terminy` where year(`pohlad-statistika-terminy`.DatumPotvrdeny) = " + Convert.ToInt32(comboBox1.SelectedValue).ToString() + @" and month(`pohlad-statistika-terminy`.DatumPotvrdeny) = `Mesiac` and (`pohlad-statistika-terminy`.StatusDopytu != 'Zrušená' or `pohlad-statistika-terminy`.StatusDopytu != 'Zrušený' or `pohlad-statistika-terminy`.StatusDopytu != 'Pozastavená' or `pohlad-statistika-terminy`.StatusDopytu != 'Pozastavený') and `pohlad-statistika-terminy`.`MeskanieExpedicie[dni]` > 0 and `pohlad-statistika-terminy`.`MeskanieExpedicie[dni]` <= 7 ) AS `MeskajuceDo7`,
(select count(`pohlad-statistika-terminy`.IDCPOBJ) from `pohlad-statistika-terminy` where year(`pohlad-statistika-terminy`.DatumPotvrdeny) = " + Convert.ToInt32(comboBox1.SelectedValue).ToString() + @" and month(`pohlad-statistika-terminy`.DatumPotvrdeny) = `Mesiac` and (`pohlad-statistika-terminy`.StatusDopytu != 'Zrušená' or `pohlad-statistika-terminy`.StatusDopytu != 'Zrušený' or `pohlad-statistika-terminy`.StatusDopytu != 'Pozastavená' or `pohlad-statistika-terminy`.StatusDopytu != 'Pozastavený') and `pohlad-statistika-terminy`.`MeskanieExpedicie[dni]` > 7 ) AS `MeskajuceNad7`,
(select count(`pohlad-statistika-terminy`.IDCPOBJ) from `pohlad-statistika-terminy` where year(`pohlad-statistika-terminy`.DatumPotvrdeny) = " + Convert.ToInt32(comboBox1.SelectedValue).ToString() + @" and month(`pohlad-statistika-terminy`.DatumPotvrdeny) = `Mesiac` and (`pohlad-statistika-terminy`.StatusDopytu != 'Zrušená' or `pohlad-statistika-terminy`.StatusDopytu != 'Zrušený' or `pohlad-statistika-terminy`.StatusDopytu != 'Pozastavená' or `pohlad-statistika-terminy`.StatusDopytu != 'Pozastavený') and `pohlad-statistika-terminy`.`MeskanieExpedicie[dni]` <= 0 ) AS `ExpedovaneNacas`,
(select count(`pohlad-statistika-terminy`.IDCPOBJ) from `pohlad-statistika-terminy` where year(`pohlad-statistika-terminy`.DatumPotvrdeny) = " + Convert.ToInt32(comboBox1.SelectedValue).ToString() + @" and month(`pohlad-statistika-terminy`.DatumPotvrdeny) = `Mesiac` and (`pohlad-statistika-terminy`.StatusDopytu = 'Zrušená' or `pohlad-statistika-terminy`.StatusDopytu = 'Zrušený')) AS `Zrusené`,
(select count(`pohlad-statistika-terminy`.IDCPOBJ) from `pohlad-statistika-terminy` where year(`pohlad-statistika-terminy`.DatumPotvrdeny) = " + Convert.ToInt32(comboBox1.SelectedValue).ToString() + @" and month(`pohlad-statistika-terminy`.DatumPotvrdeny) = `Mesiac` and (`pohlad-statistika-terminy`.StatusDopytu = 'Pozastavená' or `pohlad-statistika-terminy`.StatusDopytu = 'Pozastavený')) AS `Pozastavene`,
(select count(`pohlad-statistika-terminy`.IDCPOBJ) from `pohlad-statistika-terminy` where year(`pohlad-statistika-terminy`.DatumPotvrdeny) = " + Convert.ToInt32(comboBox1.SelectedValue).ToString() + @" and month(`pohlad-statistika-terminy`.DatumPotvrdeny) = `Mesiac` and (`pohlad-statistika-terminy`.StatusDopytu = 'Prijatá' or `pohlad-statistika-terminy`.StatusDopytu = 'Na lapovni' or `pohlad-statistika-terminy`.StatusDopytu = 'Vo výrobe' or `pohlad-statistika-terminy`.StatusDopytu = 'Zaradená do výroby')) AS `VoVyrobe`
from `pohlad-statistika-terminy`
order by `Mesiac`";
DataTable tblTentoRok;
classSQL.SQL(cmd, out tblTentoRok);
classGlobal.DeleteRamDisk(); classGlobal.CreateRamDisk();
classSQL.ExportFormToHDD("Štatistika expedície.xls", @"W:\se.xls");
Excel.Application xlApp;
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;
Excel.Range range;
xlApp = new Excel.Application();
xlWorkBook = xlApp.Workbooks.Open(@"W:\se.xls");
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
range = xlWorkSheet.UsedRange;
xlWorkSheet.Range["C3", "F6"].Value = comboBox1.Text;
xlWorkSheet.Range["C7", "F10"].Value = Convert.ToInt32(comboBox1.SelectedValue)-1;
xlWorkSheet.Range["K7", "L8"].Value = tblMinulyRok.Rows[0]["Celkom"].ToString();
xlWorkSheet.Range["Q7", "R8"].Value = tblMinulyRok.Rows[0]["MeskajuceDo7"].ToString();
xlWorkSheet.Range["W7", "X8"].Value = tblMinulyRok.Rows[0]["MeskajuceNad7"].ToString();
xlWorkSheet.Range["K9", "L10"].Value = tblMinulyRok.Rows[0]["ExpedovaneNacas"].ToString();
for (int i = 16; i < 28; i++)
{
xlWorkSheet.Range["E" + i.ToString(), "F" + i.ToString()].Value = tblTentoRok.Rows[i - 16]["Celkovy pocet"].ToString();
xlWorkSheet.Range["G" + i.ToString(), "H" + i.ToString()].Value = tblTentoRok.Rows[i - 16]["ExpedovaneNacas"].ToString();
xlWorkSheet.Range["I" + i.ToString(), "J" + i.ToString()].Value = tblTentoRok.Rows[i - 16]["MeskajuceDo7"].ToString();
xlWorkSheet.Range["K" + i.ToString(), "L" + i.ToString()].Value = tblTentoRok.Rows[i - 16]["MeskajuceNad7"].ToString();
xlWorkSheet.Range["S" + i.ToString(), "T" + i.ToString()].Value = tblTentoRok.Rows[i - 16]["Zrusené"].ToString();
xlWorkSheet.Range["U" + i.ToString(), "V" + i.ToString()].Value = tblTentoRok.Rows[i - 16]["Pozastavene"].ToString();
xlWorkSheet.Range["W" + i.ToString(), "X" + i.ToString()].Value = tblTentoRok.Rows[i - 16]["VoVyrobe"].ToString();
}
xlApp.Visible = true;
xlApp.ActiveWindow.Activate();
xlWorkSheet.PrintPreview();
xlApp.Visible = false;
xlWorkBook.Save();
xlWorkBook.Close(false, null, null);
xlApp.Quit();
classGlobal.DeleteRamDisk();
}
private void button2_Click(object sender, EventArgs e)
{
SaveFileDialog sfg = new SaveFileDialog();
sfg.Filter = "Excel files (*.xls)|*.xls|All files (*.*)|*.*";
sfg.FileName = "Štatistika expedície " + comboBox1.Text.ToString() + ".xls";
if (sfg.ShowDialog() == DialogResult.OK)
{
classSQL.ExportFormToHDD("Štatistika expedície.xls", sfg.FileName);
string cmd;
cmd = @"select
(select count(`pohlad-statistika-terminy`.IDCPOBJ) from `pohlad-statistika-terminy` where year(`pohlad-statistika-terminy`.DatumPotvrdeny) = " + (Convert.ToInt32(comboBox1.SelectedValue) - 1).ToString() + @" and (`pohlad-statistika-terminy`.StatusDopytu != 'Zrušená' or `pohlad-statistika-terminy`.StatusDopytu != 'Zrušený' or `pohlad-statistika-terminy`.StatusDopytu != 'Pozastavená' or `pohlad-statistika-terminy`.StatusDopytu != 'Pozastavený') ) AS `Celkom`,
(select count(`pohlad-statistika-terminy`.IDCPOBJ) from `pohlad-statistika-terminy` where year(`pohlad-statistika-terminy`.DatumPotvrdeny) = " + (Convert.ToInt32(comboBox1.SelectedValue) - 1).ToString() + @" and (`pohlad-statistika-terminy`.StatusDopytu != 'Zrušená' or `pohlad-statistika-terminy`.StatusDopytu != 'Zrušený' or `pohlad-statistika-terminy`.StatusDopytu != 'Pozastavená' or `pohlad-statistika-terminy`.StatusDopytu != 'Pozastavený') and `pohlad-statistika-terminy`.`MeskanieExpedicie[dni]` > 0 and `pohlad-statistika-terminy`.`MeskanieExpedicie[dni]` <= 7 ) AS `MeskajuceDo7`,
(select count(`pohlad-statistika-terminy`.IDCPOBJ) from `pohlad-statistika-terminy` where year(`pohlad-statistika-terminy`.DatumPotvrdeny) = " + (Convert.ToInt32(comboBox1.SelectedValue) - 1).ToString() + @" and (`pohlad-statistika-terminy`.StatusDopytu != 'Zrušená' or `pohlad-statistika-terminy`.StatusDopytu != 'Zrušený' or `pohlad-statistika-terminy`.StatusDopytu != 'Pozastavená' or `pohlad-statistika-terminy`.StatusDopytu != 'Pozastavený') and `pohlad-statistika-terminy`.`MeskanieExpedicie[dni]` > 7 ) AS `MeskajuceNad7`,
(select count(`pohlad-statistika-terminy`.IDCPOBJ) from `pohlad-statistika-terminy` where year(`pohlad-statistika-terminy`.DatumPotvrdeny) = " + (Convert.ToInt32(comboBox1.SelectedValue) - 1).ToString() + @" and (`pohlad-statistika-terminy`.StatusDopytu != 'Zrušená' or `pohlad-statistika-terminy`.StatusDopytu != 'Zrušený' or `pohlad-statistika-terminy`.StatusDopytu != 'Pozastavená' or `pohlad-statistika-terminy`.StatusDopytu != 'Pozastavený') and `pohlad-statistika-terminy`.`MeskanieExpedicie[dni]` <= 0 ) AS `ExpedovaneNacas`";
DataTable tblMinulyRok;
classSQL.SQL(cmd, out tblMinulyRok);
cmd = @"select distinct month(`pohlad-statistika-terminy`.DatumPotvrdeny) AS `Mesiac`,
(SELECT count(`pohlad-statistika-terminy`.IDCPOBJ) from `pohlad-statistika-terminy` where year(`pohlad-statistika-terminy`.DatumPotvrdeny) = " + Convert.ToInt32(comboBox1.SelectedValue).ToString() + @" and month(`pohlad-statistika-terminy`.DatumPotvrdeny) = `Mesiac` and (`pohlad-statistika-terminy`.StatusDopytu != 'Zrušená' or `pohlad-statistika-terminy`.StatusDopytu != 'Zrušený' or `pohlad-statistika-terminy`.StatusDopytu != 'Pozastavená' or `pohlad-statistika-terminy`.StatusDopytu != 'Pozastavený')) AS `Celkovy pocet`,
(select count(`pohlad-statistika-terminy`.IDCPOBJ) from `pohlad-statistika-terminy` where year(`pohlad-statistika-terminy`.DatumPotvrdeny) = " + Convert.ToInt32(comboBox1.SelectedValue).ToString() + @" and month(`pohlad-statistika-terminy`.DatumPotvrdeny) = `Mesiac` and (`pohlad-statistika-terminy`.StatusDopytu != 'Zrušená' or `pohlad-statistika-terminy`.StatusDopytu != 'Zrušený' or `pohlad-statistika-terminy`.StatusDopytu != 'Pozastavená' or `pohlad-statistika-terminy`.StatusDopytu != 'Pozastavený') and `pohlad-statistika-terminy`.`MeskanieExpedicie[dni]` > 0 and `pohlad-statistika-terminy`.`MeskanieExpedicie[dni]` <= 7 ) AS `MeskajuceDo7`,
(select count(`pohlad-statistika-terminy`.IDCPOBJ) from `pohlad-statistika-terminy` where year(`pohlad-statistika-terminy`.DatumPotvrdeny) = " + Convert.ToInt32(comboBox1.SelectedValue).ToString() + @" and month(`pohlad-statistika-terminy`.DatumPotvrdeny) = `Mesiac` and (`pohlad-statistika-terminy`.StatusDopytu != 'Zrušená' or `pohlad-statistika-terminy`.StatusDopytu != 'Zrušený' or `pohlad-statistika-terminy`.StatusDopytu != 'Pozastavená' or `pohlad-statistika-terminy`.StatusDopytu != 'Pozastavený') and `pohlad-statistika-terminy`.`MeskanieExpedicie[dni]` > 7 ) AS `MeskajuceNad7`,
(select count(`pohlad-statistika-terminy`.IDCPOBJ) from `pohlad-statistika-terminy` where year(`pohlad-statistika-terminy`.DatumPotvrdeny) = " + Convert.ToInt32(comboBox1.SelectedValue).ToString() + @" and month(`pohlad-statistika-terminy`.DatumPotvrdeny) = `Mesiac` and (`pohlad-statistika-terminy`.StatusDopytu != 'Zrušená' or `pohlad-statistika-terminy`.StatusDopytu != 'Zrušený' or `pohlad-statistika-terminy`.StatusDopytu != 'Pozastavená' or `pohlad-statistika-terminy`.StatusDopytu != 'Pozastavený') and `pohlad-statistika-terminy`.`MeskanieExpedicie[dni]` <= 0 ) AS `ExpedovaneNacas`,
(select count(`pohlad-statistika-terminy`.IDCPOBJ) from `pohlad-statistika-terminy` where year(`pohlad-statistika-terminy`.DatumPotvrdeny) = " + Convert.ToInt32(comboBox1.SelectedValue).ToString() + @" and month(`pohlad-statistika-terminy`.DatumPotvrdeny) = `Mesiac` and (`pohlad-statistika-terminy`.StatusDopytu = 'Zrušená' or `pohlad-statistika-terminy`.StatusDopytu = 'Zrušený')) AS `Zrusené`,
(select count(`pohlad-statistika-terminy`.IDCPOBJ) from `pohlad-statistika-terminy` where year(`pohlad-statistika-terminy`.DatumPotvrdeny) = " + Convert.ToInt32(comboBox1.SelectedValue).ToString() + @" and month(`pohlad-statistika-terminy`.DatumPotvrdeny) = `Mesiac` and (`pohlad-statistika-terminy`.StatusDopytu = 'Pozastavená' or `pohlad-statistika-terminy`.StatusDopytu = 'Pozastavený')) AS `Pozastavene`,
(select count(`pohlad-statistika-terminy`.IDCPOBJ) from `pohlad-statistika-terminy` where year(`pohlad-statistika-terminy`.DatumPotvrdeny) = " + Convert.ToInt32(comboBox1.SelectedValue).ToString() + @" and month(`pohlad-statistika-terminy`.DatumPotvrdeny) = `Mesiac` and (`pohlad-statistika-terminy`.StatusDopytu = 'Prijatá' or `pohlad-statistika-terminy`.StatusDopytu = 'Na lapovni' or `pohlad-statistika-terminy`.StatusDopytu = 'Vo výrobe' or `pohlad-statistika-terminy`.StatusDopytu = 'Zaradená do výroby')) AS `VoVyrobe`
from `pohlad-statistika-terminy`
order by `Mesiac`";
DataTable tblTentoRok;
classSQL.SQL(cmd, out tblTentoRok);
Excel.Application xlApp;
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;
Excel.Range range;
xlApp = new Excel.Application();
xlWorkBook = xlApp.Workbooks.Open(sfg.FileName);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
range = xlWorkSheet.UsedRange;
xlWorkSheet.Range["C3", "F6"].Value = comboBox1.Text;
xlWorkSheet.Range["C7", "F10"].Value = Convert.ToInt32(comboBox1.SelectedValue) - 1;
xlWorkSheet.Range["K7", "L8"].Value = tblMinulyRok.Rows[0]["Celkom"].ToString();
xlWorkSheet.Range["Q7", "R8"].Value = tblMinulyRok.Rows[0]["MeskajuceDo7"].ToString();
xlWorkSheet.Range["W7", "X8"].Value = tblMinulyRok.Rows[0]["MeskajuceNad7"].ToString();
xlWorkSheet.Range["K9", "L10"].Value = tblMinulyRok.Rows[0]["ExpedovaneNacas"].ToString();
for (int i = 16; i < 28; i++)
{
xlWorkSheet.Range["E" + i.ToString(), "F" + i.ToString()].Value = tblTentoRok.Rows[i - 16]["Celkovy pocet"].ToString();
xlWorkSheet.Range["G" + i.ToString(), "H" + i.ToString()].Value = tblTentoRok.Rows[i - 16]["ExpedovaneNacas"].ToString();
xlWorkSheet.Range["I" + i.ToString(), "J" + i.ToString()].Value = tblTentoRok.Rows[i - 16]["MeskajuceDo7"].ToString();
xlWorkSheet.Range["K" + i.ToString(), "L" + i.ToString()].Value = tblTentoRok.Rows[i - 16]["MeskajuceNad7"].ToString();
xlWorkSheet.Range["S" + i.ToString(), "T" + i.ToString()].Value = tblTentoRok.Rows[i - 16]["Zrusené"].ToString();
xlWorkSheet.Range["U" + i.ToString(), "V" + i.ToString()].Value = tblTentoRok.Rows[i - 16]["Pozastavene"].ToString();
xlWorkSheet.Range["W" + i.ToString(), "X" + i.ToString()].Value = tblTentoRok.Rows[i - 16]["VoVyrobe"].ToString();
}
xlApp.Visible = true;
xlApp.ActiveWindow.Activate();
//xlWorkSheet.PrintPreview();
xlApp.Visible = false;
xlWorkBook.Save();
xlWorkBook.Close(false, null, null);
xlApp.Quit();
MessageBox.Show("Súbor úspešne uložený!");
}
}
}
}