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

228 lines
10 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;
namespace Mip
{
public partial class frmZadatZmatkovitost : Form
{
Int32 intIDDopyt = 0;
Int32 intPocetZmatkov = 0;
public frmZadatZmatkovitost(Int32 _iddopyt)
{
intIDDopyt = _iddopyt;
InitializeComponent();
}
private void frmZadatZmatkovitost_Shown(object sender, EventArgs e)
{
DataTable tabHladany = new DataTable();
classSQL.SQL("SELECT * FROM `pohladzmatkovitost` WHERE `IDCPOBJ`=" + intIDDopyt.ToString() + ";", 0, 0, out tabHladany);
intPocetZmatkov = Convert.ToInt32(tabHladany.Rows[0].ItemArray[tabHladany.Columns["PocetZmatkov"].Ordinal].ToString());
label1.Text = tabHladany.Rows[0].ItemArray[tabHladany.Columns["Zákazkové číslo"].Ordinal].ToString();
label15.Text = "Chybný záznam";
label4.Text = "0/" + intPocetZmatkov;
label11.Text = tabHladany.Rows[0].ItemArray[tabHladany.Columns["Zákazník"].Ordinal].ToString();
label12.Text = tabHladany.Rows[0].ItemArray[tabHladany.Columns["Názov výrobku"].Ordinal].ToString();
string matumat = "";
if (tabHladany.Rows[0].ItemArray[tabHladany.Columns["Úprava materiálu"].Ordinal].ToString() == "") matumat = tabHladany.Rows[0].ItemArray[tabHladany.Columns["Materiál"].Ordinal].ToString();
else matumat = tabHladany.Rows[0].ItemArray[tabHladany.Columns["Materiál"].Ordinal].ToString() + " - " + tabHladany.Rows[0].ItemArray[tabHladany.Columns["Úprava materiálu"].Ordinal].ToString();
label14.Text = matumat;
textBox1.Text = tabHladany.Rows[0].ItemArray[tabHladany.Columns["Rezanie"].Ordinal].ToString();
textBox2.Text = tabHladany.Rows[0].ItemArray[tabHladany.Columns["Klasika"].Ordinal].ToString();
textBox3.Text = tabHladany.Rows[0].ItemArray[tabHladany.Columns["Impregnacia"].Ordinal].ToString();
textBox4.Text = tabHladany.Rows[0].ItemArray[tabHladany.Columns["CNC"].Ordinal].ToString();
textBox5.Text = tabHladany.Rows[0].ItemArray[tabHladany.Columns["KontrolaLapovanie"].Ordinal].ToString();
textBox6.Text = tabHladany.Rows[0].ItemArray[tabHladany.Columns["ChybyMaterialu"].Ordinal].ToString();
StatusZmatkovitosti();
}
private void button1_Click(object sender, EventArgs e)
{
this.Close();
}
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == Convert.ToChar(Keys.Enter)) textBox2.Focus();
int intResult;
if (!(int.TryParse(textBox1.Text + e.KeyChar, out intResult)) && (int)e.KeyChar != 8) e.KeyChar = '\0';
}
private void textBox2_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == Convert.ToChar(Keys.Enter)) textBox3.Focus();
int intResult;
if (!(int.TryParse(textBox2.Text + e.KeyChar, out intResult)) && (int)e.KeyChar != 8) e.KeyChar = '\0';
}
private void textBox3_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == Convert.ToChar(Keys.Enter)) textBox4.Focus();
int intResult;
if (!(int.TryParse(textBox3.Text + e.KeyChar, out intResult)) && (int)e.KeyChar != 8) e.KeyChar = '\0';
}
private void textBox4_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == Convert.ToChar(Keys.Enter)) textBox5.Focus();
int intResult;
if (!(int.TryParse(textBox4.Text + e.KeyChar, out intResult)) && (int)e.KeyChar != 8) e.KeyChar = '\0';
}
private void textBox5_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == Convert.ToChar(Keys.Enter)) textBox6.Focus();
int intResult;
if (!(int.TryParse(textBox5.Text + e.KeyChar, out intResult)) && (int)e.KeyChar != 8) e.KeyChar = '\0';
}
private void textBox6_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == Convert.ToChar(Keys.Enter)) textBox1.Focus();
int intResult;
if (!(int.TryParse(textBox6.Text + e.KeyChar, out intResult)) && (int)e.KeyChar != 8) e.KeyChar = '\0';
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
StatusZmatkovitosti();
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
StatusZmatkovitosti();
}
private void textBox3_TextChanged(object sender, EventArgs e)
{
StatusZmatkovitosti();
}
private void textBox4_TextChanged(object sender, EventArgs e)
{
StatusZmatkovitosti();
}
private void textBox5_TextChanged(object sender, EventArgs e)
{
StatusZmatkovitosti();
}
private void textBox6_TextChanged(object sender, EventArgs e)
{
StatusZmatkovitosti();
}
private void StatusZmatkovitosti()
{
int intSucet = 0;
int intMedziSucet = 0;
if (textBox1.Text != "") intMedziSucet = Convert.ToInt32(textBox1.Text);
else intMedziSucet = 0;
intSucet = intSucet + intMedziSucet;
if (textBox2.Text != "") intMedziSucet = Convert.ToInt32(textBox2.Text);
else intMedziSucet = 0;
intSucet = intSucet + intMedziSucet;
if (textBox3.Text != "") intMedziSucet = Convert.ToInt32(textBox3.Text);
else intMedziSucet = 0;
intSucet = intSucet + intMedziSucet;
if (textBox4.Text != "") intMedziSucet = Convert.ToInt32(textBox4.Text);
else intMedziSucet = 0;
intSucet = intSucet + intMedziSucet;
if (textBox5.Text != "") intMedziSucet = Convert.ToInt32(textBox5.Text);
else intMedziSucet = 0;
intSucet = intSucet + intMedziSucet;
if (textBox6.Text != "") intMedziSucet = Convert.ToInt32(textBox6.Text);
else intMedziSucet = 0;
intSucet = intSucet + intMedziSucet;
label4.Text = intSucet.ToString() + "/" + intPocetZmatkov.ToString();
if (intSucet == intPocetZmatkov) ZaznamOK();
else ZaznamChybny();
}
private void ZaznamOK()
{
label15.Text = "Údaje vyplnené";
label1.BackColor = Color.LightGreen;
label15.BackColor = Color.LightGreen;
label4.BackColor = Color.LightGreen;
button2.Enabled = true;
}
private void ZaznamChybny()
{
label15.Text = "Chybný záznam";
label1.BackColor = Color.AntiqueWhite;
label15.BackColor = Color.AntiqueWhite;
label4.BackColor = Color.AntiqueWhite;
button2.Enabled = false;
}
private void button2_Click(object sender, EventArgs e)
{
string strNajdiZaznam;
classSQL.SQL("SELECT `IDZmatky` FROM `tabzmatkovitost` WHERE `IDDopyt` = " + intIDDopyt.ToString() + ";", out strNajdiZaznam);
Int32 intKlasika = 0;
Int32 intImpregnacia = 0;
Int32 intRezanie = 0;
Int32 intCNC = 0;
Int32 intKontrolaLapovanie = 0;
Int32 intChybyMaterialu = 0;
if (textBox2.Text != "") intKlasika = Convert.ToInt32(textBox2.Text);
if (textBox3.Text != "") intImpregnacia = Convert.ToInt32(textBox3.Text);
if (textBox1.Text != "") intRezanie = Convert.ToInt32(textBox1.Text);
if (textBox4.Text != "") intCNC = Convert.ToInt32(textBox4.Text);
if (textBox5.Text != "") intKontrolaLapovanie = Convert.ToInt32(textBox5.Text);
if (textBox6.Text != "") intChybyMaterialu = Convert.ToInt32(textBox6.Text);
if (strNajdiZaznam == "")
{
string cmd = @"INSERT INTO `mip`.`tabzmatkovitost` (`DatumZaznamu`, `StatusZaznamu`, `IDDopyt`, `Klasika`, `Impregnacia`, `Rezanie`, `CNC`, `KontrolaLapovanie`, `ChybyMaterialu`) VALUES ("
+ "DATE(NOW()), '"
+ label15.Text + "', "
+ intIDDopyt.ToString() + ", "
+ intKlasika.ToString() + ", "
+ intImpregnacia.ToString() + ", "
+ intRezanie.ToString() + ", "
+ intCNC.ToString() + ", "
+ intKontrolaLapovanie.ToString() + ", "
+ intChybyMaterialu.ToString() + ");";
Int32 ff;
classSQL.SQL(cmd,out ff);
MessageBox.Show(ff.ToString());
}
else
{
string cmd = @"UPDATE `mip`.`tabzmatkovitost` SET `DatumZaznamu` = DATE(NOW()), `StatusZaznamu` = '" + label15.Text + "'," +
"`IDDopyt` = " + intIDDopyt.ToString() + ", " +
"`Klasika` = " + intKlasika.ToString() + ", " +
"`Impregnacia` = " + intImpregnacia.ToString() + ", " +
"`Rezanie` = " + intRezanie.ToString() + ", " +
"`CNC` = " + intCNC.ToString() + ", " +
"`KontrolaLapovanie` = " + intKontrolaLapovanie.ToString() + ", " +
"`ChybyMaterialu` = " + intChybyMaterialu.ToString() +
" WHERE `IDZmatky`= " + strNajdiZaznam + ";";
classSQL.SQL(cmd);
}
this.Close();
}
}
}