/* * public void ChangeColor(string color) * { * if (InvokeRequired) * { * this.Invoke(new Action<string>(ChangeColor), new object[] { color }); * return; * } * * if (color.Equals("Green")) * this.button4.BackColor = Color.Green; * else * this.button4.BackColor = Color.Red; * } */ private void fillCmp(long code) { try { MainCmp mpc = new MainCmp(); mpc.GetMainCmpByName(Properties.Settings.Default.CmpName); cmpR.Clear(); cmpR = mpc.MainCmpToCompany(); cmpS.Clear(); cmpS.GetCompanyInfoByID(code); } catch (Exception e1) { new LogWriter(e1); } }
private void button2_Click(object sender, EventArgs e) { ///////////////// LogMe //////////////////////// String function = this.GetType().FullName + " - " + System.Reflection.MethodBase.GetCurrentMethod().Name; String usedQC = "Save to db"; String data = ""; String Result = ""; LogWriter lw = new LogWriter(); //////////////////////////////////////////////// /// Dictionary <String, int> groupArr = new Dictionary <string, int>(); int ind; ind = comboBox5.FindStringExact(comboBox5.Text); if (ind < 0) { comboBox5.ResetText(); } OTPNumber = ""; if (this.label2.Text.Equals("Name")) { Result = "Please select company, nothing done."; lw.LogMe(function, usedQC, data, Result); MessageBox.Show(Result); textBox1.SelectAll(); textBox1.Focus(); } else if (this.listView1.Items.Count == 0) { Result = "There is no items in list, nothing done."; lw.LogMe(function, usedQC, data, Result); MessageBox.Show(Result); textBox1.SelectAll(); textBox1.Focus(); } else { MainCmp mpc = new MainCmp(); mpc.GetMainCmpByName(Properties.Settings.Default.CmpName); cmpS.Clear(); cmpS = mpc.MainCmpToCompany(); if (cmpR.GetCompanyByName(label2.Text.Trim())) { try { List <String> arr = new List <string>(); ConnectionHelper cn = new ConnectionHelper(); using (SqlConnection cnnPR = cn.Connect(WorkingUser.Username, WorkingUser.Password)) { QueryCommands qc = new QueryCommands(); if (cn.TestConnection(cnnPR)) { //Provjera da li brojcano odgovaraju dijelovi String testStr; groupArr.Add(listView1.Items[0].SubItems[2].Text + "_" + listView1.Items[0].SubItems[3].Text + "_" + listView1.Items[0].SubItems[4].Text + "_" + listView1.Items[0].SubItems[5].Text + "_" + WorkingUser.RegionID.ToString(), 1); for (int i = 1; i < listView1.Items.Count; i++) { testStr = listView1.Items[i].SubItems[2].Text + "_" + listView1.Items[i].SubItems[3].Text + "_" + listView1.Items[i].SubItems[4].Text + "_" + listView1.Items[i].SubItems[5].Text + "_" + WorkingUser.RegionID.ToString(); if (groupArr.ContainsKey(testStr)) { groupArr[testStr] = groupArr[testStr] + 1; } else { groupArr.Add(testStr, 1); } } for (int i = 0; i < groupArr.Count(); i++) { var testArr = groupArr.ElementAt(i).Key.Split('_'); int prtConut = qc.GetPartCountByCodeSNCNStateStorage(WorkingUser.Username, WorkingUser.Password, long.Parse(testArr[0]), testArr[1], testArr[2], testArr[3], long.Parse(testArr[4])); if (groupArr[groupArr.ElementAt(i).Key] > prtConut) { data = testArr[0] + ", " + testArr[1] + ", " + testArr[2] + ", " + testArr[3] + ", " + prtConut + ", " + groupArr[groupArr.ElementAt(i).Key]; Result = "You do not have enough patrs in you storage:" + "\n\n Code: " + testArr[0] + "\n SN: " + testArr[1] + "\n CN: " + testArr[2] + "\n State: " + testArr[3] + "\n\nYou have: " + prtConut + "\nYou want: " + groupArr[groupArr.ElementAt(i).Key] + "\n\nNothing Done."; lw.LogMe(function, usedQC, data, Result); MessageBox.Show(Result, "Caution", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } } //Provjera da li se dijelovi nalaze u mom skladistu for (int i = 0; i < listView1.Items.Count; i++) { if (qc.GetPartIDCompareCodeSNCNStorage(WorkingUser.Username, WorkingUser.Password, long.Parse(listView1.Items[i].SubItems[2].Text), listView1.Items[i].SubItems[3].Text, listView1.Items[i].SubItems[4].Text, WorkingUser.RegionID)[0].Equals("nok")) { data = listView1.Items[i].SubItems[2].Text + ", " + listView1.Items[i].Index + 1; Result = "There is no part in your storage with: \n\n Code: " + listView1.Items[i].SubItems[2].Text + "\n on position " + (listView1.Items[i].Index + 1) + ". \n\nNothing Done."; lw.LogMe(function, usedQC, data, Result); MessageBox.Show(Result); textBox1.SelectAll(); textBox1.Focus(); return; } } //Provjera i spremanje u bazu List <String> allRegions = new List <string>(); allRegions = qc.GetAllRegions(); int index = resultArrC.FindIndex(resultArrC => resultArrC.Name.Equals(label2.Text)); if (resultArrC[index].RegionID != WorkingUser.RegionID) { for (int i = 0; i < listView1.Items.Count; i++) // vec imam provjeru gore kod unosa ali neka ostane(tamo je po imenu) { //long test = long.Parse(listView1.Items[i].SubItems[2].Text.Substring(4)); //DecoderBB long test = Decoder.GetFullPartCodeLng(listView1.Items[i].SubItems[2].Text); if (!resultArrSearchCode.Contains(test.ToString())) { data = test.ToString() + ", " + listView1.Items[i].Index + 1; Result = "There is no part in 'Sifrarnik' with code, = " + test.ToString() + "\n" + "on position " + (listView1.Items[i].Index + 1) + " \n\nNothing Done."; lw.LogMe(function, usedQC, data, Result); MessageBox.Show(Result); textBox1.SelectAll(); textBox1.Focus(); return; } } //Provjera da li se dijelovi nalaze u mom skladistu i dohvacanje dijelova List <Part> partList = new List <Part>(); String napomenaOTP = napomenaOTPPrint = textBox4.Text; for (int i = 0; i < groupArr.Count(); i++) { PartSifrarnik tempSifPart = new PartSifrarnik(); List <Part> tempParts = new List <Part>(); Part tempPart = new Part(); tempSifPart.GetPart(Decoder.GetFullPartCodeStr(listView1.Items[i].SubItems[2].Text)); tempParts = tempPart.GetListOfParts(long.Parse(groupArr.ElementAt(i).Key.Split('_')[0]), groupArr.ElementAt(i).Key.Split('_')[1], groupArr.ElementAt(i).Key.Split('_')[2], groupArr.ElementAt(i).Key.Split('_')[3], long.Parse(groupArr.ElementAt(i).Key.Split('_')[4])); if (tempParts.Count() < groupArr[groupArr.ElementAt(i).Key]) { data = groupArr.ElementAt(i).Key.Split('_')[0] + ", " + groupArr.ElementAt(i).Key.Split('_')[1] + ", " + groupArr.ElementAt(i).Key.Split('_')[2] + ", " + groupArr.ElementAt(i).Key.Split('_')[3] + ", " + tempParts.Count + ", " + groupArr[groupArr.ElementAt(i).Key]; Result = "There is no part in your storage with:" + "" + "\n\n Code: " + groupArr.ElementAt(i).Key.Split('_')[0] + "\n SN: " + groupArr.ElementAt(i).Key.Split('_')[1] + "\n CN: " + groupArr.ElementAt(i).Key.Split('_')[2] + "\n State: " + groupArr.ElementAt(i).Key.Split('_')[3] + "\n\nYou have: " + tempParts.Count + "\nYou want: " + groupArr[groupArr.ElementAt(i).Key] + "\n\nNothing Done."; lw.LogMe(function, usedQC, data, Result); MessageBox.Show(Result, "Caution", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); textBox1.SelectAll(); textBox1.Focus(); return; } else { int kk = 0; foreach (Part prt in tempParts) { partList.Add(prt); kk++; if (kk == groupArr[groupArr.ElementAt(i).Key]) { break; } } } } //SPREMANJE U BAZU if (resultArrC[index].RegionID != Properties.Settings.Default.OstaliIDRegion && resultArrC[index].RegionID != Properties.Settings.Default.TransportIDRegion && resultArrC[index].RegionID != Properties.Settings.Default.ServisIDRegion) { OTPNumber = qc.OTPUnesiUredajeDaSuPrimljeniInner(WorkingUser.Username, WorkingUser.Password, partList, cmpR, cmpS, textBox4.Text, 0); } else if (resultArrC[index].RegionID != Properties.Settings.Default.TransportIDRegion && resultArrC[index].RegionID != Properties.Settings.Default.ServisIDRegion) { OTPNumber = qc.OTPUnesiUredajeDaSuPrimljeni(WorkingUser.Username, WorkingUser.Password, partList, cmpR, cmpS, textBox4.Text, br.FilID); } else { Result = "Hm... You cant send part to service!"; lw.LogMe(function, usedQC, data, Result); MessageBox.Show(Result); textBox1.SelectAll(); textBox1.Focus(); return; } if (!OTPNumber.Equals("nok")) { PovijestLog pl = new PovijestLog(); Boolean saved = false; for (int k = 0; k < partList.Count; k++) { List <Part> tempPart = new List <Part>(); tempPart.Clear(); tempPart.Add(new Part()); tempPart.Add(partList[k]); if (pl.SaveToPovijestLog(tempPart, DateTime.Now.ToString("dd.MM.yy."), napomenaOTP, cmpR.Name, "", "", "OTP " + Properties.Settings.Default.ShareDocumentName, tempPart[1].State)) { saved = true; } else { saved = false; Properties.Settings.Default.ShareDocumentName = ""; break; } } if (Program.SaveDocumentsPDF) { saveToPDF(partList); } if (saved) { Result = "DONE, document nbr. OTP '" + OTPNumber + "'."; lw.LogMe(function, usedQC, data, Result); MessageBox.Show(Result); partListPrint.Clear(); partListPrint.AddRange(partList); isOtpremnicaSaved = true; listView1.Clear(); listView1.View = View.Details; listView1.Columns.Add("RB"); listView1.Columns.Add("Name"); listView1.Columns.Add("Code"); listView1.Columns.Add("SN"); listView1.Columns.Add("CN"); listView1.Columns.Add("Condition"); textBox4.Clear(); napomenaOTPPrint = napomenaOTP; } else { Result = "DONE, document nbr. 'OTP " + OTPNumber + "', but not saved in PL."; lw.LogMe(function, usedQC, data, Result); MessageBox.Show(Result); partListPrint.Clear(); partListPrint.AddRange(partList); isOtpremnicaSaved = true; listView1.Clear(); listView1.View = View.Details; listView1.Columns.Add("RB"); listView1.Columns.Add("Name"); listView1.Columns.Add("Code"); listView1.Columns.Add("SN"); listView1.Columns.Add("CN"); listView1.Columns.Add("Condition"); textBox4.Clear(); napomenaOTPPrint = napomenaOTP; } } } else { Result = "Hm... Same receiving and sending company?!"; lw.LogMe(function, usedQC, data, Result); MessageBox.Show(Result); textBox1.SelectAll(); textBox1.Focus(); return; } } cnnPR.Close(); } } catch (Exception e1) { new LogWriter(e1); MessageBox.Show(e1.Message); textBox1.SelectAll(); textBox1.Focus(); } } this.printPrewBT.Enabled = isOtpremnicaSaved; } }
private void cISS_Load(object sender, EventArgs e) { fillSifrarnik(); mm.GetMainCmpInfoByID(Properties.Settings.Default.CmpID); cmpM = mm.MainCmpToCompany(); partList = qc.ListPartsByRegionStateP(WorkingUser.RegionID, "sng"); List <Part> goodParts = new List <Part>(); goodParts = qc.ListPartsByRegionStateP(WorkingUser.RegionID, "g"); allParts = qc.GetPartsAllSifrarnik(); listView1.View = View.Details; listView1.Columns.Add("RB"); listView1.Columns.Add("ID"); listView1.Columns.Add("Date"); listView1.Columns.Add("UserID"); listView1.Columns.Add("CustomerID"); listView1.Columns.Add("PartID"); listView1.Columns.Add("Closed"); listView1.Columns.Add("TotalTime"); listView2.View = View.Details; listView2.Columns.Add("RB"); listView2.Columns.Add("Name"); listView2.Columns.Add("CodeO"); listView2.Columns.Add("SNO"); listView2.Columns.Add("CNO"); listView2.Columns.Add("CodeN"); listView2.Columns.Add("SNN"); listView2.Columns.Add("CNN"); listView2.Columns.Add("Date"); listView2.Columns.Add("Time"); listView2.Columns.Add("Work done"); listView2.Columns.Add("Comment"); customerID = qc.GetAllISScustomerID(1); if (customerID[0] != -1) { for (int i = 0; i < customerID.Count(); i++) { this.comboBox2.Items.Add(customerID[i]); } } dateCreated = qc.GetAllISSdateCreated(1); if (!dateCreated[0].Equals("nok")) { for (int i = 0; i < dateCreated.Count(); i++) { this.comboBox3.Items.Add(dateCreated[i]); } } Company temCmp = new Company(); cmpList = temCmp.GetAllCompanyInfoSortByName(); if (cmpList.Count != 0) { for (int i = 0; i < temCmp.Count; i++) { this.comboBox4.Items.Add(cmpList[i].Name); } } ISSids = qc.GetAllISSOpenClose(1); for (int i = 0; i < ISSids.Count; i++) { ISSSelectorCb.Items.Add(ISSids[i]); } for (int i = 0; i < 12; i++) { listView2.AutoResizeColumn(i, ColumnHeaderAutoResizeStyle.ColumnContent); listView2.AutoResizeColumn(i, ColumnHeaderAutoResizeStyle.HeaderSize); } Program.LoadStop(); this.Focus(); }
private void FindPart() { if (this.textBox1.TextLength > 12) { try { Program.LoadStart(); QueryCommands qc = new QueryCommands(); QueryCommands qc1 = new QueryCommands(); QueryCommands qc2 = new QueryCommands(); List <String> sendArr = new List <string>(); List <String> resultArr = new List <string>(); List <String> resultArr1 = new List <string>(); List <String> resultArr2 = new List <string>(); List <String> resultArr3 = new List <string>(); List <String> resultArrG = new List <string>(); List <String> resultArrNG = new List <string>(); ConnectionHelper cn = new ConnectionHelper(); for (int i = 1; i <= regionCnt; i++) { Control ctn1 = this.Controls["lblAdd_" + i]; Control ctn2 = this.Controls["txtBoxAddNG_" + i]; Control ctn3 = this.Controls["txtBoxAddG_" + i]; this.Controls.Remove(ctn1); this.Controls.Remove(ctn2); this.Controls.Remove(ctn3); } positionX = 20; //positionY = 100; positionPlusY = 0; resultArr3 = qc.GetAllRegions(); PartSifrarnik prt = new PartSifrarnik(); this.label7.Text = prt.PartCode.ToString(); Company cmpO = new Company(); Company cmpC = new Company(); Boolean cmpOb = false; Boolean cmpCb = false; if (Decoder.GetOwnerCode(textBox1.Text).Equals("01")) { MainCmp mpc = new MainCmp(); mpc.GetMainCmpByName(Properties.Settings.Default.CmpName); cmpO = mpc.MainCmpToCompany(); cmpOb = true; } else { cmpOb = cmpO.GetCompanyInfoByCode(Decoder.GetOwnerCode(textBox1.Text)); } if (Decoder.GetOwnerCode(textBox1.Text).Equals("01")) { MainCmp mpc = new MainCmp(); mpc.GetMainCmpByName(Properties.Settings.Default.CmpName); cmpC = mpc.MainCmpToCompany(); cmpCb = true; } else { cmpCb = cmpC.GetCompanyInfoByCode(Decoder.GetCustomerCode(textBox1.Text)); } //if (prt.GetPart(textBox1.Text.Substring(4, 9)) && cmpO.GetCompanyInfoByCode(textBox1.Text.Substring(0, 2)) && cmpC.GetCompanyInfoByCode(textBox1.Text.Substring(2, 2))) //DecoderBB if (prt.GetPart(Decoder.GetFullPartCodeStr(textBox1.Text)) && cmpOb && cmpCb) { this.textBox2.ResetText(); this.textBox2.Text = prt.FullName; ////this.label18.Text = string.Format("{0:0000 000 000 000}", long.Parse(this.textBox1.Text)); this.label18.Text = this.textBox1.Text; this.label7.Text = cmpO.Name; this.label8.Text = cmpC.Name; this.label9.Text = cmpO.Code; this.label10.Text = cmpC.Code; this.label11.Text = prt.CategoryName; this.label12.Text = prt.PartName; this.label13.Text = string.Format("{0:000}", (prt.CategoryCode / 1000000)); this.label14.Text = string.Format("{0:000}", (prt.PartCode / 1000)); this.label15.Text = prt.SubPartName; this.label16.Text = string.Format("{0:000}", prt.SubPartCode); this.label21.Text = string.Format("{0:C}", prt.PriceInKn); this.label22.Text = string.Format("{0:C}", prt.PriceOutKn); var culture = new CultureInfo("de-DE"); this.label25.Text = string.Format(culture, "{0:C}", prt.PriceInEur); this.label26.Text = string.Format(culture, "{0:C}", prt.PriceOutEur); this.label29.Text = prt.PartNumber; sendArr.Clear(); resultArr = qc.InTransport(WorkingUser.Username, WorkingUser.Password, long.Parse(label18.Text.Trim())); this.label30.Text = resultArr[0] == "nok" ? "0" : resultArr[0]; this.label32.Text = prt.Packing; this.textBox3.Text = "*" + this.label18.Text + "*"; regionCnt = (resultArr3.Count() / 3); int j = 1; int jj = 0; for (int i = 1; i <= regionCnt; i++) { if (!resultArr3[j].Equals("O")) { Label lblAdd = new Label(); this.Controls.Add(lblAdd); lblAdd.Size = new Size(50, 20); positionY = this.panel21.Bounds.Bottom + 40 + positionPlusY;// + (40 * i); lblAdd.Location = new Point(positionX, positionY); lblAdd.Font = new Font(lblAdd.Font, FontStyle.Bold); lblAdd.Name = "lblAdd_" + i; lblAdd.Text = resultArr3[j] + " - " + resultArr3[j - 1]; TextBox txtBoxAddG = new TextBox(); this.Controls.Add(txtBoxAddG); txtBoxAddG.Size = new Size(60, 60); positionY = this.panel21.Bounds.Bottom + 60 + positionPlusY;// + (40 * i); txtBoxAddG.Location = new Point(positionX, positionY); txtBoxAddG.BackColor = Color.LightGreen; txtBoxAddG.TextAlign = HorizontalAlignment.Center; txtBoxAddG.ReadOnly = true; resultArrG.Clear(); sendArr.Clear(); if (resultArr3[jj + 1].Equals("S")) { resultArrG = qc.PartsCntGS(WorkingUser.Username, WorkingUser.Password, long.Parse(label18.Text.Trim())); } else { resultArrG = qc.PartsCntG(WorkingUser.Username, WorkingUser.Password, long.Parse(label18.Text.Trim()), long.Parse(resultArr3[jj].Trim())); } if (resultArr3[jj + 1].Equals("S")) { txtBoxAddG.Name = "txtBoxAddSG_" + i; } else { txtBoxAddG.Name = "txtBoxAddG_" + i; } txtBoxAddG.Text = resultArrG[0] == "nok" ? "" : resultArrG[0].Equals("0") ? "" : resultArrG[0]; if (!txtBoxAddG.Text.Equals("")) { totalG = totalG + int.Parse(txtBoxAddG.Text); } TextBox txtBoxAddNG = new TextBox(); this.Controls.Add(txtBoxAddNG); txtBoxAddNG.Size = new Size(60, 60); positionX = txtBoxAddG.Bounds.Right + 10; txtBoxAddNG.Location = new Point(positionX, positionY); txtBoxAddNG.BackColor = Color.LightCoral; txtBoxAddNG.TextAlign = HorizontalAlignment.Center; txtBoxAddNG.ReadOnly = true; resultArrNG.Clear(); sendArr.Clear(); if (resultArr3[jj + 1].Equals("S")) { resultArrNG = qc.PartsCntNGS(WorkingUser.Username, WorkingUser.Password, long.Parse(label18.Text.Trim())); } else { resultArrNG = qc.PartsCntNG(WorkingUser.Username, WorkingUser.Password, long.Parse(label18.Text.Trim()), long.Parse(resultArr3[jj].Trim())); } if (resultArr3[jj + 1].Equals("S")) { txtBoxAddNG.Name = "txtBoxAddSNG_" + i; } else { txtBoxAddNG.Name = "txtBoxAddNG_" + i; } txtBoxAddNG.Text = resultArrNG[0] == "nok" ? "" : resultArrNG[0].Equals("0") ? "" : resultArrNG[0]; if (!txtBoxAddNG.Text.Equals("")) { totalNG = totalNG + int.Parse(txtBoxAddNG.Text); } txtBoxAddNG.Click += new EventHandler(showList); txtBoxAddG.Click += new EventHandler(showList); positionX = positionX + 80; if ((positionX + 150) >= ClientRectangle.Width) { positionPlusY = positionPlusY + 50; positionX = 20; } } j = j + 3; jj = jj + 3; } textBox4.Text = totalG.ToString(); textBox5.Text = totalNG.ToString(); } else { clearME(); } } catch (Exception e1) { new LogWriter(e1); MessageBox.Show(e1.Message); clearME(); return; } finally { Program.LoadStop(); this.Focus(); } } }
private void button2_Click(object sender, EventArgs e) { ///////////////// LogMe //////////////////////// String function = this.GetType().FullName + " - " + System.Reflection.MethodBase.GetCurrentMethod().Name; String usedQC = "Save to db"; String data = ""; String Result = ""; LogWriter lw = new LogWriter(); //////////////////////////////////////////////// /// IUSNumber = ""; if (this.label2.Text.Equals("Name")) { Result = "Please select company, nothing done."; lw.LogMe(function, usedQC, data, Result); MessageBox.Show(Result); textBox1.SelectAll(); isFocused = true; textBox1.Focus(); isFocused = false; } else if (this.listView1.Items.Count == 0) { Result = "There is no items in list, nothing done."; lw.LogMe(function, usedQC, data, Result); MessageBox.Show(Result); textBox1.SelectAll(); isFocused = true; textBox1.Focus(); isFocused = false; } else { //List<Part> listOfOtpPartsPrimka = new List<Part>(); MainCmp mpc = new MainCmp(); mpc.GetMainCmpByName(Properties.Settings.Default.CmpName); cmpR.Clear(); cmpR = mpc.MainCmpToCompany(); if (cmpS.GetCompanyByName(label2.Text.Trim())) { try { List <String> arr = new List <string>(); ConnectionHelper cn = new ConnectionHelper(); using (SqlConnection cnnIUS = cn.Connect(WorkingUser.Username, WorkingUser.Password)) { if (cn.TestConnection(cnnIUS)) { //Provjera da li se dijelovi nalaze u mom skladistu QueryCommands qc = new QueryCommands(); for (int i = 0; i < listView1.Items.Count; i++) // vec imam provjeru gore kod unosa ali neka ostane(tamo je po imenu) { if (qc.GetPartIDCompareCodeSNCNStorageState(WorkingUser.Username, WorkingUser.Password, long.Parse(listView1.Items[i].SubItems[2].Text), listView1.Items[i].SubItems[3].Text, listView1.Items[i].SubItems[4].Text, WorkingUser.RegionID, "ng")[0].Equals("nok")) { data = listView1.Items[i].SubItems[2].Text + "\n on position " + (listView1.Items[i].Index + 1); Result = "In your storage does not exist NG part with: \n\n Code: " + listView1.Items[i].SubItems[2].Text + "\n on position " + (listView1.Items[i].Index + 1) + "\n\nNothing Done."; lw.LogMe(function, usedQC, data, Result); MessageBox.Show(Result); textBox1.SelectAll(); isFocused = true; textBox1.Focus(); isFocused = false; return; } } //Provjera i spremanje u bazu List <String> allRegions = new List <string>(); allRegions = qc.GetAllRegions(); int index = resultArrC.FindIndex(resultArrC => resultArrC.Name.Equals(label2.Text)); List <Part> partList = new List <Part>(); String napomenaIUS = textBox4.Text; for (int i = 0; i < listView1.Items.Count; i++) { PartSifrarnik tempSifPart = new PartSifrarnik(); Part tempPart = new Part(); foreach (Part part in partsArr) { tempSifPart.GetPart(Decoder.GetFullPartCodeStr(listView1.Items[i].SubItems[2].Text)); if (part.PartialCode == tempSifPart.FullCode && part.SN.ToUpper().Equals(listView1.Items[i].SubItems[3].Text.ToUpper()) && part.CN.ToUpper().Equals(listView1.Items[i].SubItems[4].Text.ToUpper()) && !partList.Contains(part)) { tempPart = part; tempPart.StorageID = WorkingUser.RegionID; tempPart.State = "sng"; tempPart.CompanyO = Decoder.GetOwnerCode(listView1.Items[i].SubItems[2].Text); tempPart.CompanyC = Decoder.GetCustomerCode(listView1.Items[i].SubItems[2].Text); break; } } String tmpResult = qc.GetListPartsByPartIDFromParts(tempPart.PartID)[0]; if (tmpResult.Equals("nok")) { data = listView1.Items[i].SubItems[2].Text + "\n on position " + (listView1.Items[i].Index + 1); Result = "There is no NG part in your storage with: \n\n Code: " + listView1.Items[i].SubItems[2].Text + "\n on position " + (listView1.Items[i].Index + 1) + ". \n\nNothing Done."; lw.LogMe(function, usedQC, data, Result); MessageBox.Show(Result); textBox1.SelectAll(); isFocused = true; textBox1.Focus(); isFocused = false; return; } else { tempPart.PartID = long.Parse(tmpResult); partList.Add(tempPart); } } IUSNumber = qc.IUSPrebaciUServis(WorkingUser.Username, WorkingUser.Password, partList, WorkingUser.RegionID, cmpS.ID, napomenaIUS); if (!IUSNumber.Equals("nok")) { partsArr = partsArr.Except(partList).ToList(); PovijestLog pl = new PovijestLog(); if (Program.SaveDocumentsPDF) { saveToPDF(partList); } if (pl.SaveToPovijestLog(partList, DateTime.Now.ToString("dd.MM.yy."), napomenaIUS, cmpS.Name, "", "", "IUS " + Properties.Settings.Default.ShareDocumentName, "sng")) { Properties.Settings.Default.ShareDocumentName = ""; Result = "DONE, document nbr. IUS '" + IUSNumber + "'."; lw.LogMe(function, usedQC, data, Result); MessageBox.Show(Result); partListPrint.Clear(); partListPrint.AddRange(partList); isIUSSaved = true; listView1.Clear(); listView1.View = View.Details; listView1.Columns.Add("RB"); listView1.Columns.Add("Name"); listView1.Columns.Add("Code"); listView1.Columns.Add("SN"); listView1.Columns.Add("CN"); listView1.Columns.Add("Condition"); textBox4.Clear(); napomenaIUSPrint = napomenaIUS; } else { Result = "DONE, document nbr. 'IUS " + IUSNumber + "', but not saved in PL."; lw.LogMe(function, usedQC, data, Result); MessageBox.Show(Result); partListPrint.Clear(); partListPrint.AddRange(partList); isIUSSaved = true; listView1.Clear(); listView1.View = View.Details; listView1.Columns.Add("RB"); listView1.Columns.Add("Name"); listView1.Columns.Add("Code"); listView1.Columns.Add("SN"); listView1.Columns.Add("CN"); listView1.Columns.Add("Condition"); textBox4.Clear(); napomenaIUSPrint = napomenaIUS; } } else { Result = "Unknown error in QUERY."; lw.LogMe(function, usedQC, data, Result); MessageBox.Show(Result); napomenaIUSPrint = ""; isIUSSaved = false; } //} } cnnIUS.Close(); } } catch (Exception e1) { new LogWriter(e1); MessageBox.Show(e1.Message); textBox1.SelectAll(); isFocused = true; textBox1.Focus(); isFocused = false; } } this.printPrewBT.Enabled = isIUSSaved; } }
private void button2_Click(object sender, EventArgs e) { Program.SaveStart(); ///////////////// LogMe //////////////////////// String function = this.GetType().FullName + " - " + System.Reflection.MethodBase.GetCurrentMethod().Name; String usedQC = "Save to db"; String data = ""; String Result = ""; LogWriter lw = new LogWriter(); //////////////////////////////////////////////// /// PrimkaNumber = ""; if (this.label2.Text.Equals("Name")) { Result = "Please select company, nothing done."; lw.LogMe(function, usedQC, data, Result); Program.SaveStop(); MessageBox.Show(Result); textBox1.SelectAll(); textBox1.Focus(); } else if (this.listView1.Items.Count == 0) { Result = "There is no items in list, nothing done."; lw.LogMe(function, usedQC, data, Result); Program.SaveStop(); MessageBox.Show(Result); textBox1.SelectAll(); textBox1.Focus(); } else { List <Part> listOfOtpPartsFromOTP = new List <Part>(); //List<Part> listOfOtpPartsPrimka = new List<Part>(); MainCmp mpc = new MainCmp(); mpc.GetMainCmpByName(Properties.Settings.Default.CmpName); cmpR.Clear(); cmpR = mpc.MainCmpToCompany(); if (cmpS.GetCompanyByName(label2.Text.Trim())) { try { List <String> arr = new List <string>(); SqlCommand commandPR; String queryPR; ConnectionHelper cn = new ConnectionHelper(); using (SqlConnection cnnPR = cn.Connect(WorkingUser.Username, WorkingUser.Password)) { if (cn.TestConnection(cnnPR)) { //Provjera da li se dijelovi nalaze u mom skladistu QueryCommands qc = new QueryCommands(); for (int i = 0; i < listView1.Items.Count; i++) // vec imam provjeru gore kod unosa ali neka ostane(tamo je po imenu) { if (!listView1.Items[i].SubItems[3].Text.Equals("") && !listView1.Items[i].SubItems[4].Text.Equals("")) { if (!qc.GetPartIDCompareCodeSNCNStorage(WorkingUser.Username, WorkingUser.Password, long.Parse(listView1.Items[i].SubItems[2].Text), listView1.Items[i].SubItems[3].Text, listView1.Items[i].SubItems[4].Text, WorkingUser.RegionID)[0].Equals("nok")) { data = listView1.Items[i].SubItems[2].Text + ", " + listView1.Items[i].Index + 1; Result = "In your storage, part with: \n\n Code: " + listView1.Items[i].SubItems[2].Text + "\n on position " + (listView1.Items[i].Index + 1) + "\n, already exist in DB.\n\nNothing Done."; lw.LogMe(function, usedQC, data, Result); Program.SaveStop(); MessageBox.Show(Result); textBox1.SelectAll(); textBox1.Focus(); return; } } } //Provjera i spremanje u bazu List <String> allRegions = new List <string>(); allRegions = qc.GetAllRegions(); int index = resultArrC.FindIndex(resultArrC => resultArrC.Name.Equals(label2.Text)); if (resultArrC[index].RegionID != Properties.Settings.Default.OstaliIDRegion && resultArrC[index].RegionID != Properties.Settings.Default.TransportIDRegion) { queryPR = "Select RegionIDOut from Transport where RegionIDIn = " + WorkingUser.RegionID + " and UsersUserIDIn is NULL"; commandPR = new SqlCommand(queryPR, cnnPR); commandPR.ExecuteNonQuery(); SqlDataReader dataReader = commandPR.ExecuteReader(); dataReader.Read(); if (dataReader.HasRows) { do { openedTransactionSenderRegions.Add(dataReader["RegionIDOut"].ToString()); } while (dataReader.Read()); dataReader.Close(); } else { data = resultArrC[index].RegionID + ", " + Properties.Settings.Default.OstaliIDRegion + ", " + resultArrC[index].RegionID + ", " + Properties.Settings.Default.TransportIDRegion; Result = "From selected region nothing is sent to you. \n\n Nothing Done."; lw.LogMe(function, usedQC, data, Result); Program.SaveStop(); MessageBox.Show(Result); textBox1.SelectAll(); textBox1.Focus(); return; } for (int i = 0; i < listView1.Items.Count; i++) // vec imam provjeru gore kod unosa ali neka ostane(tamo je po imenu) { //long test = long.Parse(listView1.Items[i].SubItems[2].Text.Substring(4)); //DecoderBB long test = Decoder.GetFullPartCodeLng(listView1.Items[i].SubItems[2].Text); if (!resultArrSearchCode.Contains(test.ToString())) { data = test.ToString() + ", " + listView1.Items[i].Index + 1; Result = "There is no part in 'Sifrarnik' with code, = " + test.ToString() + "\n" + "on position " + (listView1.Items[i].Index + 1) + " \n\n Nothing Done."; lw.LogMe(function, usedQC, data, Result); Program.SaveStop(); MessageBox.Show(Result); textBox1.SelectAll(); textBox1.Focus(); return; } } //Provjera da li sam odabrao dobru tvrtku koja salje Boolean exist = false; for (int j = 0; j < openedTransactionSenderRegions.Count; j++) { if (cmpS.RegionID.ToString().Equals(openedTransactionSenderRegions[j])) { exist = true; break; } } if (!exist) { data = cmpS.RegionID.ToString(); Result = "Please select right company! \n\n Nothing done."; lw.LogMe(function, usedQC, data, Result); Program.SaveStop(); MessageBox.Show(Result); textBox1.SelectAll(); textBox1.Focus(); return; } openedOTP = qc.GetAllOpenedOTP(WorkingUser.Username, WorkingUser.Password, WorkingUser.RegionID); long selectedOTP = 0; if (openedOTP[0].Equals("nok")) { data = openedOTP[0].ToString(); Result = "There is no opened documents for you!"; lw.LogMe(function, usedQC, data, Result); Program.SaveStop(); MessageBox.Show(Result); textBox1.SelectAll(); textBox1.Focus(); return; } using (Selector selector = new Selector()) { selector.SetLabelText = "Please select receiving document"; selector.SetComboBoxStringList = openedOTP; selector.ShowDialog(); if (selector.GetOTPValue > 0) { selectedOTP = selector.GetOTPValue; } else { data = selectedOTP.ToString(); Result = "Please select valid receiving document! \n\n Nothing done."; lw.LogMe(function, usedQC, data, Result); Program.SaveStop(); MessageBox.Show(Result); textBox1.SelectAll(); textBox1.Focus(); return; } } Part otpParts = new Part(); listOfOtpPartsFromOTP = otpParts.GetListOfPartsOTPParts(selectedOTP); int counterLP = listOfOtpPartsFromOTP.Count; int counterLV = listView1.Items.Count; Boolean same = false; for (int i = 0; i < counterLP; i++) { for (int ii = 0; ii < counterLV; ii++) { if (listOfOtpPartsFromOTP[i].CodePartFull == long.Parse(listView1.Items[ii].SubItems[2].Text) && listOfOtpPartsFromOTP[i].SN.ToUpper().Equals(listView1.Items[ii].SubItems[3].Text.ToUpper()) && listOfOtpPartsFromOTP[i].CN.ToUpper().Equals(listView1.Items[ii].SubItems[4].Text.ToUpper())) { same = true; break; } else { same = false; data = listOfOtpPartsFromOTP[i].CodePartFull.ToString() + ", " + long.Parse(listView1.Items[ii].SubItems[2].Text).ToString() + ", " + listOfOtpPartsFromOTP[i].SN.ToUpper().Equals(listView1.Items[ii].SubItems[3].Text.ToUpper()).ToString() + ", " + listOfOtpPartsFromOTP[i].CN.ToUpper().Equals(listView1.Items[ii].SubItems[4].Text.ToUpper()).ToString(); } } if (!same) { break; } } if (!same || counterLP != counterLV) { Result = "Receiving document and sending document items do not match ! \n\n Nothing done."; lw.LogMe(function, usedQC, data, Result); Program.SaveStop(); MessageBox.Show(Result); textBox1.SelectAll(); textBox1.Focus(); return; } PrimkaNumber = qc.PRIMUnesiUredajeDaSuPrimljeniInnner(WorkingUser.Username, WorkingUser.Password, listOfOtpPartsFromOTP, cmpS.RegionID, cmpR.RegionID, selectedOTP, textBox4.Text); if (!PrimkaNumber.Equals("nok")) { PovijestLog pl = new PovijestLog(); Boolean saved = false; for (int k = 0; k < listOfOtpPartsFromOTP.Count; k++) { List <Part> tempPart = new List <Part>(); tempPart.Clear(); tempPart.Add(listOfOtpPartsFromOTP[k]); if (pl.SaveToPovijestLog(tempPart, DateTime.Now.ToString("dd.MM.yy."), textBox4.Text, cmpS.Name, "", "", "PRIM " + Properties.Settings.Default.ShareDocumentName, tempPart[0].State)) { saved = true; Properties.Settings.Default.ShareDocumentName = ""; } else { saved = false; break; } } if (saved) { data = PrimkaNumber; Result = "DONE, document nbr. 'PRIM " + PrimkaNumber + "'."; lw.LogMe(function, usedQC, data, Result); Program.SaveStop(); MessageBox.Show(Result); isPrimkaSaved = true; listView1.Clear(); listView1.View = View.Details; partListPrint.Clear(); partListPrint.AddRange(listOfOtpPartsFromOTP); //partListPrint = listOfOtpPartsPrimka; listView1.Columns.Add("RB"); listView1.Columns.Add("Name"); listView1.Columns.Add("Code"); listView1.Columns.Add("SN"); listView1.Columns.Add("CN"); listView1.Columns.Add("Condition"); textBox4.Clear(); } else { data = PrimkaNumber; Result = "DONE, document nbr. 'PRIM " + PrimkaNumber + "', but not saved in PL."; lw.LogMe(function, usedQC, data, Result); Program.SaveStop(); MessageBox.Show(Result); listView1.Clear(); listView1.View = View.Details; partListPrint.Clear(); partListPrint.AddRange(listOfOtpPartsFromOTP); //partListPrint = listOfOtpPartsPrimka; listView1.Columns.Add("RB"); listView1.Columns.Add("Name"); listView1.Columns.Add("Code"); listView1.Columns.Add("SN"); listView1.Columns.Add("CN"); listView1.Columns.Add("Condition"); textBox4.Clear(); } } else { Result = "Unknown error in QUERYinner."; lw.LogMe(function, usedQC, data, Result); Program.SaveStop(); MessageBox.Show(Result); isPrimkaSaved = false; } } else if (resultArrC[index].RegionID == Properties.Settings.Default.OstaliIDRegion) { List <Part> partList = new List <Part>(); String napomenaPRIM = napomenaPRIMPrint = textBox4.Text; for (int i = 0; i < listView1.Items.Count; i++) { PartSifrarnik tempSifPart = new PartSifrarnik(); Part tempPart = new Part(); //tempSifPart.GetPart(listView1.Items[i].SubItems[2].Text.Substring(4)); //DecoderBB tempSifPart.GetPart(Decoder.GetFullPartCodeStr(listView1.Items[i].SubItems[2].Text)); tempPart.PartialCode = tempSifPart.FullCode; tempPart.SN = listView1.Items[i].SubItems[3].Text; tempPart.CN = listView1.Items[i].SubItems[4].Text; tempPart.DateIn = DateTime.Now.ToString("dd.MM.yy."); tempPart.StorageID = WorkingUser.RegionID; tempPart.State = listView1.Items[i].SubItems[5].Text; //tempPart.CompanyO = listView1.Items[i].SubItems[2].Text.Substring(0, 2); //DecoderBB tempPart.CompanyO = Decoder.GetOwnerCode(listView1.Items[i].SubItems[2].Text); //tempPart.CompanyC = listView1.Items[i].SubItems[2].Text.Substring(2, 2); //DecoderBB tempPart.CompanyC = Decoder.GetCustomerCode(listView1.Items[i].SubItems[2].Text); partList.Add(tempPart); } PrimkaNumber = qc.PRIMUnesiUredajeDaSuPrimljeni(WorkingUser.Username, WorkingUser.Password, partList, WorkingUser.RegionID, cmpS.ID, napomenaPRIM); if (!PrimkaNumber.Equals("nok")) { PovijestLog pl = new PovijestLog(); Boolean saved = false; for (int k = 0; k < partList.Count; k++) { List <Part> tempPart = new List <Part>(); tempPart.Clear(); tempPart.Add(partList[k]); if (pl.SaveToPovijestLog(tempPart, DateTime.Now.ToString("dd.MM.yy."), napomenaPRIM, cmpS.Name, "", "", "PRIM " + Properties.Settings.Default.ShareDocumentName, tempPart[0].State)) { saved = true; } else { saved = false; Properties.Settings.Default.ShareDocumentName = ""; break; } } if (Program.SaveDocumentsPDF) { saveToPDF(partList); } if (saved) { data = PrimkaNumber; Result = "DONE, document nbr. 'PRIM " + PrimkaNumber + "'."; lw.LogMe(function, usedQC, data, Result); Program.SaveStop(); MessageBox.Show(Result); partListPrint.Clear(); partListPrint.AddRange(partList); isPrimkaSaved = true; listView1.Clear(); listView1.View = View.Details; listView1.Columns.Add("RB"); listView1.Columns.Add("Name"); listView1.Columns.Add("Code"); listView1.Columns.Add("SN"); listView1.Columns.Add("CN"); listView1.Columns.Add("Condition"); textBox4.Clear(); napomenaPRIMPrint = napomenaPRIM; } else { data = PrimkaNumber; Result = "DONE, document nbr. 'PRIM " + PrimkaNumber + "', but not saved in PL."; lw.LogMe(function, usedQC, data, Result); Program.SaveStop(); MessageBox.Show(Result); partListPrint.Clear(); partListPrint.AddRange(partList); isPrimkaSaved = true; listView1.Clear(); listView1.View = View.Details; listView1.Columns.Add("RB"); listView1.Columns.Add("Name"); listView1.Columns.Add("Code"); listView1.Columns.Add("SN"); listView1.Columns.Add("CN"); listView1.Columns.Add("Condition"); textBox4.Clear(); napomenaPRIMPrint = napomenaPRIM; } } else { Result = "Unknown error in QUERYinner."; lw.LogMe(function, usedQC, data, Result); Program.SaveStop(); MessageBox.Show(Result); napomenaPRIMPrint = ""; isPrimkaSaved = false; } } } cnnPR.Close(); } } catch (Exception e1) { Program.SaveStop(); new LogWriter(e1); MessageBox.Show(e1.Message); textBox1.SelectAll(); textBox1.Focus(); } } this.printPrewBT.Enabled = isPrimkaSaved; this.selectPrinterPrintBtn.Enabled = isPrimkaSaved; } Program.SaveStop(); }