Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Microsoft.Win32;
- using System;
- using System.Data;
- using System.Data.SqlClient;
- using System.Drawing;
- using System.IO;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace eReport
- {
- public partial class eReport_Form : Form
- {
- private string connectionString;
- private int actualLastID;
- private int actualWorkerCount;
- private int globalReportID;
- private SqlConnection cnn;
- private SqlConnection conn;
- private bool sorting;
- private DateTimePicker StartPicker;
- private DateTimePicker StopPicker;
- private int workerNumber;
- private bool updateWorkers = true;
- public static readonly TimeSpan InfiniteTimeSpan = new TimeSpan(0, 0, 0, 0, Timeout.Infinite);
- public eReport_Form()
- {
- InitializeComponent();
- InitializeTimePickers();
- AppDomain.CurrentDomain.SetData("DataDirectory", AppDomain.CurrentDomain.BaseDirectory);
- connectionString = @"Data Source=.\SQLEXPRESS;Initial Catalog=eReport;Integrated Security=True;MultipleActiveResultSets=True";
- RegisterInStartup();
- TaskScheduler.Instance.ScheduleTask(06, 10, 24,
- () =>
- {
- this.Export_CSV();
- });
- TaskScheduler.Instance.ScheduleTask(14, 10, 24,
- () =>
- {
- this.Export_CSV();
- });
- TaskScheduler.Instance.ScheduleTask(22, 10, 24,
- () =>
- {
- this.Export_CSV();
- });
- fillMachineCombo();
- fillToolCombo();
- machineCombo.Select();
- sorting = false;
- MessageBoxManager.OK = "Rendben";
- MessageBoxManager.Yes = "Igen";
- MessageBoxManager.No = "Nem";
- MessageBoxManager.Register();
- }
- private void InitializeTimePickers()
- {
- StartPicker = new DateTimePicker();
- StartPicker.Format = DateTimePickerFormat.Time;
- StartPicker.ShowUpDown = true;
- StartPicker.Location = new Point(790, 39);
- StartPicker.Width = 100;
- groupBox1.Controls.Add(StartPicker);
- StopPicker = new DateTimePicker();
- StopPicker.Format = DateTimePickerFormat.Time;
- StopPicker.ShowUpDown = true;
- StopPicker.Location = new Point(896, 39);
- StopPicker.Width = 100;
- groupBox1.Controls.Add(StopPicker);
- }
- private void lastID()
- {
- cnn = new SqlConnection(connectionString);
- try
- {
- cnn.Open();
- }
- catch (Exception ex)
- {
- MessageBox.Show("Hiba az adatbázis megnyitása közben: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
- return;
- }
- SqlDataReader dr;
- try
- {
- SqlCommand cmd = new SqlCommand("SELECT TOP 1 ID FROM Report_tbl ORDER BY ID DESC", cnn);
- dr = cmd.ExecuteReader();
- while (dr.Read())
- {
- actualLastID = dr.GetInt32(0);
- }
- dr.Close();
- }
- catch (Exception ex)
- {
- MessageBox.Show("133Hiba a lekérdezés közben: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
- }
- }
- private void report_Click(object sender, EventArgs e)
- {
- if (checkMainData() && !dataExist() && descriptionBox.TextLength <= 15000 && solutionBox.TextLength <= 15000)
- {
- cnn = new SqlConnection(connectionString);
- string reportQuery = "INSERT INTO Report_tbl (Machine, Error_Short, Worker_Number, Report, Solution, Create_Record, Modify_Record, Start_Work, End_Work, Intervall)" +
- "VALUES (@machine, @error_short, @worker_number, @report, @solution, @create_record, @modify_record, @start_work, @end_work, @intervall)";
- string toolQuery = "INSERT INTO Tool_tbl (Tool, Report_ID) " +
- "VALUES (@tool, @report_id)";
- SqlCommand reportCommand = new SqlCommand(reportQuery, cnn);
- SqlCommand toolCommand = new SqlCommand(toolQuery, cnn);
- reportCommand.Parameters.AddWithValue("@machine", machineCombo.Text);
- reportCommand.Parameters.AddWithValue("@error_short", errorCombo.Text);
- reportCommand.Parameters.AddWithValue("@report", descriptionBox.Text);
- reportCommand.Parameters.AddWithValue("@solution", solutionBox.Text);
- reportCommand.Parameters.AddWithValue("@create_record", DateTime.Now);
- reportCommand.Parameters.AddWithValue("@modify_record", DateTime.Now);
- reportCommand.Parameters.AddWithValue("@start_work", StartPicker.Value);
- reportCommand.Parameters.AddWithValue("@end_work", StopPicker.Value);
- //DateTime overflow = new DateTime(0000, 00, 00, 24, 00, 00);
- //if ((StopPicker.Value - StartPicker.Value) < temp)
- //{
- //}
- TimeSpan TS = new TimeSpan(24, 0, 0);
- TimeSpan result = TS + (StopPicker.Value - StartPicker.Value);
- //reportCommand.Parameters.AddWithValue("@intervall", result.ToString());
- string formatted = result.ToString(@"hh\:mm\:ss");
- reportCommand.Parameters.AddWithValue("@intervall", Convert.ToDateTime(formatted.ToString()).ToShortTimeString());
- //SqlParameter parCreate = reportCommand.Parameters.Add("@create", System.Data.SqlDbType.DateTime);
- //parCreate.Value = DateTime.Now;
- //SqlParameter parModify = reportCommand.Parameters.Add("@modify", System.Data.SqlDbType.DateTime);
- //parModify.Value = DateTime.Now;
- try
- {
- reportCommand.Parameters.AddWithValue("@worker_number", Int32.Parse(numberCombo.Text));
- }
- catch (Exception ex)
- {
- MessageBox.Show("A törzsszám hibás: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
- return;
- }
- try
- {
- cnn.Open();
- }
- catch (Exception ex)
- {
- MessageBox.Show("Hiba az adatbázis megnyitása közben: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
- return;
- }
- reportCommand.ExecuteNonQuery();
- cnn.Close();
- try
- {
- cnn.Open();
- }
- catch (Exception ex)
- {
- MessageBox.Show("Hiba az adatbázis megnyitása közben: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
- return;
- }
- lastID();
- toolCommand.Parameters.Add("@tool", System.Data.SqlDbType.NVarChar);
- toolCommand.Parameters.AddWithValue("@report_iD", actualLastID);
- if (toolList.Items.Count > 0)
- {
- foreach (var Tool in toolList.Items)
- {
- //toolCommand.Parameters.AddWithValue("@tool", Tool.ToString());
- toolCommand.Parameters["@tool"].Value = Tool.ToString();
- toolCommand.ExecuteNonQuery();
- }
- }
- cnn.Close();
- clearAll();
- MessageBox.Show("A jelentés leadása sikeresen megtörtént!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
- if (sorting)
- {
- sortByDate();
- fillToolCombo();
- }
- else
- {
- fillMachineCombo();
- fillToolCombo();
- }
- }
- else
- {
- if (!checkMainData())
- {
- MessageBox.Show("A leadás csak a felső sor kitöltése után lehetséges!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- }
- else if (dataExist())
- {
- MessageBox.Show("Meglévő azonosítóval próbál adatokat menteni!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- }
- if (descriptionBox.TextLength > 15000)
- {
- MessageBox.Show("A hiba leírása nem haladhatja meg a 15000 karaktert.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- }
- if (solutionBox.TextLength > 15000)
- {
- MessageBox.Show("A megoldás nem haladhatja meg a 15000 karaktert.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- }
- }
- }
- private void clearAll()
- {
- machineCombo.ResetText();
- errorCombo.ResetText();
- numberCombo.ResetText();
- toolCombo.ResetText();
- descriptionBox.ResetText();
- solutionBox.ResetText();
- toolList.Items.Clear();
- }
- private bool checkMainData()
- {
- return (string.IsNullOrEmpty(machineCombo.Text) ||
- string.IsNullOrEmpty(errorCombo.Text) ||
- string.IsNullOrEmpty(numberCombo.Text) ||
- string.IsNullOrWhiteSpace(machineCombo.Text) ||
- string.IsNullOrWhiteSpace(errorCombo.Text) ||
- string.IsNullOrWhiteSpace(numberCombo.Text))
- ? false : true;
- }
- private void addToolButton_Click(object sender, EventArgs e)
- {
- if (!toolList.Items.Contains(toolCombo.Text))
- {
- if (!string.IsNullOrWhiteSpace(toolCombo.Text))
- {
- toolList.Items.Add(toolCombo.Text);
- }
- }
- toolCombo.ResetText();
- }
- private void delToolButton_Click(object sender, EventArgs e)
- {
- if (toolList.SelectedItem == null)
- {
- if (toolList.Items.Count > 0)
- {
- toolList.Items.RemoveAt(toolList.Items.Count - 1);
- }
- }
- else
- {
- toolList.Items.Remove(toolList.SelectedItem);
- }
- }
- private void fillErrorCombo()
- {
- errorCombo.Items.Clear();
- cnn = new SqlConnection(connectionString);
- AutoCompleteStringCollection data = new AutoCompleteStringCollection();
- try
- {
- cnn.Open();
- }
- catch (Exception ex)
- {
- MessageBox.Show("Hiba az adatbázis megnyitása közben: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
- return;
- }
- SqlDataReader dr;
- try
- {
- string sortQuery;
- SqlCommand cmd;
- if (sorting)
- {
- sortQuery = "SELECT DISTINCT Error_Short, Machine, Create_Record, Modify_Record FROM Report_tbl WHERE Machine = @machine AND Modify_Record BETWEEN @start_date AND @end_date";
- cmd = new SqlCommand(sortQuery, cnn);
- cmd.Parameters.AddWithValue("@machine", machineCombo.Text);
- cmd.Parameters.AddWithValue("@start_date", monthCalendar1.SelectionRange.Start);
- cmd.Parameters.AddWithValue("@end_date", monthCalendar1.SelectionRange.End.AddDays(1));
- }
- else
- {
- sortQuery = "SELECT DISTINCT Error_Short, Machine, Create_Record, Modify_Record FROM Report_tbl WHERE Machine = @machine";
- cmd = new SqlCommand(sortQuery, cnn);
- cmd.Parameters.AddWithValue("@machine", machineCombo.Text);
- }
- dr = cmd.ExecuteReader();
- while (dr.Read())
- {
- string getStringFromDR = dr.GetString(0);
- if (!errorCombo.Items.Contains(getStringFromDR))
- {
- errorCombo.Items.Add(getStringFromDR);
- errorCombo.AutoCompleteCustomSource = data;
- }
- }
- dr.Close();
- }
- catch (Exception ex)
- {
- MessageBox.Show("425Hiba a lekérdezés közben: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
- }
- cnn.Close();
- }
- private void fillWorkerCombo()
- {
- numberCombo.Items.Clear();
- cnn = new SqlConnection(connectionString);
- using (cnn)
- {
- AutoCompleteStringCollection data = new AutoCompleteStringCollection();
- try
- {
- cnn.Open();
- }
- catch (Exception ex)
- {
- MessageBox.Show("Hiba az adatbázis megnyitása közben: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
- return;
- }
- SqlDataReader dr;
- try
- {
- string sortQuery;
- SqlCommand cmd;
- if (sorting)
- {
- sortQuery = "SELECT Worker_Number, Error_Short, Machine, Create_Record, Modify_Record FROM Report_tbl WHERE Machine = @machine AND Error_Short = @errorshort AND Modify_Record BETWEEN @start_date AND @end_date";
- cmd = new SqlCommand(sortQuery, cnn);
- cmd.Parameters.AddWithValue("@machine", machineCombo.Text);
- cmd.Parameters.AddWithValue("@errorshort", errorCombo.Text);
- cmd.Parameters.AddWithValue("@start_date", monthCalendar1.SelectionRange.Start);
- cmd.Parameters.AddWithValue("@end_date", monthCalendar1.SelectionRange.End.AddDays(1));
- }
- else
- {
- sortQuery = "SELECT Worker_Number, Error_Short, Machine, Create_Record, Modify_Record FROM Report_tbl WHERE Machine = @machine AND Error_Short = @errorshort";
- cmd = new SqlCommand(sortQuery, cnn);
- cmd.Parameters.AddWithValue("@machine", machineCombo.Text);
- cmd.Parameters.AddWithValue("@errorshort", errorCombo.Text);
- }
- //------------------------------------------------------------------------------------------------------------------------------
- dr = cmd.ExecuteReader();
- int workerNumber = 0;
- while (dr.HasRows)
- {
- while (dr.Read())
- {
- int getIntFromDR = dr.GetInt32(0);
- if (!numberCombo.Items.Contains(getIntFromDR))
- {
- workerNumber = getIntFromDR;
- numberCombo.Text = workerNumber.ToString();
- numberCombo.Items.Add(workerNumber.ToString());
- numberCombo.AutoCompleteCustomSource = data;
- }
- }
- dr.NextResult();
- }
- dr.Close();
- }
- catch (Exception ex)
- {
- MessageBox.Show("521Hiba a lekérdezés közben: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
- }
- cnn.Close();
- }
- }
- private void fillMachineCombo()
- {
- machineCombo.Items.Clear();
- cnn = new SqlConnection(connectionString);
- AutoCompleteStringCollection data = new AutoCompleteStringCollection();
- try
- {
- cnn.Open();
- }
- catch (Exception ex)
- {
- MessageBox.Show("Hiba az adatbázis megnyitása közben: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
- return;
- }
- SqlDataReader dr;
- try
- {
- SqlCommand cmd = new SqlCommand("SELECT DISTINCT Machine FROM Report_tbl", cnn);
- dr = cmd.ExecuteReader();
- while (dr.Read())
- {
- string getStringFromDR = dr.GetString(0);
- if (!machineCombo.Items.Contains(getStringFromDR))
- {
- machineCombo.Items.Add(getStringFromDR);
- machineCombo.AutoCompleteCustomSource = data;
- }
- }
- dr.Close();
- }
- catch (Exception ex)
- {
- MessageBox.Show("575Hiba a lekérdezés közben: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
- }
- cnn.Close();
- }
- private void fillToolCombo()
- {
- toolCombo.Items.Clear();
- cnn = new SqlConnection(connectionString);
- AutoCompleteStringCollection data = new AutoCompleteStringCollection();
- try
- {
- cnn.Open();
- }
- catch (Exception ex)
- {
- MessageBox.Show("Hiba az adatbázis megnyitása közben: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
- return;
- }
- SqlDataReader dr;
- try
- {
- SqlCommand cmd = new SqlCommand("SELECT DISTINCT Tool FROM Tool_tbl", cnn);
- dr = cmd.ExecuteReader();
- while (dr.Read())
- {
- toolCombo.Items.Add(dr.GetString(0));
- toolCombo.AutoCompleteCustomSource = data;
- }
- dr.Close();
- }
- catch (Exception ex)
- {
- MessageBox.Show("622Hiba a lekérdezés közben: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
- }
- cnn.Close();
- }
- private void eReport_Form_Load(object sender, EventArgs e)
- {
- }
- private void groupBox1_Enter(object sender, EventArgs e)
- {
- }
- private void clearExceptMachine()
- {
- errorCombo.ResetText();
- numberCombo.ResetText();
- descriptionBox.ResetText();
- solutionBox.ResetText();
- toolCombo.ResetText();
- toolList.Items.Clear();
- }
- private void sortByMachine(object sender, EventArgs e)
- {
- if (machineCombo.Text.Length > 50)
- {
- MessageBox.Show("A gép neve nem állhat több, mint 50 karakterből!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- machineCombo.ResetText();
- }
- else
- {
- clearExceptMachine();
- fillErrorCombo();
- if (checkMainData())
- {
- getOthers();
- }
- }
- }
- private void sortByError(object sender, EventArgs e)
- {
- if (errorCombo.Text.Length > 50)
- {
- MessageBox.Show("A hiba rövid leirása nem haladhatja meg az 50 karaktert!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- errorCombo.ResetText();
- }
- else
- {
- fillWorkerCombo();
- if (checkMainData())
- {
- getOthers();
- }
- }
- }
- private void workerTextChanged(object sender, EventArgs e)
- {
- try
- {
- if (!string.IsNullOrEmpty(numberCombo.Text))
- {
- Int32.Parse(numberCombo.Text);
- }
- if (checkMainData())
- {
- getOthers();
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show("A törzsszám hibás: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
- numberCombo.ResetText();
- return;
- }
- }
- private void getOthers()
- {
- int reportID = 0;
- cnn = new SqlConnection(connectionString);
- try
- {
- cnn.Open();
- }
- catch (Exception ex)
- {
- MessageBox.Show("Hiba az adatbázis megnyitása közben: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
- return;
- }
- SqlDataReader dr;
- SqlDataReader drTool;
- try
- {
- string sortQuery;
- SqlCommand cmd;
- if (sorting)
- {
- sortQuery = "SELECT ID, Machine, Error_Short, Worker_Number, Report, Solution, Create_Record, Modify_Record FROM Report_tbl " +
- "WHERE Machine = @machine AND Error_Short = @error_short AND Worker_Number = @worker_number AND Modify_Record BETWEEN @start_date AND @end_date";
- cmd = new SqlCommand(sortQuery, cnn);
- cmd.Parameters.AddWithValue("@machine", machineCombo.Text);
- cmd.Parameters.AddWithValue("@error_short", errorCombo.Text);
- cmd.Parameters.AddWithValue("@worker_number", numberCombo.Text);
- cmd.Parameters.AddWithValue("@start_date", monthCalendar1.SelectionRange.Start);
- cmd.Parameters.AddWithValue("@end_date", monthCalendar1.SelectionRange.End.AddDays(1));
- }
- else
- {
- sortQuery = "SELECT ID, Machine, Error_Short, Worker_Number, Report, Solution, Create_Record, Modify_Record, Start_Work, End_Work FROM Report_tbl " +
- "WHERE Machine = @machine AND Error_Short = @error_short AND Worker_Number = @worker_number";
- cmd = new SqlCommand(sortQuery, cnn);
- cmd.Parameters.AddWithValue("@machine", machineCombo.Text);
- cmd.Parameters.AddWithValue("@error_short", errorCombo.Text);
- cmd.Parameters.AddWithValue("@worker_number", numberCombo.Text);
- }
- dr = cmd.ExecuteReader();
- while (dr.Read())
- {
- reportID = dr.GetInt32(0);
- descriptionBox.Text = dr.GetString(4);
- solutionBox.Text = dr.GetString(5);
- StartPicker.Value = dr.GetDateTime(8);
- StopPicker.Value = dr.GetDateTime(9);
- }
- globalReportID = reportID;
- dr.Close();
- string sortQueryTool = "SELECT ID, Tool, Report_ID FROM Tool_tbl " +
- "WHERE Report_ID = @reportid";
- SqlCommand cmdTool = new SqlCommand(sortQueryTool, cnn);
- cmdTool.Parameters.AddWithValue("@reportid", reportID);
- drTool = cmdTool.ExecuteReader();
- if (numberCombo.Items.Contains(numberCombo.Text))
- {
- toolList.Items.Clear();
- }
- while (drTool.Read())
- {
- string actualTool = drTool.GetString(1);
- if (!toolList.Items.Contains(actualTool))
- {
- toolList.Items.Add(actualTool);
- }
- }
- drTool.Close();
- }
- catch (Exception ex)
- {
- MessageBox.Show("827Hiba a lekérdezés közben: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
- }
- cnn.Close();
- }
- private bool dataExist()
- {
- cnn = new SqlConnection(connectionString);
- try
- {
- cnn.Open();
- }
- catch (Exception ex)
- {
- MessageBox.Show("Hiba az adatbázis megnyitása közben: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
- }
- SqlDataReader dr;
- try
- {
- string sortQuery = "SELECT COUNT(*) FROM Report_tbl " +
- "WHERE Machine = @machine AND Error_Short = @error_short AND Worker_Number = @worker_number AND Intervall = @intervall";
- SqlCommand cmd = new SqlCommand(sortQuery, cnn);
- TimeSpan TS = new TimeSpan(24, 0, 0);
- TimeSpan result = TS + (StopPicker.Value - StartPicker.Value);
- cmd.Parameters.AddWithValue("@machine", machineCombo.Text);
- cmd.Parameters.AddWithValue("@error_short", errorCombo.Text);
- cmd.Parameters.AddWithValue("@worker_number", numberCombo.Text);
- MessageBox.Show("867 " + result.GetType());
- string formatted = result.ToString(@"hh\:mm\:ss");
- cmd.Parameters.AddWithValue("@intervall", Convert.ToDateTime(formatted.ToString()).ToShortTimeString());
- //cmd.Parameters.AddWithValue("@intervall", (result).ToString());
- MessageBox.Show("871");
- dr = cmd.ExecuteReader();
- MessageBox.Show("875");
- while (dr.Read())
- {
- if (dr.GetInt32(0) > 0)
- {
- MessageBox.Show("882");
- cnn.Close();
- return true;
- }
- }
- MessageBox.Show("889");
- dr.Close();
- }
- catch (Exception ex)
- {
- MessageBox.Show("878Hiba a lekérdezés közben: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
- }
- cnn.Close();
- return false;
- }
- private void modifyReport_Click(object sender, EventArgs e)
- {
- if (checkMainData() && dataExist() && descriptionBox.TextLength <= 15000 && solutionBox.TextLength <= 15000)
- {
- if (checkPassword())
- {
- cnn = new SqlConnection(connectionString);
- string delToolsQuery = "DELETE FROM Tool_tbl WHERE Report_ID = @report_id";
- string modQuery = "UPDATE Report_tbl SET Report = @report, Solution = @solution, Modify_Record = @modify_record WHERE ID = @report_id";
- string modToolQuery = "INSERT INTO Tool_tbl (Tool, Report_ID) VALUES (@tool, @report_id)";
- SqlCommand modReportCommand = new SqlCommand(modQuery, cnn);
- SqlCommand modToolCommand = new SqlCommand(modToolQuery, cnn);
- SqlCommand delToolsCommand = new SqlCommand(delToolsQuery, cnn);
- delToolsCommand.Parameters.AddWithValue("@report_iD", globalReportID);
- try
- {
- cnn.Open();
- }
- catch (Exception ex)
- {
- MessageBox.Show("Hiba az adatbázis megnyitása közben: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
- return;
- }
- try
- {
- delToolsCommand.ExecuteNonQuery();
- }
- catch (Exception ex)
- {
- MessageBox.Show("Hiba az adatbázis frissítése közben: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
- return;
- }
- cnn.Close();
- modReportCommand.Parameters.AddWithValue("@report", descriptionBox.Text);
- modReportCommand.Parameters.AddWithValue("@solution", solutionBox.Text);
- modReportCommand.Parameters.AddWithValue("@report_id", globalReportID);
- modReportCommand.Parameters.AddWithValue("@modify_record", DateTime.Now);
- try
- {
- cnn.Open();
- }
- catch (Exception ex)
- {
- MessageBox.Show("Hiba az adatbázis megnyitása közben: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
- return;
- }
- try
- {
- modReportCommand.ExecuteNonQuery();
- }
- catch (Exception ex)
- {
- MessageBox.Show("Hiba az adatbázis frissítése közben: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
- return;
- }
- cnn.Close();
- try
- {
- cnn.Open();
- }
- catch (Exception ex)
- {
- MessageBox.Show("Hiba az adatbázis megnyitása közben: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
- return;
- }
- modToolCommand.Parameters.Add("@tool", System.Data.SqlDbType.NVarChar);
- modToolCommand.Parameters.AddWithValue("@report_id", globalReportID);
- if (toolList.Items.Count > 0)
- {
- foreach (var Tool in toolList.Items)
- {
- //toolCommand.Parameters.AddWithValue("@tool", Tool.ToString());
- modToolCommand.Parameters["@tool"].Value = Tool.ToString();
- modToolCommand.ExecuteNonQuery();
- }
- }
- cnn.Close();
- clearAll();
- MessageBox.Show("A jelentés módosítása sikeresen megtörtént!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
- if (sorting)
- {
- sortByDate();
- }
- else
- {
- fillMachineCombo();
- }
- //sortByDate();
- }
- }
- else
- {
- if (!checkMainData())
- {
- MessageBox.Show("A módosítás csak a felső sor kitöltése után lehetséges, kivéve az időket!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- }
- else if (!dataExist())
- {
- MessageBox.Show("Nem létező azonosítóval próbál adatokat módosítani!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- }
- if (descriptionBox.TextLength > 15000)
- {
- MessageBox.Show("A hiba leírása nem haladhatja meg a 15000 karaktert.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- }
- if (solutionBox.TextLength > 15000)
- {
- MessageBox.Show("A megoldás nem haladhatja meg a 15000 karaktert.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- }
- }
- }
- private void delete_Click(object sender, EventArgs e)
- {
- if (checkMainData() && dataExist())
- {
- if (checkPassword())
- {
- cnn = new SqlConnection(connectionString);
- string delToolsQuery = "DELETE FROM Tool_tbl WHERE Report_ID = @report_id";
- string delReportQuery = "DELETE FROM Report_tbl WHERE ID = @report_id";
- SqlCommand delReportCommand = new SqlCommand(delReportQuery, cnn);
- SqlCommand delToolsCommand = new SqlCommand(delToolsQuery, cnn);
- delReportCommand.Parameters.AddWithValue("@report_id", globalReportID);
- delToolsCommand.Parameters.AddWithValue("@report_id", globalReportID);
- try
- {
- cnn.Open();
- }
- catch (Exception ex)
- {
- MessageBox.Show("Hiba az adatbázis megnyitása közben: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
- return;
- }
- try
- {
- delReportCommand.ExecuteNonQuery();
- delToolsCommand.ExecuteNonQuery();
- }
- catch (Exception ex)
- {
- MessageBox.Show("Hiba a jelentés törlése közben: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
- return;
- }
- cnn.Close();
- clearAll();
- MessageBox.Show("A jelentés törlése sikeresen megtörtént!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
- if (sorting)
- {
- sortByDate();
- }
- else
- {
- fillMachineCombo();
- }
- }
- }
- else
- {
- if (!checkMainData())
- {
- MessageBox.Show("A törlés csak a felső sor kitöltése után lehetséges, kivéve az időket!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- }
- else if (!dataExist())
- {
- MessageBox.Show("Nem létező azonosítóval próbál adatokat törölni!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- }
- }
- }
- public static DialogResult InputBox(string title, string promptText, ref string value)
- {
- Form form = new Form();
- Label label = new Label();
- TextBox textBox = new TextBox();
- Button buttonOk = new Button();
- Button buttonCancel = new Button();
- form.Text = title;
- label.Text = promptText;
- textBox.Text = value;
- buttonOk.Text = "OK";
- buttonCancel.Text = "Cancel";
- buttonOk.DialogResult = DialogResult.OK;
- buttonCancel.DialogResult = DialogResult.Cancel;
- label.SetBounds(9, 20, 372, 13);
- textBox.SetBounds(12, 36, 372, 20);
- buttonOk.SetBounds(228, 72, 75, 23);
- buttonCancel.SetBounds(309, 72, 75, 23);
- label.AutoSize = true;
- textBox.Anchor = textBox.Anchor | AnchorStyles.Right;
- buttonOk.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
- buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
- form.ClientSize = new Size(396, 107);
- form.Controls.AddRange(new Control[] { label, textBox, buttonOk, buttonCancel });
- form.ClientSize = new Size(Math.Max(300, label.Right + 10), form.ClientSize.Height);
- form.FormBorderStyle = FormBorderStyle.FixedDialog;
- form.StartPosition = FormStartPosition.CenterScreen;
- form.MinimizeBox = false;
- form.MaximizeBox = false;
- form.AcceptButton = buttonOk;
- form.CancelButton = buttonCancel;
- DialogResult dialogResult = form.ShowDialog();
- value = textBox.Text;
- return dialogResult;
- }
- public bool checkPassword()
- {
- string pw = "tmktorus";
- string value = "";
- if (InputBox("Jelszó", "Adja meg a jelszót:", ref value) == DialogResult.OK)
- {
- if (string.Equals(pw, value))
- {
- return true;
- }
- else
- {
- MessageBox.Show("Hibás jelszó!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- }
- }
- return false;
- }
- private void dateSelected(object sender, DateRangeEventArgs e)
- {
- //string message = "Akarja alkalmazni a kiválasztott dátum szerinti szűrést?";
- //string title = "Szűrés";
- //MessageBoxButtons buttons = MessageBoxButtons.YesNo;
- //DialogResult result = MessageBox.Show(message, title, buttons);
- //if (result == DialogResult.Yes)
- //{
- // pictureBox1.BackColor = Color.Green;
- // sortByDate();
- //}
- //else
- //{
- // pictureBox1.BackColor = Color.Transparent;
- // fillMachineCombo();
- //}
- }
- private void dateChanged(object sender, DateRangeEventArgs e)
- {
- if (sorting)
- {
- sortByDate();
- }
- }
- private void sortByDate()
- {
- using (SqlConnection cnn = new SqlConnection(connectionString))
- {
- SqlCommand cmd;
- //cnn = new SqlConnection(connectionString);
- try
- {
- cnn.Open();
- }
- catch (Exception ex)
- {
- MessageBox.Show("Hiba az adatbázis megnyitása közben: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
- return;
- }
- machineCombo.Items.Clear();
- AutoCompleteStringCollection data = new AutoCompleteStringCollection();
- SqlDataReader dr;
- try
- {
- clearAll();
- //if (monthCalendar1.SelectionRange.Start.ToString("MM:dd:yyyy") != DateTime.Now.ToString("MM:dd:yyyy") || monthCalendar1.SelectionRange.End.ToString("MM:dd:yyyy") != DateTime.Now.ToString("MM:dd:yyyy"))
- //{
- cmd = new SqlCommand("SELECT DISTINCT Machine FROM Report_tbl WHERE Modify_Record BETWEEN @start_date AND @end_date", cnn);
- cmd.Parameters.AddWithValue("@start_date", Convert.ToDateTime(monthCalendar1.SelectionRange.Start.ToString()));
- cmd.Parameters.AddWithValue("@end_date", Convert.ToDateTime(monthCalendar1.SelectionRange.End.ToString()).AddDays(1));
- dr = cmd.ExecuteReader();
- while (dr.Read())
- {
- machineCombo.Items.Add(dr.GetString(0));
- machineCombo.AutoCompleteCustomSource = data;
- }
- dr.Close();
- cnn.Close();
- //}
- //else
- //{
- // cnn.Close();
- // fillMachineCombo();
- // fillToolCombo();
- //}
- }
- catch (Exception ex)
- {
- MessageBox.Show("1268Hiba a lekérdezés közben: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
- }
- }
- }
- private void sortButton_Click(object sender, EventArgs e)
- {
- clearAll();
- if (sorting)
- {
- sorting = false;
- fillMachineCombo();
- sortButton.BackColor = Color.White;
- }
- else
- {
- //machineCombo.Items.Clear();
- sorting = true;
- sortByDate();
- sortButton.BackColor = Color.GreenYellow;
- MessageBox.Show("A félreértések elkerülése érdekében kapcsolja ki a szűrőt a keresés után!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- }
- private void button6_Click(object sender, EventArgs e)
- {
- clearAll();
- button3.Enabled = true;
- button3.BackColor = Color.White;
- }
- private void make_Dir(string path)
- {
- //string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\Reports" + "\\" + DateTime.Now.ToString("yyyy") + "\\" + DateTime.Now.ToString("yyyy_MM") + "\\" + DateTime.Now.ToString("yyyy_MM_dd");
- try
- {
- // Determine whether the directory exists.
- if (Directory.Exists(path))
- {
- return;
- }
- // Try to create the directory.
- DirectoryInfo di = Directory.CreateDirectory(path);
- }
- catch (Exception ex)
- {
- MessageBox.Show("Hiba a mappaszerkezet létrehozása közben: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
- }
- //System.Threading.Thread.Sleep(500);
- }
- private void Export_CSV()
- {
- SqlConnection conn;
- SqlDataReader dr;
- string fileName;
- try
- {
- conn = new SqlConnection(connectionString);
- conn.Open();
- }
- catch (Exception ex)
- {
- MessageBox.Show("Hiba az adatbázis megnyitása közben: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
- return;
- }
- try
- {
- SqlCommand cmd = new SqlCommand("SELECT * FROM Report_tbl WHERE Modify_Record > @NOW", conn); // "SELECT * FROM Report_tbl WHERE Modify_Record > @NOW"
- cmd.Parameters.AddWithValue("@NOW", DateTime.Now.AddHours(-8));
- dr = cmd.ExecuteReader();
- }
- catch (Exception ex)
- {
- MessageBox.Show("1364Hiba a lekérdezés közben: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
- return;
- }
- try
- {
- make_Dir("C:\\Users\\Public\\Desktop\\Reports" + "\\" + DateTime.Now.ToString("yyyy") + "\\" + DateTime.Now.ToString("yyyy_MM") + "\\" + DateTime.Now.ToString("yyyy_MM_dd"));
- //make_Dir("C:\\Users\\Public\\Desktop\\Reports\\" + DateTime.Now.ToString("yyyy") + "\\" + DateTime.Now.ToString("yyyy_MM") + "\\" + DateTime.Now.ToString("yyyy_MM_dd"));
- fileName = "C:\\Users\\Public\\Desktop\\Reports" + "\\" + DateTime.Now.ToString("yyyy") + "\\" + DateTime.Now.ToString("yyyy_MM") + "\\" + DateTime.Now.ToString("yyyy_MM_dd") + "\\" + "eReport_" + DateTime.Now.ToString("yyyy_MM_dd_HH_mm") + ".csv";
- //fileName = "C:\\Users\\Public\\Desktop\\Reports\\" + DateTime.Now.ToString("yyyy") + "\\" + DateTime.Now.ToString("yyyy_MM") + "\\" + DateTime.Now.ToString("yyyy_MM_dd") + "\\eReport_" + DateTime.Now.ToString("yyyy_MM_dd_HH_mm") + ".csv";
- //MessageBox.Show(Environment.GetFolderPath(Environment.SpecialFolder.Desktop));
- }
- catch (Exception ex)
- {
- MessageBox.Show("Hiba az elérési út megadása közben: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
- return;
- }
- try
- {
- FileInfo oldFile = new FileInfo(fileName);
- if (oldFile.Exists)
- {
- File.SetAttributes(oldFile.FullName, FileAttributes.Normal);
- oldFile.Delete();
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show("Hiba a régebbi report fájl törlése közben: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
- return;
- }
- using (System.IO.StreamWriter fs = new System.IO.StreamWriter(new FileStream(fileName, FileMode.Create), Encoding.UTF8))
- {
- // Loop through the fields and add headers
- for (int i = 0; i < dr.FieldCount; i++)
- {
- string name = dr.GetName(i);
- if (name == "ID") name = " ID ";
- if (name.Contains(","))
- name = "\"" + name + "\"";
- fs.Write(name + ";");
- }
- fs.WriteLine();
- // Loop through the rows and output the data
- while (dr.Read())
- {
- for (int i = 0; i < dr.FieldCount; i++)
- {
- string value;
- if (i == 6 || i == 7)
- {
- value = Convert.ToDateTime(dr[i]).ToString("yyyy.MM.dd HH:mm");
- }
- else
- {
- value = dr[i].ToString();
- }
- if (value.Contains(","))
- value = "\"" + value + "\"";
- fs.Write(value + ";");
- }
- fs.WriteLine();
- }
- fs.Close();
- }
- conn.Close();
- }
- private void ExportAll_CSV()
- {
- SqlConnection conn;
- SqlDataReader dr;
- string fileName;
- try
- {
- conn = new SqlConnection(connectionString);
- conn.Open();
- }
- catch (Exception ex)
- {
- MessageBox.Show("Hiba az adatbázis megnyitása közben: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
- return;
- }
- try
- {
- SqlCommand cmd = new SqlCommand("SELECT * FROM Report_tbl", conn); // "SELECT * FROM Report_tbl WHERE Modify_Record > @NOW"
- cmd.Parameters.AddWithValue("@NOW", DateTime.Now.AddHours(-8));
- dr = cmd.ExecuteReader();
- }
- catch (Exception ex)
- {
- MessageBox.Show("1475Hiba a lekérdezés közben: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
- return;
- }
- try
- {
- make_Dir("C:\\Users\\Public\\Desktop\\Reports\\All");
- //make_Dir("C:\\Users\\Public\\Desktop\\Reports\\" + DateTime.Now.ToString("yyyy") + "\\" + DateTime.Now.ToString("yyyy_MM") + "\\" + DateTime.Now.ToString("yyyy_MM_dd"));
- fileName = "C:\\Users\\Public\\Desktop\\Reports\\All\\eReport_All_" + DateTime.Now.ToString("yyyy_MM_dd") + ".csv";
- //fileName = "C:\\Users\\Public\\Desktop\\Reports\\" + DateTime.Now.ToString("yyyy") + "\\" + DateTime.Now.ToString("yyyy_MM") + "\\" + DateTime.Now.ToString("yyyy_MM_dd") + "\\eReport_" + DateTime.Now.ToString("yyyy_MM_dd_HH_mm") + ".csv";
- //MessageBox.Show(Environment.GetFolderPath(Environment.SpecialFolder.Desktop));
- }
- catch (Exception ex)
- {
- MessageBox.Show("Hiba az elérési út megadása közben: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
- return;
- }
- try
- {
- FileInfo oldFile = new FileInfo(fileName);
- if (oldFile.Exists)
- {
- File.SetAttributes(oldFile.FullName, FileAttributes.Normal);
- oldFile.Delete();
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show("Hiba a régebbi report fájl törlése közben: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
- return;
- }
- using (System.IO.StreamWriter fs = new System.IO.StreamWriter(new FileStream(fileName, FileMode.Create), Encoding.UTF8))
- {
- // Loop through the fields and add headers
- for (int i = 0; i < dr.FieldCount; i++)
- {
- string name = dr.GetName(i);
- if (name == "ID") name = " ID ";
- if (name.Contains(","))
- name = "\"" + name + "\"";
- fs.Write(name + ";");
- }
- fs.WriteLine();
- // Loop through the rows and output the data
- while (dr.Read())
- {
- for (int i = 0; i < dr.FieldCount; i++)
- {
- string value;
- if (6 <= i && i <= 9)
- {
- value = Convert.ToDateTime(dr[i]).ToString("yyyy.MM.dd HH:mm");
- }
- //else if(i == 10)
- //{
- // value = Convert.ToDateTime(dr[i]).AddTicks(-(Convert.ToDateTime(dr[i]).Ticks % TimeSpan.TicksPerSecond)).ToString();
- //}
- else
- {
- value = dr[i].ToString();
- }
- if (value.Contains(","))
- value = "\"" + value + "\"";
- fs.Write(value + ";");
- }
- fs.WriteLine();
- }
- fs.Close();
- }
- conn.Close();
- }
- /*private void BackupSQL()
- {
- make_Dir("C:\\Users\\Public\\Desktop\\SQLBackup");
- cnn = new SqlConnection(connectionString);
- //string backupQuery = @"BACKUP DATABASE eReport TO DISK = N'D:\Programs\data.bak'";
- string backupQuery = @"BACKUP DATABASE eReport TO DISK = N'C:\Users\Public\Desktop\SQLBackup\data.bak'";
- SqlCommand backupCommand = new SqlCommand(backupQuery, cnn);
- try
- {
- File.Delete(@"C:\Users\Public\Desktop\SQLBackup\data.bak");
- }
- catch (Exception ex)
- {
- MessageBox.Show("Hiba az elavult backup fájl törlése közben: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
- return;
- }
- try
- {
- cnn.Open();
- }
- catch (Exception ex)
- {
- MessageBox.Show("Hiba az adatbázis megnyitása közben: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
- return;
- }
- try
- {
- backupCommand.ExecuteNonQuery();
- }
- catch (Exception ex)
- {
- MessageBox.Show("Hiba a backup fájl létrehozása közben: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
- return;
- }
- cnn.Close();
- }*/
- private void RegisterInStartup()
- {
- try
- {
- RegistryKey registryKey = Registry.CurrentUser.OpenSubKey
- ("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
- registryKey.SetValue("eReport", Path.GetDirectoryName(Application.ExecutablePath) + "\\eReport.exe");
- //registryKey.DeleteValue("eReport", false);
- }
- catch (Exception ex)
- {
- MessageBox.Show("A program rendszerrel induló alkalmazásként történő regisztrálása közben hiba lépett fel: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
- return;
- }
- }
- protected override void OnFormClosing(FormClosingEventArgs e)
- {
- base.OnFormClosing(e);
- if (e.CloseReason == CloseReason.WindowsShutDown) return;
- // Confirm user wants to close
- switch (MessageBox.Show(this, "Bezárás után a program nem exportálja ki a reportokat!" + "\n" + "Biztosan kilép?", "Bezárás", MessageBoxButtons.YesNo, MessageBoxIcon.Question))
- {
- case DialogResult.No:
- e.Cancel = true;
- break;
- default:
- break;
- }
- }
- private void toolCombo_KeyDown(object sender, KeyEventArgs e)
- {
- if (toolCombo.Text.Length > 49) // allow max 20 chars
- {
- if (!e.KeyCode.Equals(Keys.Back)) // allow removing chars
- {
- e.Handled = true; // block any additional key press if there is more than allowed max
- //System.Media.SystemSounds.Beep.Play(); // optional: beep to let user know he is out of space :)
- }
- }
- else
- {
- ;
- if (e.KeyCode.Equals(Keys.Enter)) {;
- if (!toolList.Items.Contains(toolCombo.Text))
- {
- if (!string.IsNullOrWhiteSpace(toolCombo.Text))
- {
- toolList.Items.Add(toolCombo.Text);
- }
- }
- toolCombo.ResetText();
- }
- }
- }
- private void toolComboTextChanged(object sender, EventArgs e)
- {
- if (toolCombo.Text.Length > 50)
- {
- MessageBox.Show("Nem adhat meg 50-nél több karaktert egy szerszám nevének!", "Figyelmeztetés", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- toolCombo.ResetText();
- }
- }
- private void button8_Click(object sender, EventArgs e)
- {
- try
- {
- ExportAll_CSV();
- //BackupSQL();
- MessageBox.Show("Az adatbázis exportálása sikeresen lezajlott.", "Információ", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- catch (Exception ex)
- {
- MessageBox.Show("Hiba lépett fel az adatbázis exportálása közben: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
- return;
- }
- }
- private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
- {
- }
- private void toolCombo_SelectedIndexChanged(object sender, EventArgs e)
- {
- }
- private int lastWorkerCount(int workerNumber)
- {
- cnn = new SqlConnection(connectionString);
- //AutoCompleteStringCollection data = new AutoCompleteStringCollection();
- try
- {
- cnn.Open();
- }
- catch (Exception ex)
- {
- MessageBox.Show("Hiba az adatbázis megnyitása közben: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
- }
- SqlDataReader dr;
- try
- {
- string sortQuery;
- SqlCommand cmd;
- if (sorting)
- {
- sortQuery = "SELECT Worker_Number_Count FROM Report_tbl WHERE Machine = @machine AND Error_Short = @errorshort AND Worker_Number = " + workerNumber + " AND Modify_Record BETWEEN @start_date AND @end_date";
- cmd = new SqlCommand(sortQuery, cnn);
- cmd.Parameters.AddWithValue("@machine", machineCombo.Text);
- cmd.Parameters.AddWithValue("@errorshort", errorCombo.Text);
- cmd.Parameters.AddWithValue("@start_date", monthCalendar1.SelectionRange.Start);
- cmd.Parameters.AddWithValue("@end_date", monthCalendar1.SelectionRange.End.AddDays(1));
- }
- else
- {
- sortQuery = "SELECT Worker_Number_Count FROM Report_tbl WHERE Machine = @machine AND Error_Short = @errorshort AND Worker_Number = " + workerNumber + " ";
- cmd = new SqlCommand(sortQuery, cnn);
- cmd.Parameters.AddWithValue("@machine", machineCombo.Text);
- cmd.Parameters.AddWithValue("@errorshort", errorCombo.Text);
- }
- dr = cmd.ExecuteReader();
- MessageBox.Show("1804");
- while (dr.Read())
- {
- actualWorkerCount = dr.GetInt32(0);
- }
- MessageBox.Show("1810");
- dr.Close();
- }
- catch (Exception ex)
- {
- MessageBox.Show("Hiba a lekérdezés közben: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
- }
- cnn.Close();
- return actualWorkerCount;
- }
- private void button7_Click(object sender, EventArgs e)
- {
- if (checkMainData() && !dataExist() && descriptionBox.TextLength <= 15000 && solutionBox.TextLength <= 15000)
- {
- int workerNumberCount;
- cnn = new SqlConnection(connectionString);
- try
- {
- cnn.Open();
- }
- catch (Exception ex)
- {
- MessageBox.Show("Hiba az adatbázis megnyitása közben: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
- return;
- }
- string reportQuery = "INSERT INTO Report_tbl (Machine, Error_Short, Worker_Number, Report, Solution, Create_Record, Modify_Record, Start_Work, End_Work, Intervall, Worker_Number_Count) " +
- "VALUES (@machine, @error_short, @worker_number, @report, @solution, @create_record, @modify_record, @startwork, @endwork, @intervall, @workernumbercount)";
- string toolQuery = "INSERT INTO Tool_tbl (Tool, Report_ID) " +
- "VALUES (@tool, @report_id)";
- SqlCommand reportCommand = new SqlCommand(reportQuery, cnn);
- SqlCommand toolCommand = new SqlCommand(toolQuery, cnn);
- reportCommand.Parameters.AddWithValue("@machine", machineCombo.Text);
- reportCommand.Parameters.AddWithValue("@error_short", errorCombo.Text);
- reportCommand.Parameters.AddWithValue("@report", descriptionBox.Text);
- reportCommand.Parameters.AddWithValue("@solution", solutionBox.Text);
- reportCommand.Parameters.AddWithValue("@create_record", DateTime.Now);
- reportCommand.Parameters.AddWithValue("@modify_record", DateTime.Now);
- reportCommand.Parameters.AddWithValue("@startwork", StartPicker.Value);
- reportCommand.Parameters.AddWithValue("@endwork", StopPicker.Value);
- //SqlParameter parCreate = reportCommand.Parameters.Add("@create", System.Data.SqlDbType.DateTime);
- //parCreate.Value = DateTime.Now;
- //SqlParameter parModify = reportCommand.Parameters.Add("@modify", System.Data.SqlDbType.DateTime);
- //parModify.Value = DateTime.Now;
- TimeSpan TS = new TimeSpan(24, 0, 0);
- TimeSpan result = TS + (StopPicker.Value - StartPicker.Value);
- reportCommand.Parameters.AddWithValue("@worker_number", numberCombo.Text);
- //reportCommand.Parameters.AddWithValue("@intervall", (result).ToString());
- string formatted = result.ToString(@"hh\:mm\:ss");
- reportCommand.Parameters.AddWithValue("@intervall", Convert.ToDateTime(formatted.ToString()).ToShortTimeString());
- try
- {
- MessageBox.Show("1882");
- workerNumberCount = lastWorkerCount(Int32.Parse(numberCombo.Text)) + 1;
- MessageBox.Show("1884");
- reportCommand.Parameters.AddWithValue("@workernumbercount", workerNumberCount);
- MessageBox.Show("1886");
- }
- catch (Exception ex)
- {
- MessageBox.Show("A törzsszám hibás: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
- return;
- }
- reportCommand.ExecuteNonQuery();
- cnn.Close();
- try
- {
- cnn.Open();
- }
- catch (Exception ex)
- {
- MessageBox.Show("Hiba az adatbázis megnyitása közben: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
- return;
- }
- lastID();
- toolCommand.Parameters.Add("@tool", System.Data.SqlDbType.NVarChar);
- toolCommand.Parameters.AddWithValue("@report_iD", actualLastID);
- MessageBox.Show("1912");
- if (toolList.Items.Count > 0)
- {
- foreach (var Tool in toolList.Items)
- {
- //toolCommand.Parameters.AddWithValue("@tool", Tool.ToString());
- toolCommand.Parameters["@tool"].Value = Tool.ToString();
- toolCommand.ExecuteNonQuery();
- }
- }
- MessageBox.Show("1923");
- cnn.Close();
- fillWorkerCombo();
- button3.Enabled = false;
- button3.BackColor = Color.LightGray;
- MessageBox.Show("A törzsám és a lejelentés is sikeresen megtörtént, a leadás gomb feloldásához kattintson a tisztítás gombra.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
- if (sorting)
- {
- sortByDate();
- fillToolCombo();
- }
- else
- {
- fillMachineCombo();
- fillToolCombo();
- }
- }
- else
- {
- if (!checkMainData())
- {
- MessageBox.Show("A leadás csak a felső sor kitöltése után lehetséges!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- }
- else if (dataExist())
- {
- MessageBox.Show("Meglévő azonosítóval próbál adatokat menteni!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- }
- if (descriptionBox.TextLength > 15000)
- {
- MessageBox.Show("A hiba leírása nem haladhatja meg a 15000 karaktert.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- }
- if (solutionBox.TextLength > 15000)
- {
- MessageBox.Show("A megoldás nem haladhatja meg a 15000 karaktert.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- }
- }
- }
- private void pictureBox1_Click(object sender, EventArgs e)
- {
- }
- private void numberCombo_SelectedIndexChanged(object sender, EventArgs e)
- {
- pickSets();
- }
- private void pickSets()
- {
- cnn = new SqlConnection(connectionString);
- using (cnn)
- {
- try
- {
- cnn.Open();
- }
- catch (Exception ex)
- {
- MessageBox.Show("Hiba az adatbázis megnyitása közben: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
- return;
- }
- SqlDataReader dr;
- try
- {
- string sortQuery;
- SqlCommand cmd;
- if (sorting)
- {
- sortQuery = "SELECT Start_Work, End_Work FROM Report_tbl WHERE Machine = @machinee AND Error_Short = @errorshortt AND Worker_Number = " + workerNumber + " AND Start_Work = " + StartPicker + " AND End_Work = " + StopPicker + " AND Modify_Record BETWEEN @start_datee AND @end_datee";
- cmd = new SqlCommand(sortQuery, cnn);
- cmd.Parameters.AddWithValue("@machinee", machineCombo.Text);
- cmd.Parameters.AddWithValue("@errorshortt", errorCombo.Text);
- cmd.Parameters.AddWithValue("@start_datee", monthCalendar1.SelectionRange.Start);
- cmd.Parameters.AddWithValue("@end_datee", monthCalendar1.SelectionRange.End.AddDays(1));
- }
- else
- {
- sortQuery = "SELECT Start_Work, End_Work FROM Report_tbl WHERE Machine = @machinee AND Error_Short = @errorshortt AND Worker_Number = " + workerNumber + " AND Start_Work = " + StartPicker + " AND End_Work = " + StopPicker + " ";
- cmd = new SqlCommand(sortQuery, cnn);
- cmd.Parameters.AddWithValue("@machinee", machineCombo.Text);
- cmd.Parameters.AddWithValue("@errorshortt", errorCombo.Text);
- }
- dr = cmd.ExecuteReader();
- workerNumber = 0;
- while (dr.HasRows)
- {
- while (dr.Read())
- {
- StartPicker.Value = dr.GetDateTime(0);
- StopPicker.Value = dr.GetDateTime(1);
- }
- dr.NextResult();
- }
- dr.Close();
- }
- catch (Exception ex)
- {
- MessageBox.Show("Hiba a lekérdezés közben: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
- }
- cnn.Close();
- }
- }
- private void pictureBox2_Click(object sender, EventArgs e)
- {
- }
- private void numberCombo_Enter(object sender, EventArgs e)
- {
- //pictureBox2.Visible = false;
- }
- private void numberCombo_Leave(object sender, EventArgs e)
- {
- //pictureBox2.Visible = true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement