//------------------------------------------------------------------------- private void InitLinsForm(bool BarCodeControlsBuilding) { Application.DoEvents(); int qn = 0; try { RecognizeAllButton.Enabled = true; CreateEtalonAreas(); if (BarCodeControlsBuilding)// && (rec.areas == null || rec.areas.Length == 0)) { rec.areas = (RegionsArea[])etalonAreas.Clone(); } if (linsForm != null && appSettings.Fields.LinsTrackBar1Value != 0) linsForm.trackBar1.Value = appSettings.Fields.LinsTrackBar1Value; UpdateZoomedImage(0, 0); //regions = recTools.GetRegions(rec.SheetIdentifier, rec.regionsList); int amout_of_questions = -1; if (rec.regions == null) { if (appSettings.Fields.ChbSheetId && !string.IsNullOrEmpty(lastSheetId)) { rec.regions = recTools.GetRegions(lastSheetId, rec.regionsList); } } for (int i = 0; i < rec.regions.regions.Length; i++) { var item = rec.regions.regions[i]; if (item.value == rec.SheetIdentifier) continue; if (item.type.StartsWith("bar")) { if (item.name == "sheetIdentifier") continue; int j = Array.IndexOf(rec.allBarCodeNames, item.name); if (j >= 0) { BarCodeListItemControl b = barCodeList.ControlList[j] as BarCodeListItemControl; switch (item.name) { case "district_id": if (string.IsNullOrEmpty(b.comboBox1.Text))//item.value == null { if (appSettings.Fields.DistrictId && lastDistrictId != "") { rec.allBarCodeValues[j] = lastDistrictId; b.comboBox1.Text = lastDistrictId; item.value = lastDistrictId; b.comboBox1.ForeColor = Color.Red; } } break; case "amout_of_questions": if (rec != null && rec.SheetIdentifier == "FLEX") { BarCodeListItemControl b2 = barCodeList.ControlList["bubbles_per_line"] as BarCodeListItemControl; if (string.IsNullOrEmpty(b2.comboBox1.Text) || !utils.IsNumeric(b2.comboBox1.Text)) { b.comboBox1.Text = ""; MessageBox.Show("You must specify bubbles_per_line." , Text, MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } rep: for (int k = 0; k < BarCodeItems.Count; k++) { var itm = BarCodeItems[k]; //} //foreach (var item in BarCodeItems)//barCodeList.ControlList //{ if (itm.Name.StartsWith("question_number")) { qn++; if (qn > rec.AmoutOfQuestions) { BarCodeItems.Remove(itm); barCodeList.ControlList.Remove(barCodeList.ControlList[k]); rec.BarCodeItems.RemoveAt(k); goto rep; } } } Array.Resize(ref rec.allBarCodeNames, BarCodeItems.Count); Array.Resize(ref rec.allBarCodeValues, BarCodeItems.Count); Array.Resize(ref rec.questionNumbers, rec.AmoutOfQuestions); BarCodeControlsBuilding = true; } amout_of_questionsIndex = j; string s = rec.allBarCodeValues[j]; if (!string.IsNullOrEmpty(s)) { s = b.comboBox1.Text; rec.allBarCodeValues[j] = s; } try { j = Convert.ToInt32(s); amout_of_questions = j; amoutOfQuestions = j.ToString(); SetRowsValue(amout_of_questions); if (rec.allBarCodeValues[amout_of_questionsIndex] != s) { rec.allBarCodeValues[amout_of_questionsIndex] = s; SetAmoutOfQuestions(amout_of_questions); } } catch (Exception) { if (appSettings.Fields.AmoutOfQuestions && lastAmoutOfQuestions != "") { b.comboBox1.Text = lastAmoutOfQuestions; b.comboBox1.ForeColor = Color.Red; } else amout_of_questions = -1; } break; } continue; } if (rec.QrCodeHeaders != null && rec.QrCodeHeaders.Length > 0 && rec.defaults.useStudentId) continue; if (item.areas != null && item.areas[0].width == 0) continue; string value = ""; bool verify = false; if (item.name.StartsWith("question_number")) { string number = item.name; number = number.Remove(0, number.LastIndexOf("_") + 1); int index = Convert.ToInt32(number); if (amout_of_questions > -1 && index > amout_of_questions) continue; if (rec.questionNumbers.Length < index) { Array.Resize(ref rec.questionNumbers, index); } index--; } switch (item.name) { case "district_id": if (rec.QrCodeHeaders != null && rec.QrCodeHeaders.Length > 0) { int index = Array.IndexOf(rec.QrCodeHeaders, "{" + item.name + "}"); if (index > -1) { value = rec.QrCodeValues[index]; districtId = value; verify = true; } } else if (appSettings.Fields.DistrictId && !string.IsNullOrEmpty(lastDistrictId)) value = lastDistrictId; break; case "test_id": if (rec.QrCodeHeaders != null && rec.QrCodeHeaders.Length > 0) { int index = Array.IndexOf(rec.QrCodeHeaders, "{" + item.name + "}"); if (index > -1) { value = rec.QrCodeValues[index]; testId = value; verify = true; } } else if (appSettings.Fields.TestId && !string.IsNullOrEmpty(lastTestId)) { value = lastTestId; testId = lastTestId; } break; case "amout_of_questions": if (rec.QrCodeHeaders != null && rec.QrCodeHeaders.Length > 0) { int index = Array.IndexOf(rec.QrCodeHeaders, "{" + item.name + "}"); if (index > -1) { value = rec.QrCodeValues[index]; amoutOfQuestions = value; rec.AmoutOfQuestions = Convert.ToInt32(value); verify = true; } } else if (appSettings.Fields.AmoutOfQuestions && !string.IsNullOrEmpty(lastAmoutOfQuestions)) value = lastAmoutOfQuestions; break; case "question_number_1": case "index_of_first_question": if (rec.QrCodeHeaders != null && rec.QrCodeHeaders.Length > 0) { int index = Array.IndexOf(rec.QrCodeHeaders, "{" + item.name + "}"); if (index > -1) { value = rec.QrCodeValues[index]; //indexOfQuestion = value;//??? verify = true; } } else if (appSettings.Fields.IndexOfFirstQuestion && !string.IsNullOrEmpty(lastIndexOfQuestion)) value = lastIndexOfQuestion; break; default: value = ""; break; } if ((rec.QrCodeHeaders == null || rec.QrCodeHeaders.Length == 0) && lastSheetId != "" && lastSheetId == rec.SheetIdentifier && lastTestId != "" && testId == lastTestId) { if (item.name == "amout_of_questions") { value = lastAmoutOfQuestions; if (utils.IsNumeric(lastAmoutOfQuestions)) rec.AmoutOfQuestions = Convert.ToInt32(lastAmoutOfQuestions); } else if (item.name == "index_of_first_question" || item.name == "question_number_1") { value = lastIndexOfQuestion; if (utils.IsNumeric(lastIndexOfQuestion)) rec.IndexOfFirstQuestion = Convert.ToInt32(lastIndexOfQuestion); } } //var bItem = new BarCodeItem(item.name, "numbersText", value, value//item.type//rec.areas[1].type //, new Rectangle(item.areas[0].left, item.areas[0].top, item.areas[0].width, item.areas[0].height)); var bItem = new BarCodeItem(item.name, item.areas[1].type, value, value//item.type//rec.areas[1].type , new Rectangle(item.areas[0].left, item.areas[0].top, item.areas[0].width, item.areas[0].height)); recTools.SetOutputValues(ref rec.headers, ref rec.headersValues, ref rec.totalOutput, ref rec.allBarCodeNames , ref rec.allBarCodeValues, bItem.Name, bItem.Value, item.outputPosition); if (BarCodeControlsBuilding) rec.FindOrAddAndSetValueBarcode(bItem.Name, value, verify); if (item.name == "amout_of_questions") amout_of_questionsIndex = rec.allBarCodeValues.Length - 1; if (!verify || (item.name == "bubbles_per_line" && (bItem.Value != "5" || bItem.Value != "6"))) { lblErr.Text = "Error in " + bItem.Name; if (!errList.Contains(lblErr.Text)) errList.Add(lblErr.Text); try { int index = Array.IndexOf(rec.allBarCodeNames, item.name); BarCodeListItemControl b = barCodeList.ControlList[index] as BarCodeListItemControl; b.comboBox1.ForeColor = Color.Red; } catch (Exception) { } lblErr.Visible = true; } else if (item.name == "bubbles_per_line") { switch (bItem.Value) { case "5": case "6": rec.bubbles_per_lineErr = false; break; default: if (!errList.Contains(lblErr.Text)) errList.Add(lblErr.Text); rec.bubbles_per_lineErr = true; try { int index = Array.IndexOf(rec.allBarCodeNames, item.name); BarCodeListItemControl b = barCodeList.ControlList[index] as BarCodeListItemControl; b.comboBox1.ForeColor = Color.Red; } catch (Exception) { } lblErr.Visible = true; break; } } } else if (item.type == "bubblesRegions") { rec.numberOfBubblesRegion = i; bubblesRegions = item; if (linsForm != null) { linsForm.nudArea.Maximum = item.areas.Length; linsForm.nudArea.Value = 1; } if (factAreas.Length == 0) { for (int j = 0; j < rec.areas.Length; j++) rec.areas[j].bubblesPerLine = item.areas[j].bubblesPerLine; } recTools.SetSettings ( ref rec.bubblesRegions , ref rec.bubblesOfRegion , ref rec.bubblesSubLinesCount , ref rec.bubblesSubLinesStep , ref rec.bubblesPerLine , ref rec.lineHeight , ref rec.linesPerArea , out rec.answersPosition , out rec.indexAnswersPosition , ref rec.totalOutput , ref rec.bubbleLines , item , rec.kx, rec.ky , rec.curRect, rec.etRect ); } } if (BarCodeControlsBuilding) { rec.maxAmoutOfQuestions = rec.linesPerArea.Sum(); allAreasNaturalSize = new Rectangle[bubblesRegions.areas.Length]; factAreasManualSet = new bool[bubblesRegions.areas.Length]; if (rec.SheetIdentifier == "FANDP")//rec.AmoutOfQuestions == 0 { maxAmoutOfQuestions = rec.linesPerArea.Sum(); rec.AmoutOfQuestions = maxAmoutOfQuestions; rec.FindOrAddAndSetValueBarcode("amout_of_questions", maxAmoutOfQuestions.ToString()); rec.FindOrAddAndSetValueBarcode("index_of_first_question", rec.IndexOfFirstQuestion.ToString()); BarCodeListItemControl b = barCodeList.ControlList["amout_of_questions"] as BarCodeListItemControl; rbtnGrid.Enabled = false;//!!! b.btnCheck.PerformClick(); linsForm.Close(); linsForm = null; return; } } //amout_of_questions = GetFactAreas(amout_of_questions); if (!SetFactAreasSetting()) { if (rec.AmoutOfQuestions > 0) { amout_of_questions = rec.AmoutOfQuestions; } amout_of_questions = GetFactAreas(amout_of_questions); if (BarCodeControlsBuilding && lastSheetId != rec.SheetIdentifier || factAreas.Length == 0 || (amout_of_questions > 0 && amout_of_questions != factLinesPerArea.Sum())) { //if (factAreas.Length == 0) // amout_of_questions = GetFactAreas(amout_of_questions); nudArea_ValueChanged(null, null); for (int i = 0; i < factAreas.Length; i++) { factAreas[i].height = 0; } } else { if (factLinesPerArea.Length == 0 && linsForm != null) linsForm.nudRows.Value = rec.linesPerArea[0]; else { if (linsForm != null && BarCodeControlsBuilding) linsForm.nudRows.Value = factLinesPerArea[0]; } if (linsForm != null && BarCodeControlsBuilding) { linsForm.nudCols.Value = 4;// factAreas[0].bubblesPerLine; linsForm.nudSubRows.Value = factAreas[0].subLinesAmount; } } } RecognizeBubblesButton.Enabled = true; } catch (Exception ex) { log.LogMessage(ex.Message); } }
//------------------------------------------------------------------------- void linsForm_FormClosing(object sender, FormClosingEventArgs e) { appSettings.Fields.LinsWindowLocation = linsForm.Location; appSettings.Fields.LinsWindowSize = linsForm.Size; appSettings.Fields.LinsTrackBar1Value = linsForm.trackBar1.Value; appSettings.Fields.ChbBuildAllAreas = linsForm.chbBuildAllAreas.Checked; //linsFormIsVisible = false; if (e.CloseReason == CloseReason.UserClosing) { e.Cancel = true; linsForm.Hide(); RecognizeAllButton.Enabled = true; //RecognizeBubblesButton.Enabled = true; return; } SaveSettings(); linsForm.FormClosing -= new FormClosingEventHandler(linsForm_FormClosing); //btnRestore.Enabled = false; if (animatedTimer != null) animatedTimer.StartAnimation(); area = Rectangle.Empty; RecognizeAllButton.Enabled = true; allAreasNaturalSize = new Rectangle[0]; //recBitmap = null; linsForm.Dispose(); linsForm = null; }
//------------------------------------------------------------------------- public void CreateLinsForm(bool barCodeControlsBuilding = true) { if (Status == StatusMessage.Delete || Status == StatusMessage.Verify) return; linsForm = new LinsForm(); linsForm.Visible = false; linsForm.WindowState = FormWindowState.Normal; linsForm.Location = appSettings.Fields.LinsWindowLocation; linsForm.Size = appSettings.Fields.LinsWindowSize; linsForm.Owner = this; linsForm.FormClosing += new FormClosingEventHandler(linsForm_FormClosing); linsForm.nudArea.ValueChanged += new EventHandler(nudArea_ValueChanged); linsForm.nudCols.ValueChanged += new EventHandler(nudCols_ValueChanged); linsForm.nudRows.ValueChanged += new EventHandler(nudRows_ValueChanged); linsForm.nudSubRows.ValueChanged += new EventHandler(nudSubRows_ValueChanged); linsForm.btnOk.Click += new EventHandler(btnOk_Click); linsForm.chbBuildAllAreas.CheckedChanged += ChbBuildAllAreas_CheckedChanged; linsForm.chbBuildAllAreas.Checked = appSettings.Fields.ChbBuildAllAreas; //eDoctrinaUtils.RegionsArea[] lastFactAreas = new RegionsArea[0]; InitLinsForm(barCodeControlsBuilding); }