private void buttonGO_Click(object sender, RoutedEventArgs e) { bool flag = false; for (int i = 0; i < List.Count; i++) { if (List[i].val1 != -1 || List[i].val2 != -1) { string names = "GOST_ID,MARKA,VYTYAZHKA"; for (int j = 0; j < List.Count; j++) { names += "," + task.yAll[j].name + "_MIN," + task.yAll[j].name; } string values = "'" + textBoxGost.Text + "','" + textBoxMarka.Text + "','" + textBoxType.Text + "'"; for (int j = 0; j < List.Count; j++) { values += "," + List[j].val1.ToString(System.Globalization.CultureInfo.InvariantCulture) + "," + List[j].val2.ToString(System.Globalization.CultureInfo.InvariantCulture); } DBWorker dbConnection = new DBWorker(); int res = dbConnection.InsertGOST(names, values); dbConnection.CloseConnection(); if (res == 1) { MessageBox.Show("Запись добавлена!"); } else { MessageBox.Show("Ошибка добавления!"); } this.Close(); flag = true; break; } } if (flag == false) { MessageBox.Show("Введите границы!"); } }
private void markComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (markComboBox.SelectedIndex != -1) { DBWorker dbConnection = new DBWorker(); if (dbConnection.isConnected) { DataTable dt = dbConnection.GetPlavka(DbSelect.GOSTS, markComboBox.SelectedItem.ToString()); gostComboBox.Items.Clear(); for (int i = 0; i < dt.Rows.Count; i++) { gostComboBox.Items.Add(dt.Rows[i].ItemArray[0]); } gostComboBox.IsEnabled = true; typeComboBox.IsEnabled = false; typeComboBox.Items.Clear(); } dbConnection.CloseConnection(); } }
private void gostComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (gostComboBox.HasItems) { DBWorker dbConnection = new DBWorker(); if (dbConnection.isConnected) { string[] conds = new string[2]; conds[0] = markComboBox.SelectedItem.ToString(); conds[1] = gostComboBox.SelectedItem.ToString(); DataTable dt = dbConnection.GetPlavka(DbSelect.SteelTypes, conds); typeComboBox.Items.Clear(); for (int i = 0; i < dt.Rows.Count; i++) { typeComboBox.Items.Add(dt.Rows[i].ItemArray[0]); } typeComboBox.IsEnabled = true; } dbConnection.CloseConnection(); } }
private void saveTechnology(Technology tech) { DBWorker dbConnection = new DBWorker(); if (dbConnection.isConnected) { tech.id = dbConnection.GetID(DbSelect.TechID) + 1; if (dbConnection.InsertModel(task, tech) == -1) { MessageBox.Show("Ошибка сохранения технологии"); tech.id = -1; } else { if (tech.isCorrected != true) { MessageBox.Show("Cохранено!"); } labelOptID.Text = "ID: " + tech.id.ToString(); } } }
private void saveDesModel(bool showBox) { DBWorker dbConnection = new DBWorker(); if (dbConnection.isConnected) { modelDescret.id = dbConnection.GetID(DbSelect.DesID) + 1; if (dbConnection.InsertModel(task, modelDescret) == -1) { MessageBox.Show("Ошибка сохранения дискретной модели"); modelDescret.id = -1; } else { if (showBox) { MessageBox.Show("Модель успешно сохранена!"); } labelDesID.Text = "ID: " + modelDescret.id.ToString(); } } }
private void saveRegModel(bool showBox) { DBWorker dbConnection = new DBWorker(); if (dbConnection.isConnected) { modelRegress.id = dbConnection.GetID(DbSelect.RegID) + 1; if (dbConnection.InsertModel(task, modelRegress) == -1) { MessageBox.Show("Ошибка сохранения регрессионной модели"); modelRegress.id = -1; } else { if (showBox) { MessageBox.Show("Модель успешно сохранена!"); } labelRegID.Text = "ID: " + modelRegress.id.ToString(); } } }
private void startBtn_Click(object sender, RoutedEventArgs e) { isChanged = true; if (markComboBox.Text != "" && gostComboBox.Text != "" && typeComboBox.Text != "" && xTaskListBox.HasItems && yTaskListBox.HasItems) { string[] columns = new string[2]; //формируем запрос на извлечение данных task.x.Clear(); task.y.Clear(); // for (int i = 0; i < yTaskListBox.Items.Count; i++) //записываем в задачу и sql выборку всех у { for (int j = 0; j < task.yAll.Count; j++) { if (task.yAll[j].description == yTaskListBox.Items[i].ToString()) { columns[0] += "P." + task.yAll[j].name + ","; task.y.Add(j); } } } for (int i = 0; i < xTaskListBox.Items.Count; i++)//записываем в задачу и sql выборку всех х { for (int j = 0; j < task.xAll.Count; j++) { if (task.xAll[j].description == xTaskListBox.Items[i].ToString()) { columns[0] += task.xAll[j].name + ","; task.x.Add(j); } } } task.y.Sort(); task.x.Sort(); columns[0] = columns[0].Trim(','); // удаляем последнюю запятую columns[1] = "marka='" + markComboBox.SelectionBoxItem + "' AND gost_id='" + gostComboBox.SelectionBoxItem + "' AND vytyazhka='" + typeComboBox.SelectionBoxItem + "' AND date_plavka > to_date('" + date1picker.Text + "', 'dd.mm.yyyy') AND date_plavka < to_date('" + date2picker.Text + "', 'dd.mm.yyyy')"; //выбор конкретной марки стали dbConnection = new DBWorker(); plavka = dbConnection.GetPlavka(DbSelect.Data, columns); //извлекаем нужные данные полностью task.plavka = plavka.Copy(); for (int i = 0; i < task.plavka.Rows.Count; i++) //удаляем из данных задачи строки с пустыми значениями { for (int j = 0; j < task.plavka.Rows[i].ItemArray.Length; j++) { if (task.plavka.Rows[i].ItemArray[j].ToString() == "") { task.plavka.Rows.RemoveAt(i); i--; break; } } } labelResult.Content = "Выбрано " + plavka.Rows.Count + " записей"; labelResult2.Content = plavka.Rows.Count - task.plavka.Rows.Count + " с пустыми полями"; viewBtn.IsEnabled = true; dbConnection.CloseConnection(); task.mark = markComboBox.SelectionBoxItem + " " + typeComboBox.SelectionBoxItem; task.GOST = gostComboBox.SelectionBoxItem.ToString(); mainWindow.labelDataMark.Text = "Марка: " + markComboBox.SelectionBoxItem + " " + typeComboBox.SelectionBoxItem; mainWindow.labelDataGOST.Text = "Стандарт: " + gostComboBox.SelectionBoxItem; mainWindow.labelDataSince.Text = "C: " + date1picker.Text; mainWindow.labelDataTo.Text = "По: " + date2picker.Text; task.GOST = gostComboBox.SelectionBoxItem.ToString(); task.mark = markComboBox.SelectionBoxItem + " " + typeComboBox.SelectionBoxItem; } else { labelResult.Content = "Укажите все параметры"; } }
private int LoadTechnology(int id) { DBWorker dbConnection = new DBWorker(); if (dbConnection.isConnected) { DataTable modelTable = dbConnection.LoadModel(DbSelect.SelectTech, id); if (W.task == null) { W.task = new DataPlavka(dbConnection.GetPlavka(DbSelect.Columns, null)); //берем список параметров } if (modelTable == null) { return(-1); } if (modelTable.Rows.Count == 0) { return(0); } W.technology = new Technology(id); W.technology.date = Convert.ToDateTime(modelTable.Rows[0]["DATE_TECH"]); string[] markInfo = dbConnection.GetMark(Convert.ToInt32(modelTable.Rows[0]["STE_ID"])); W.technology.GOST = markInfo[0]; W.technology.mark = markInfo[1] + " " + markInfo[2]; W.technology.rmserror = Convert.ToDouble(modelTable.Rows[0]["RMSERROR"]); if (W.technology.rmserror == 0) { W.technology.rmserror = 1.0e-16; } W.technology.descretID = Convert.ToInt32(modelTable.Rows[0]["DES_ID"]); W.technology.regressID = Convert.ToInt32(modelTable.Rows[0]["REG_ID"]); W.technology.baseTechnologyID = Convert.ToInt32(modelTable.Rows[0]["BASE_ID"]); if (W.technology.baseTechnologyID != -1) { W.technology.isCorrected = true; } //формируем массив факторов Х for (int i = 0; i < W.task.xAll.Count; i++) { if (modelTable.Rows[0][W.task.xAll[i].name] != System.DBNull.Value) { W.technology.x.Add(i); } } //формируем массив факторов Y for (int i = 0; i < W.task.yAll.Count; i++) { if (modelTable.Rows[0][W.task.yAll[i].name] != System.DBNull.Value) { W.technology.y.Add(i); } } for (int i = 0; i < W.technology.x.Count; i++) { W.technology.xOpt.Add(Convert.ToDouble(modelTable.Rows[0][W.task.xAll[W.technology.x[i]].name])); } for (int i = 0; i < W.technology.y.Count; i++) { W.technology.yOpt.Add(Convert.ToDouble(modelTable.Rows[0][W.task.yAll[W.technology.y[i]].name])); } } dbConnection.CloseConnection(); return(1); }
private int LoadRegress(int id) //грузим регрессионную модель { DBWorker dbConnection = new DBWorker(); if (dbConnection.isConnected) { DataTable modelTable = dbConnection.LoadModel(DbSelect.SelectReg, id); if (W.task == null) { W.task = new DataPlavka(dbConnection.GetPlavka(DbSelect.Columns, null)); //берем список параметров } if (modelTable == null) { if (W.modelRegress != null) { W.modelRegress.buildInfo = -3; } return(-1); } if (modelTable.Rows.Count == 0) { return(0); } W.modelRegress = new RegressionModel(id); W.modelRegress.date = Convert.ToDateTime(modelTable.Rows[0]["DATE_REG"]); W.modelRegress.GOST = modelTable.Rows[0]["GOST_ID"].ToString(); W.modelRegress.mark = modelTable.Rows[0]["MARKA"].ToString() + " " + modelTable.Rows[0]["VYTYAZHKA"].ToString(); //W.task.GOST = W.modelRegress.GOST; //W.task.mark = W.modelRegress.mark; //формируем массив факторов Х for (int i = 0; i < W.task.xAll.Count; i++) { if (modelTable.Rows[0][W.task.xAll[i].name] != System.DBNull.Value) { W.modelRegress.x.Add(i); } } for (int i = 0; i < W.modelRegress.x.Count; i++) //проверяем простая или точная модель { if (modelTable.Rows[0][W.task.xAll[W.modelRegress.x[i]].name + "_F"] != System.DBNull.Value) { W.modelRegress.isUpgraded = true; break; } } if (W.modelRegress.isUpgraded) { W.modelRegress.typesF = new int[W.modelRegress.x.Count]; for (int i = 0; i < W.modelRegress.x.Count; i++) { W.modelRegress.typesF[i] = Convert.ToInt32(modelTable.Rows[0][W.task.xAll[W.modelRegress.x[i]].name + "_F"]); } } for (int i = 0; i < modelTable.Rows.Count; i++) //каждая строка - модель { W.modelRegress.y.Add(Convert.ToInt32(modelTable.Rows[i]["Y_ID"])); //W.task.y.Add(Convert.ToInt32(modelTable.Rows[i]["Y_ID"])); double[] weights = new double[W.modelRegress.x.Count + 1]; //последний - свобоный ЧЛЕН for (int j = 0; j < W.modelRegress.x.Count; j++) { weights[j] = Convert.ToDouble(modelTable.Rows[i][W.task.xAll[W.modelRegress.x[j]].name]); } weights[W.modelRegress.x.Count] = Convert.ToDouble(modelTable.Rows[i]["A"]); RegEquation modelOne = new RegEquation(weights, Convert.ToDouble(modelTable.Rows[i]["FISHER"]), Convert.ToDouble(modelTable.Rows[i]["FISHER_VAL"]), Convert.ToDouble(modelTable.Rows[i]["RMSERROR"])); modelOne.descr = W.task.yAll[W.modelRegress.y[i]].description; if (modelOne.F_test == 0) { modelOne.F_test = 1.0e-16; } W.modelRegress.equation.Add(modelOne); } } dbConnection.CloseConnection(); return(1); }
private void SetGOST() { string[] temp; if (modelDescret != null) { temp = modelDescret.mark.Split(' '); } else { temp = task.mark.Split(' '); } string[] conds = new string[4]; conds[0] = ""; conds[1] = temp[0]; if (modelDescret != null) { conds[2] = modelDescret.GOST; } else { conds[2] = task.GOST; } conds[3] = temp[1]; if (modelDescret != null) { for (int i = 0; i < modelDescret.y.Count; i++) { conds[0] += task.yAll[modelDescret.y[i]].name + "," + task.yAll[modelDescret.y[i]].name + "_min,"; } } else { for (int i = 0; i < task.y.Count; i++) { conds[0] += task.yAll[task.y[i]].name + "," + task.yAll[task.y[i]].name + "_min,"; } } conds[0] = conds[0].Trim(','); DBWorker dbConnection = new DBWorker(); DataTable res = dbConnection.GetPlavka(DbSelect.DataY, conds); //извлекаем нужные данные полностью dbConnection.CloseConnection(); yBoundsData.Clear(); if (modelDescret != null) { for (int i = 0; i < res.Rows[0].ItemArray.Length; i = i + 2) { yBoundsData.Add(new itemGrid(task.yAll[modelDescret.y[i / 2]].description, Convert.ToDouble(res.Rows[0].ItemArray[i + 1]), Convert.ToDouble(res.Rows[0].ItemArray[i]))); } } else { for (int i = 0; i < res.Rows[0].ItemArray.Length; i = i + 2) { yBoundsData.Add(new itemGrid(task.yAll[task.y[i / 2]].description, Convert.ToDouble(res.Rows[0].ItemArray[i + 1]), Convert.ToDouble(res.Rows[0].ItemArray[i]))); } } yDescrGrid.ItemsSource = null; yDescrGrid.ItemsSource = yBoundsData; expanderDes.Header = conds[1] + " " + conds[2] + " " + conds[3]; labelDesGOST.Text = "Стандарт: " + conds[2]; labelDesMark.Text = "Марка: " + conds[1] + " " + conds[3]; }