public DataSelect(TaskConfig w)
        {
            InitializeComponent();
            mainWindow   = w;
            dbConnection = new DBWorker();

            //подключаемся к БД и извлекаем начальную инфу о параметрах и марках стали
            if (dbConnection.isConnected)
            {
                task = new DataPlavka(dbConnection.GetPlavka(DbSelect.Columns, null));
                for (int i = 0; i < task.xAll.Count; i++)
                {
                    xListBox.Items.Add(task.xAll[i].description);
                }
                for (int i = 0; i < task.yAll.Count; i++)
                {
                    yListBox.Items.Add(task.yAll[i].description);
                }

                DataTable dt = dbConnection.GetPlavka(DbSelect.Marks, null);
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    markComboBox.Items.Add(dt.Rows[i].ItemArray[0]);
                }

                gostComboBox.IsEnabled = false;
                typeComboBox.IsEnabled = false;
                dbConnection.CloseConnection();
            }
        }
Ejemplo n.º 2
0
        private void dataMenuItem_Click(object sender, RoutedEventArgs e)
        {
            if (dataWindow == null)
            {
                dataWindow = new DataSelect(this);
            }
            dataWindow.ShowDialog();
            if (dataWindow.IsInitialized)
            {
                if (dataWindow.isChanged)
                {
                    dataWindow.isChanged = false;
                    task                = new DataPlavka(dataWindow.task);
                    Log.Text            = "Загружено " + dataWindow.task.plavka.Rows.Count.ToString() + " записей";
                    labelDataNotes.Text = "Загружено записей: " + dataWindow.task.plavka.Rows.Count.ToString();

                    dataDataGrid.ItemsSource = null;
                    dataDataGrid.ItemsSource = dataWindow.task.plavka.AsDataView();
                    if (dataDataGrid.Columns.Count < 9)
                    {
                        for (int i = 0; i < dataDataGrid.Columns.Count; i++)
                        {
                            dataDataGrid.Columns[i].Width = new DataGridLength(1, DataGridLengthUnitType.Star);
                        }
                    }

                    labelDataX.Content = "Количество исследуемых факторов - " + task.x.Count;
                    labelDataY.Content = "Количество исследуемых свойств - " + task.y.Count;
                    xBoundsData.Clear();
                    for (int i = 0; i < task.x.Count; i++)
                    {
                        xBoundsData.Add(new itemGrid(task.xAll[task.x[i]].description, -1, -1));
                    }
                    xDescrGrid.ItemsSource = xBoundsData;

                    markComboBox.Items.Clear();
                    gostComboBox.Items.Clear();
                    typeComboBox.Items.Clear();
                    typeComboBox.IsEnabled = false;
                    DBWorker  dbConnection = new DBWorker();
                    DataTable dt           = dbConnection.GetPlavka(DbSelect.Marks, null);
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        markComboBox.Items.Add(dt.Rows[i].ItemArray[0]);
                    }
                    dbConnection.CloseConnection();

                    string[] temp = task.mark.Split(' ');
                    SetGOST();

                    funcGrid.Visibility     = System.Windows.Visibility.Collapsed;
                    statGrid.Visibility     = System.Windows.Visibility.Collapsed;
                    groupBoxBefore.Header   = "Начальные границы";
                    groupBoxAfter.Header    = "Дискретная модель";
                    dataExpander.IsExpanded = true;
                }
            }
        }
        private int LoadDescret(int id)
        {
            DBWorker dbConnection = new DBWorker();

            if (dbConnection.isConnected)
            {
                DataTable modelTable = dbConnection.LoadModel(DbSelect.SelectDes, 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.modelDescret      = new DescrModel(id);
                W.modelDescret.date = Convert.ToDateTime(modelTable.Rows[0]["DATE_DES"]);

                W.modelDescret.GOST = modelTable.Rows[0]["GOST_ID"].ToString();
                W.modelDescret.mark = modelTable.Rows[0]["MARKA"].ToString() + " " + modelTable.Rows[0]["VYTYAZHKA"].ToString();
                //W.task.GOST = W.modelDescret.GOST;
                //W.task.mark = W.modelDescret.mark;
                W.modelDescret.alpha    = Convert.ToDouble(modelTable.Rows[0]["ALPHA"]);
                W.modelDescret.beta     = Convert.ToDouble(modelTable.Rows[0]["BETA"]);
                W.modelDescret.criteria = Convert.ToDouble(modelTable.Rows[0]["U"]);
                string   ys  = modelTable.Rows[0]["YS"].ToString();
                string[] ys2 = ys.Split('@');
                for (int i = 0; i < ys2.Length; i++)
                {
                    W.modelDescret.y.Add(Convert.ToInt32(ys2[i]));                                  //установили У
                }
                //формируем массив факторов Х
                for (int i = 0; i < W.task.xAll.Count; i++)
                {
                    if (modelTable.Rows[0][W.task.xAll[i].name] != System.DBNull.Value)
                    {
                        W.modelDescret.x.Add(i);
                    }
                }

                for (int i = 0; i < W.modelDescret.x.Count; i++)
                {
                    double     lower = Convert.ToDouble(modelTable.Rows[0][W.task.xAll[W.modelDescret.x[i]].name + "_MIN"]);
                    double     upper = Convert.ToDouble(modelTable.Rows[0][W.task.xAll[W.modelDescret.x[i]].name]);
                    string     descr = W.task.xAll[W.modelDescret.x[i]].description;
                    Conditions c     = new Conditions(lower, upper, descr);
                    W.modelDescret.xBounds.Add(c);
                }
            }
            dbConnection.CloseConnection();
            return(1);
        }
Ejemplo n.º 4
0
        public GostHelper()
        {
            InitializeComponent();
            DBWorker dbConnection = new DBWorker();

            task = new DataPlavka(dbConnection.GetPlavka(DbSelect.Columns, null));
            for (int i = 0; i < task.yAll.Count; i++)
            {
                List.Add(new itemGrid(task.yAll[i].description, -1, -1));
            }
            dbConnection.CloseConnection();
            gridGOST.ItemsSource = List;
        }
 private void markComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     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();
     viewBtn.IsEnabled = false;
 }
Ejemplo n.º 6
0
        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("Введите границы!");
            }
        }
Ejemplo n.º 7
0
 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 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);
        }
Ejemplo n.º 11
0
        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];
        }