Exemplo n.º 1
0
        //=========================================
        // specialists
        private void Spec_MenuItemDestroy_Click(object sender, RoutedEventArgs e)
        {
            if (System.Windows.Forms.MessageBox.Show("Вы действительно хотите удалить выбраный элемент ?", "Внимание",
                  MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
            {
                try
                {
                    Connection connection = new Connection();
                    connection.Open();
                    MySqlCommand mySqlCommand = new MySqlCommand(@"
UPDATE
operators
SET active = 0
WHERE Id_Operator = @id
", connection.mySqlConnection);
                    var dataRowView = (DataRowView)dg_Specs.CurrentItem;
                    mySqlCommand.Parameters.Clear();
                    mySqlCommand.Parameters.AddWithValue("id", dataRowView.Row.ItemArray[0]);
                    mySqlCommand.ExecuteNonQuery();
                    connection.Close();
                    fill_dg_Specs();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }
            }
        }
Exemplo n.º 2
0
        public Dictionary<int, string> GetDb_TimeIntervalSmens()
        {
            var intervalSmens = new Dictionary<int, string>();
            Connection connection = null;
            try
            {
                connection = new Connection();
                connection.Open();
            } catch (Exception ex)
            {
                Console.WriteLine("========================================");
                Console.WriteLine("Parameters.cs");
                Console.WriteLine("Dictionary GetDb_TimeIntervalSmens()  :  " + DateTime.Now.ToString());
                Console.WriteLine("Open BD");
                throw (ex);
            }
            MySqlCommand mySqlCommand = new MySqlCommand("SELECT Id_TimeIntervalSmen, TimeIntervalSmen FROM timeintervalsmens WHERE active = 1", connection.mySqlConnection);
            MySqlDataReader mySqlDataReader = null;
            try { mySqlDataReader = (MySqlDataReader)mySqlCommand.ExecuteReader(); } catch (Exception ex)
            {
                Console.WriteLine("========================================");
                Console.WriteLine("Parameters.cs");
                Console.WriteLine("Dictionary GetDb_TimeIntervalSmens()  :  " + DateTime.Now.ToString());
                Console.WriteLine("ExecuteReader");
                throw (ex);
            }
            try
            {
                while (mySqlDataReader.Read())
                {
                    intervalSmens.Add(
                        mySqlDataReader.GetInt32(0),
                        mySqlDataReader.GetString(1));
                }
            } catch (Exception ex)
            {
                Console.WriteLine("========================================");
                Console.WriteLine("Parameters.cs");
                Console.WriteLine("Dictionary GetDb_TimeIntervalSmens()  :  " + DateTime.Now.ToString());
                Console.WriteLine("Read BD");
                throw (ex);
            }
            try
            {
                mySqlDataReader.Close();
                connection.Close();
                connection = null;
            }
            catch (Exception ex)
            {
                Console.WriteLine("========================================");
                Console.WriteLine("Parameters.cs");
                Console.WriteLine("Dictionary GetDb_WorkSmens()  :  " + DateTime.Now.ToString());
                Console.WriteLine("Close BD");
                throw (ex);
            }

            return intervalSmens;
        }
Exemplo n.º 3
0
        public void Fist_TreeData()
        {
            Mouse.OverrideCursor = Cursors.Wait;
            Connection connection = new Connection();
            try
            {
                try { connection.Open(); }
                catch (Exception ex)
                {
                    Console.WriteLine("========================================");
                    Console.WriteLine("ArchiveControl.cs");
                    Console.WriteLine("Fist_TreeData()  :  " + DateTime.Now.ToString());
                    Console.WriteLine("Open()");
                    throw (ex);
                }

                MySqlCommand myCommand = new MySqlCommand("SELECT DISTINCT YEAR (defectsdata.DatePr) FROM defectsdata", connection.mySqlConnection);
                MySqlDataReader dataReader = (MySqlDataReader)myCommand.ExecuteReader();

                while (dataReader.Read())
                {
                    var item = new TreeViewItem
                    {
                        Uid = dataReader.GetString(0),
                        Tag = "year",
                        Header = dataReader.GetString(0),
                        ItemContainerStyle = archiveWindow.TreeView_arc.ItemContainerStyle
                    };
                    item.Items.Add("*");
                    archiveWindow.TreeView_arc.Items.Add(item);
                }
                dataReader.Close();
            }
            catch
            {
                Mouse.OverrideCursor = Cursors.Arrow;
                archiveWindow.Close();
                Console.WriteLine("ArchiveControl.cs-Fist_TreeData() DB Error");
            }
            Mouse.OverrideCursor = Cursors.Arrow;
            try { connection.Close(); connection = null; } catch { }
        }
Exemplo n.º 4
0
 private void Recived_NewTube()
 {
     Connection connection = new Connection();
     mainWindow.New_Tube();
     if ((mainWindow.Parameters.Count == 12) && (mainWindow.Parameters2.Count == 1))
     {
         Write_NewTube write_newTube = new Write_NewTube();
         try
         {
             write_newTube.DoIt(buffForRead, bufferRecive);
         }
         catch (Exception ex)
         {
             Console.WriteLine("========================================");
             Console.WriteLine("Write.cs");
             Console.WriteLine("Recived_NewTube()  :  " + DateTime.Now.ToString());
             Console.WriteLine("Error write bd:");
             Console.WriteLine(ex.ToString());
         }
         write_newTube = null;
     }
     else
     {
         Console.WriteLine("========================================");
         Console.WriteLine("Write.cs");
         Console.WriteLine("Recived_NewTube()  :  " + DateTime.Now.ToString());
         Console.WriteLine("Ошибка количества параметров");
     }
     bufferRecive.Clear();
     //out
     {
         int last = mainWindow.parAdvn.GetDb_Last_NumberTube();
         mainWindow.Dispatcher.Invoke(new ThreadStart(delegate
         {
             mainWindow.lblinfo6.Content = "Пройдено труб:\t\t " + last;
         }));
     }
     connection = null;
 }
Exemplo n.º 5
0
        private void Button_AddUser_Click(object sender, RoutedEventArgs e)
        {
            Connection connection;
            MySqlCommand mySqlCommand;
            try
            {
                var txt_FIO = TextBox_FIO.Text;
                var txt_L_MD = TextBox_LevelMD.Text;
                var txt_L_USD = TextBox_LevelUSD.Text;
                //
                if (txt_FIO.Trim() != "" &&
                    txt_L_MD.Trim() != "" &&
                    txt_L_USD.Trim() != "")
                {
                    connection = new Connection();
                    connection.Open();
                    mySqlCommand = new MySqlCommand(@"
INSERT INTO operators
(Surname, LevelMD, LevelUSD)
VALUES
(@Surname, @LevelMD, @LevelUSD)", connection.mySqlConnection);
                    mySqlCommand.Parameters.AddWithValue("Surname", txt_FIO);
                    mySqlCommand.Parameters.AddWithValue("LevelMD", txt_L_MD);
                    mySqlCommand.Parameters.AddWithValue("LevelUSD", txt_L_USD);
                    mySqlCommand.ExecuteNonQuery();
                    connection.Close();
                    fill_dg_Specs();
                }
                else
                {
                    System.Windows.MessageBox.Show("Не все поля заполнены");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
Exemplo n.º 6
0
        public void fill_dg_Sample()
        {
            try
            {
                Connection connection = new Connection();
                connection.Open();
                MySqlCommand myCommand = new MySqlCommand(@"
SELECT
  controlsamples.Id_ControlSample AS 'ID'
, controlsamples.NameControlSample AS 'Название контрольного образца'
, sizetubes.SizeTube AS 'Диаметр трубы'
, controlsamples.DepthMin AS 'Минимальный диаметр'
, controlsamples.DepthMax AS 'Максимальный диаметр'
FROM controlsamples
Inner Join sizetubes ON sizetubes.Id_SizeTube = controlsamples.Id_SizeTube
WHERE controlsamples.active = 1
", connection.mySqlConnection);
                MySqlDataAdapter dataAdapter = new MySqlDataAdapter(myCommand.CommandText, connection.mySqlConnection);
                DataSet dSet = new DataSet();
                dataAdapter.Fill(dSet);
                dg_Sample.ItemsSource = dSet.Tables[0].DefaultView;
                Combobox_Sample_d.ItemsSource = Get_Db_SizeTubes();
                connection.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
Exemplo n.º 7
0
 public Dictionary<int, string> GetDb_Device()
 {
     var device = new Dictionary<int, string>();
     Connection connection = null;
     try
     {
         connection = new Connection();
         connection.Open();
     } catch (Exception ex)
     {
         Console.WriteLine("========================================");
         Console.WriteLine("Parameters.cs");
         Console.WriteLine("Dictionary GetDb_Device()  :  " + DateTime.Now.ToString());
         Console.WriteLine("Open BD");
         throw (ex);
     }
     MySqlCommand mySqlCommand = new MySqlCommand("SELECT Id_Device, NameDevice FROM device WHERE active = 1", connection.mySqlConnection);
     MySqlDataReader mySqlReader = null;
     try
     {
         mySqlReader = (MySqlDataReader)mySqlCommand.ExecuteReader();
     } catch (Exception ex)
     {
         Console.WriteLine("========================================");
         Console.WriteLine("Parameters.cs");
         Console.WriteLine("Dictionary GetDb_Device()  :  " + DateTime.Now.ToString());
         Console.WriteLine("ExecuteReader");
         throw (ex);
     }
     try
     {
         while (mySqlReader.Read())
         {
             device.Add(
                 mySqlReader.GetInt32(0),
                 mySqlReader.GetString(1));
         }
     } catch (Exception ex)
     {
         Console.WriteLine("========================================");
         Console.WriteLine("Parameters.cs");
         Console.WriteLine("Dictionary GetDb_Device()  :  " + DateTime.Now.ToString());
         Console.WriteLine("Read BD");
         throw (ex);
     }
     try
     {
         mySqlReader.Close();
         connection.Close();
         connection = null;
     } catch (Exception ex)
     {
         Console.WriteLine("========================================");
         Console.WriteLine("Parameters.cs");
         Console.WriteLine("Dictionary GetDb_Device()  :  " + DateTime.Now.ToString());
         Console.WriteLine("Close BD");
         throw (ex);
     }
     return device;
 }
Exemplo n.º 8
0
        //=====================================================================
        public void Tube_Control(TreeViewItem item)
        {
            Connection connection = new Connection();
            MySqlCommand myCommand = new MySqlCommand();
            try
            {
                connection.Open();
                if (item.Tag.ToString() == "tube0" || item.Tag.ToString() == "tube1")
                {
                    Mouse.OverrideCursor = Cursors.Wait;
                    myCommand.CommandText = @"
SELECT
defectsdata.IndexData,
defectsdata.NumberPart,
defectsdata.NumberTube,
defectsdata.NumberSegments,
defectsdata.DataSensors,
DATE_FORMAT(defectsdata.DatePr, '%Y-%m-%d'),
defectsdata.TimePr,
worksmens.NameSmen,
o1.Surname,
o2.Surname
FROM defectsdata
INNER JOIN indexes ON indexes.IndexData = defectsdata.IndexData
INNER JOIN worksmens ON worksmens.Id_WorkSmen = indexes.Id_WorkSmen
INNER JOIN operators o1 ON o1.Id_Operator = indexes.Id_Operator1
INNER JOIN operators o2 ON o2.Id_Operator = indexes.Id_Operator2
WHERE
indexes.IndexData = @A
LIMIT 1
";
                    myCommand.Parameters.Clear();
                    myCommand.Parameters.AddWithValue("A", item.Uid);
                    myCommand.Connection = connection.mySqlConnection;

                    MySqlDataReader dataReader = (MySqlDataReader)myCommand.ExecuteReader();

                    while (dataReader.Read())
                    {
                        archiveWindow.Label1.Content = "Номер плавки\t" + dataReader.GetString(1);
                        archiveWindow.Label2.Content = "Номер трубы\t" + dataReader.GetString(2);
                        archiveWindow.Label3.Content = "Дата проведения Н.К.\t" + dataReader.GetString(5);
                        archiveWindow.Label4.Content = "Время проведения Н.К.\t" + dataReader.GetString(6);
                        archiveWindow.Label5.Content = "Длина трубы (метры)\t\t " + Math.Round((dataReader.GetDouble(3) / 6), 2);
                        archiveWindow.Label7.Content = "Рабочая смена\t" + dataReader.GetString(7);
                        archiveWindow.Label8.Content = "Специалист ОКПП\t" + dataReader.GetString(9);
                        archiveWindow.Label9.Content = "Специалист АСК ТЭСЦ-2\t" + dataReader.GetString(8);

                        for (int i = 0; i < countDeffectsLine; i++)
                        {
                            var line = (Line)archiveWindow.Canvas_Archive.FindName("errorLine" + i);
                            archiveWindow.Canvas_Archive.Children.Remove(line);
                            try
                            {
                                archiveWindow.Canvas_Archive.UnregisterName("errorLine" + i);
                            }
                            catch
                            {

                            }
                        }
                        countDeffectsLine = 0;

                        archiveWindow.Rectangle1.Width = dataReader.GetDouble(3) * 4;

                        var j = 0;

                        foreach (var deffect in (byte[])dataReader.GetValue(4))
                        {
                            if (deffect != 0)
                            {
                                var colorBrush = new SolidColorBrush
                                {
                                    Color = Colors.Red
                                };
                                var errorLine = new Line();

                                Canvas.SetLeft(errorLine, 40 + (j * 4));
                                errorLine.Opacity = 1;
                                errorLine.X1 = 0;
                                errorLine.X2 = 0;
                                errorLine.Y1 = 151;
                                errorLine.Y2 = errorLine.Y1 + 70;
                                errorLine.StrokeThickness = 4;
                                errorLine.Stroke = colorBrush;
                                errorLine.Fill = colorBrush;
                                archiveWindow.Canvas_Archive.RegisterName("errorLine" + countDeffectsLine, errorLine);
                                archiveWindow.Canvas_Archive.Children.Add(errorLine);
                                countDeffectsLine++;
                            }
                            j++;
                        }
                        archiveWindow.Label6.Content = "Кол-во дефектных сегментов\t " + countDeffectsLine;
                    }
                    dataReader.Close();
                    Mouse.OverrideCursor = Cursors.Arrow;
                }
            }
            catch
            {
                Console.WriteLine("ArchiveControl.cs-Tube_Control() DB Error");
            }
            try { connection.Close(); connection = null; } catch { }
        }
Exemplo n.º 9
0
        // за год дефектных (без образцов)
        public void Cdyears(Dictionary<string, string> DictDYears)
        {
            Connection connection = null;
            MySqlCommand myCommand = null;
            MySqlDataReader dataReader = null;

            try
            {
                try
                {
                    connection = new Connection();
                    connection.Open();
                }
                catch
                { throw (new Exception("Open Error")); }

                try
                {
                    myCommand = new MySqlCommand(@"
SELECT
Count(IndexData),
YEAR(DatePr)
FROM defectsdata
WHERE
IndexData <= @I
AND
FlDefectTube = 1
AND
NumberTube <> 0
GROUP BY YEAR(DatePr)
", connection.mySqlConnection);
                    myCommand.Parameters.Clear();
                    myCommand.Parameters.AddWithValue("I", MainWindow.ac.lastIndex);
                }
                catch
                { throw (new Exception("MySqlCommand Error")); }

                try
                {
                    dataReader = (MySqlDataReader)myCommand.ExecuteReader();
                }
                catch
                { throw (new Exception("ExecuteRead Error")); }

                try
                {
                    while (dataReader.Read())
                    {
                        ArchiveControl.addStat(DictDYears, dataReader.GetString(1), dataReader.GetInt32(0));
                    }
                }
                catch
                { throw (new Exception("Read Error")); }

                try
                {
                    dataReader.Close();
                    connection.Close();
                }
                catch
                { throw (new Exception("Close Error")); }
            }
            catch (Exception ex)
            {
                Console.WriteLine("========================================");
                Console.WriteLine("CollectClass.cs");
                Console.WriteLine("Cdyears()  :  " + DateTime.Now.ToString());
                Console.WriteLine(ex.ToString());
            }
        }
Exemplo n.º 10
0
 public Dictionary<int,string> Get_db_Gosts()
 {
     var gosts = new Dictionary<int, string>();
     try
     {
         Connection connection = new Connection();
         connection.Open();
         MySqlCommand myCommand = new MySqlCommand("SELECT Id_Gost, NameGost FROM gosts WHERE active = 1", connection.mySqlConnection);
         MySqlDataReader dataReader = (MySqlDataReader)myCommand.ExecuteReader();
         while (dataReader.Read())
         {
             gosts.Add(dataReader.GetInt32(0), dataReader.GetString(1)); ;
         }
         dataReader.Close();
         connection.Close();
     }
     catch (Exception ex)
     {
         throw (ex);
     }
     return gosts;
 }
Exemplo n.º 11
0
        public void fill_dg_Conformity()
        {
            try
            {
                Connection connection = new Connection();
                connection.Open();
                MySqlCommand myCommand = new MySqlCommand(@"
SELECT
  bufferdata.Id AS 'ID'
, sizetubes.SizeTube AS 'Диаметр трубы'
, gosts.NameGost AS 'Название ГОСТа'
FROM bufferdata
Inner Join gosts ON gosts.Id_Gost = bufferdata.Id_Gost
Inner Join sizetubes ON sizetubes.Id_SizeTube = bufferdata.Id_SizeTube
WHERE bufferdata.active = 1
", connection.mySqlConnection);
                MySqlDataAdapter dataAdapter = new MySqlDataAdapter(myCommand.CommandText, connection.mySqlConnection);
                DataSet dSet = new DataSet();
                dataAdapter.Fill(dSet);
                dg_Conformity.ItemsSource = dSet.Tables[0].DefaultView;
                Combobox_Conformity_Name.ItemsSource = Get_db_Gosts();
                Combobox_Conformity_d.ItemsSource = Get_Db_SizeTubes();
                connection.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
Exemplo n.º 12
0
        private void Button_Conformity_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Connection connection = new Connection();
                connection.Open();
                MySqlCommand myCommand = new MySqlCommand(@"
INSERT
INTO bufferdata (Id_Gost, Id_SizeTube)
VALUES (@Id_Gost, @Id_SizeTube)
", connection.mySqlConnection);
                myCommand.Parameters.Clear();
                myCommand.Parameters.AddWithValue("Id_Gost", ((KeyValuePair<int, string>)Combobox_Conformity_Name.SelectedItem).Key);
                myCommand.Parameters.AddWithValue("Id_SizeTube", ((KeyValuePair<int, string>)Combobox_Conformity_d.SelectedItem).Key);
                myCommand.ExecuteNonQuery();
                connection.Close();
                fill_dg_Conformity();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
Exemplo n.º 13
0
        public void fill_dg_Sensors()
        {
            try
            {
                Connection connection = new Connection();
                connection.Open();
                MySqlCommand myCommand = new MySqlCommand(@"
SELECT
  Id_Sensor AS 'ID'
, NameSensor AS 'Название датчика'
FROM sensors
WHERE active = 1
", connection.mySqlConnection);
                MySqlDataAdapter dataAdapter = new MySqlDataAdapter(myCommand.CommandText, connection.mySqlConnection);
                DataSet dSet = new DataSet();
                dataAdapter.Fill(dSet);
                dg_Sensors.ItemsSource = dSet.Tables[0].DefaultView;
                connection.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
Exemplo n.º 14
0
        private void Button_AddSensors_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var txtName = Textbox_Sensors.Text;
                if (txtName.Trim() != "")
                {
                    Connection connection = new Connection();
                    connection.Open();
                    MySqlCommand myCommand = new MySqlCommand(@"
INSERT
INTO sensors (NameSensor)
VALUES (@NameSensor)
", connection.mySqlConnection);
                    myCommand.Parameters.Clear();
                    myCommand.Parameters.AddWithValue("NameSensor", txtName);
                    myCommand.ExecuteNonQuery();
                    connection.Close();
                    fill_dg_Sensors();
                }
                else
                {
                    System.Windows.Forms.MessageBox.Show("Все поля обязательны для заполнения");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
Exemplo n.º 15
0
 public Dictionary<int, string> Get_Db_SizeTubes()
 {
     var sizeTubes = new Dictionary<int, string>();
     try
     {
         Connection connection = new Connection();
         connection.Open();
         MySqlCommand myCommand = new MySqlCommand("SELECT Id_SizeTube, SizeTube FROM sizetubes WHERE active = 1", connection.mySqlConnection);
         MySqlDataReader dataReader = (MySqlDataReader)myCommand.ExecuteReader();
         while (dataReader.Read())
         {
             sizeTubes.Add(dataReader.GetInt32(0), dataReader.GetString(1));
         }
         dataReader.Close();
         connection.Close();
     }
     catch (Exception ex)
     {
         throw (ex);
     }
     return sizeTubes;
 }
Exemplo n.º 16
0
        public Int64 lastIndex_defectsdata()
        {
            Int64 index = 0;
            Connection connection = new Connection();
            try { connection.Open(); } catch (Exception ex)
            {
                throw (ex);
            }
            MySqlCommand myCommand = new MySqlCommand(@"
SELECT IndexData
FROM defectsdata
ORDER BY IndexData DESC
LIMIT 1", connection.mySqlConnection);
            MySqlDataReader myRead = null;
            try
            {
                myRead = (MySqlDataReader)myCommand.ExecuteReader();
                myRead.Read();
                index = myRead.GetInt64(0);
                myRead.Close();
                myRead.Dispose();
            } catch
            {
                Console.WriteLine("========================================");
                Console.WriteLine("Write_NewTube.cs");
                Console.WriteLine("lastIndex_defectsdata()  :  " + DateTime.Now.ToString());
            }
            return index;
        }
Exemplo n.º 17
0
        //==
        public void SaveSample()
        {
            Connection connection = new Connection();
            if ((mainWindow.Parameters.Count == 12) && (mainWindow.Parameters2.Count == 1))
            {
                int hasDeffect = 0;
                //                defectsdata
                try
                {
                    connection.Open();
                }
                catch
                {
                    Console.WriteLine("========================================");
                    Console.WriteLine("Write.cs");
                    Console.WriteLine("SaveSample()  :  " + DateTime.Now.ToString());
                    Console.WriteLine("Open for \"INSERT INTO defectsdata\"");
                }
                MySqlCommand myCommand = new MySqlCommand(@"
INSERT INTO defectsdata
(NumberPart, NumberTube, NumberSegments, DataSensors, DatePr, TimePr, Porog, Current, FlDefectTube)
VALUES
(@A, @B, @C, @D, @E, @F, @G, @H, @I)",
connection.mySqlConnection);
                myCommand.Parameters.Clear();
                // номер партии
                myCommand.Parameters.AddWithValue("A", mainWindow.Parameters["part"]);
                // порог
                myCommand.Parameters.AddWithValue("G", mainWindow.Parameters["porog"]);
                // ток
                myCommand.Parameters.AddWithValue("H", mainWindow.Parameters["current"]);
                // маркировка - образец
                myCommand.Parameters.AddWithValue("B", 0);
                // размер образца
                myCommand.Parameters.AddWithValue("C", 40);
                // дефекты
                Byte[] deffectsArray = new Byte[40];
                for (int k = 0; k < deffectsArray.Length; k++)
                {
                    if (sampleDataBytes[k] != 0) hasDeffect = 1;
                    deffectsArray[k] = sampleDataBytes[k];
                }
                myCommand.Parameters.AddWithValue("D", deffectsArray);
                // дата время
                DateTime theDateTime = DateTime.Now;
                myCommand.Parameters.AddWithValue("E", theDateTime.ToString("yyyy-MM-dd"));
                myCommand.Parameters.AddWithValue("F", theDateTime.ToString("H:mm:ss"));
                // наличие дефектов
                myCommand.Parameters.AddWithValue("I", hasDeffect);
                try
                {
                    myCommand.ExecuteNonQuery();
                }
                catch
                {
                    Console.WriteLine("========================================");
                    Console.WriteLine("Write.cs");
                    Console.WriteLine("SaveSample()  :  " + DateTime.Now.ToString());
                    Console.WriteLine("\"INSERT INTO defectsdata\"");
                }
                try
                {
                    connection.Close();
                }
                catch
                {
                    Console.WriteLine("========================================");
                    Console.WriteLine("Write.cs");
                    Console.WriteLine("SaveSample()  :  " + DateTime.Now.ToString());
                    Console.WriteLine("Close for \"INSERT INTO defectsdata\"");
                }
                try
                {
                    connection.Open();
                }
                catch
                {
                    Console.WriteLine("========================================");
                    Console.WriteLine("Write.cs");
                    Console.WriteLine("SaveSample()  :  " + DateTime.Now.ToString());
                    Console.WriteLine("Open for \"INSERT INTO indexes\"");
                }
                //        indexes
                myCommand = new MySqlCommand(@"
INSERT INTO indexes
(Version
, IndexData
, Id_SizeTube
, Id_Gost
, Id_ControlSample
, Id_WorkSmen
, Id_TimeIntervalSmen
, Id_Operator1
, Id_Operator2
, Id_Device
, Id_Sensor
, Id_NameDefect
)
VALUES
(2
, (SELECT IndexData FROM defectsdata ORDER BY IndexData DESC LIMIT 1)
, @Id_SizeTube
, @Id_Gost
, @Id_ControlSample
, @Id_WorkSmens
, @Id_TimeIntervalSmen
, @Id_Operator1
, @Id_Operator2
, @Id_Device
, @Id_Sensor
, @Id_NameDefect
)", connection.mySqlConnection);
                myCommand.Parameters.AddWithValue("Id_SizeTube", mainWindow.Parameters["diameter"]);
                myCommand.Parameters.AddWithValue("Id_Gost", mainWindow.Parameters["gost"]);
                myCommand.Parameters.AddWithValue("Id_ControlSample", (int)mainWindow.Parameters["control_sample"]);
                myCommand.Parameters.AddWithValue("Id_WorkSmens", mainWindow.Parameters["smena"]);
                myCommand.Parameters.AddWithValue("Id_TimeIntervalSmen", mainWindow.Parameters["smena_time"]);
                myCommand.Parameters.AddWithValue("Id_Operator1", mainWindow.Parameters["operator1"]);
                myCommand.Parameters.AddWithValue("Id_Operator2", mainWindow.Parameters["operator2"]);
                myCommand.Parameters.AddWithValue("Id_Device", mainWindow.Parameters["device"]);
                myCommand.Parameters.AddWithValue("Id_Sensor", mainWindow.Parameters2["ho"]);
                myCommand.Parameters.AddWithValue("Id_NameDefect", mainWindow.Parameters["name_defect"]);
                try
                {
                    myCommand.ExecuteNonQuery();
                }
                catch
                {
                    Console.WriteLine("========================================");
                    Console.WriteLine("Write.cs");
                    Console.WriteLine("SaveSample()");
                    Console.WriteLine("\"INSERT INTO indexes\"");
                }
                try
                {
                    connection.Close();
                }
                catch
                {
                    Console.WriteLine("========================================");
                    Console.WriteLine("Write.cs");
                    Console.WriteLine("SaveSample()");
                    Console.WriteLine("Close for \"INSERT INTO indexes\"");
                }
            }
        }
Exemplo n.º 18
0
        private void Button_AddVremSmens_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var txtBegin = UpDn_VremSmens_Begin.Text;
                var txtEnd = UpDn_VremSmens_End.Text;
                if (txtBegin.Trim() != "" &&
                    txtEnd.Trim() != "")
                {
                    Connection connection = new Connection();
                    connection.Open();
                    MySqlCommand myCommand = new MySqlCommand(@"
INSERT INTO
timeintervalsmens (TimeIntervalSmen)
VALUES (@TimeIntervalSmen)
", connection.mySqlConnection);
                    myCommand.Parameters.Clear();
                    myCommand.Parameters.AddWithValue("TimeIntervalSmen", txtBegin + "-" + txtEnd);
                    myCommand.ExecuteNonQuery();
                    connection.Close();
                    fill_dg_VermSmens();
                }
                else
                {
                    System.Windows.Forms.MessageBox.Show("Все поля обязательны для заполнения");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
Exemplo n.º 19
0
        //===========================================
        // за смену дефектных труб
        public void Cdsmens(Dictionary<string, string> DictDSmens)
        {
            Connection connection = null;
            MySqlCommand myCommand = null;
            MySqlDataReader dataReader = null;

            try
            {
                try
                {
                    connection = new Connection();
                    connection.Open();
                }
                catch
                { throw (new Exception("Open Error")); }

                try
                {
                    myCommand = new MySqlCommand(@"
SELECT
Count(defectsdata.IndexData),
CONCAT(DATE_FORMAT(defectsdata.DatePr, '%Y-%m-%d'), '|', indexes.Id_WorkSmen)
FROM defectsdata
Inner Join indexes ON defectsdata.IndexData = indexes.IndexData
WHERE
defectsdata.IndexData <= @I
AND
defectsdata.FlDefectTube = 1
AND
defectsdata.NumberTube <> 0
GROUP BY
defectsdata.DatePr,
indexes.Id_WorkSmen
", connection.mySqlConnection);
                    myCommand.Parameters.Clear();
                    myCommand.Parameters.AddWithValue("I", MainWindow.ac.lastIndex);
                }
                catch
                { throw (new Exception("MySqlCommand Error")); }

                try
                {
                    dataReader = (MySqlDataReader)myCommand.ExecuteReader();
                }
                catch
                { throw (new Exception("ExecuteRead Error")); }

                try
                {
                    while (dataReader.Read())
                    {
                        ArchiveControl.addStat(DictDSmens, dataReader.GetString(1), dataReader.GetInt32(0));
                    }
                }
                catch
                { throw (new Exception("Read Error")); }

                try
                {
                    dataReader.Close();
                    connection.Close();
                }
                catch
                { throw (new Exception("Close Error")); }

            }
            catch (Exception ex)
            {
                Console.WriteLine("========================================");
                Console.WriteLine("CollectClass.cs");
                Console.WriteLine("Cdsmens()  :  " + DateTime.Now.ToString());
                Console.WriteLine(ex.ToString());
            }
        }
Exemplo n.º 20
0
        public void fill_dg_VermSmens()
        {
            try
            {
                Connection connection = new Connection();
                connection.Open();
                MySqlCommand myCommand = new MySqlCommand(@"
SELECT
  Id_TimeIntervalSmen AS 'ID'
, TimeIntervalSmen AS 'Время'
FROM timeintervalsmens
WHERE active = 1
", connection.mySqlConnection);
                DataSet dSet = new DataSet();
                MySqlDataAdapter dataAdapter = new MySqlDataAdapter(myCommand.CommandText, connection.mySqlConnection);
                dataAdapter.Fill(dSet);
                dg_VremSmens.ItemsSource = dSet.Tables[0].DefaultView;
                connection.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
Exemplo n.º 21
0
//=================================================================
        public void Expander(RoutedEventArgs e)
        {
            Mouse.OverrideCursor = Cursors.Wait;
            Connection connection = null;
            MySqlCommand myCommand = null;
            try
            {
                connection = new Connection();
                connection.Open();
                var item = (TreeViewItem)e.OriginalSource;
                item.Items.Clear();
                #region Tag year
                if (item.Tag.ToString() == "year")
                {
                    try
                    {
                        myCommand = new MySqlCommand(@"
SELECT DISTINCT
DATE_FORMAT(DatePr, '%Y-%m')
FROM defectsdata
WHERE
YEAR(DatePr) = @Yr
", connection.mySqlConnection);
                        myCommand.Parameters.Clear();
                        myCommand.Parameters.AddWithValue("Yr", item.Uid);
                        MySqlDataReader dataReader = (MySqlDataReader)myCommand.ExecuteReader();
                        while (dataReader.Read())
                        {
                            var itemMonth = new TreeViewItem
                            {
                                Uid = dataReader.GetString(0),
                                Tag = "month",
                                Header = dataReader.GetString(0),
                                ItemContainerStyle = archiveWindow.TreeView_arc.ItemContainerStyle
                            };
                            itemMonth.Items.Add("*");
                            item.Items.Add(itemMonth);
                        }
                        dataReader.Close();
                    } catch { throw (new Exception("year")); }
                }
                #endregion
                #region Tag month
                if (item.Tag.ToString()== "month")
                {
                    try
                    {
                        myCommand = new MySqlCommand(@"
SELECT DISTINCT
DATE_FORMAT(DatePr, '%Y-%m-%d')
FROM defectsdata
WHERE
DATE_FORMAT(DatePr, '%Y-%m') = @Yr
", connection.mySqlConnection);
                        myCommand.Parameters.Clear();
                        myCommand.Parameters.AddWithValue("Yr", item.Uid);
                        MySqlDataReader dataReader = (MySqlDataReader)myCommand.ExecuteReader();
                        while (dataReader.Read())
                        {
                            var itemDay = new TreeViewItem
                            {
                                Uid = dataReader.GetString(0),
                                Tag = "day",
                                Header = dataReader.GetString(0),
                                ItemContainerStyle = archiveWindow.TreeView_arc.ItemContainerStyle
                            };
                            itemDay.Items.Add("*");
                            item.Items.Add(itemDay);
                        }
                        dataReader.Close();
                    }
                    catch { throw (new Exception("month")); }
                }
                #endregion
                #region Tag day
                if (item.Tag.ToString() == "day")
                {
                    try
                    {
                        myCommand = new MySqlCommand(@"
SELECT DISTINCT
worksmens.NameSmen,
DATE_FORMAT(defectsdata.DatePr, '%Y-%M-%d'),
DATE_FORMAT(defectsdata.DatePr, '%Y-%m-%d'),
indexes.Id_WorkSmen
FROM indexes
INNER JOIN defectsdata ON defectsdata.IndexData = indexes.IndexData
INNER JOIN worksmens ON worksmens.Id_WorkSmen = indexes.Id_WorkSmen
WHERE
defectsdata.DatePr = @A
", connection.mySqlConnection);
                        //ORDER BY worksmens.NameSmen
                        //";
                        myCommand.Parameters.Clear();
                        myCommand.Parameters.AddWithValue("A", item.Uid);
                        MySqlDataReader dataReader = (MySqlDataReader)myCommand.ExecuteReader();
                        while (dataReader.Read())
                        {
                            var itemSmens = new TreeViewItem
                            {
                                Uid = dataReader.GetString(2) + "|" + dataReader.GetString(3) + "+" + dataReader.GetString(2) + " / " + dataReader.GetString(0),
                                Tag = "smena",
                                Header = dataReader.GetString(0),
                                ItemContainerStyle = archiveWindow.TreeView_arc.ItemContainerStyle
                            };
                            itemSmens.Items.Add("*");
                            item.Items.Add(itemSmens);
                        }
                        dataReader.Close();
                    }
                    catch { throw (new Exception("day")); }
                }
                #endregion
                #region Tag smena
                if (item.Tag.ToString() == "smena")
                {
                    try
                    {
                        myCommand = new MySqlCommand(@"
SELECT DISTINCT
defectsdata.NumberPart,
DATE_FORMAT(defectsdata.DatePr, '%Y-%m-%d'),
indexes.Id_WorkSmen,
worksmens.NameSmen
FROM indexes
INNER JOIN defectsdata ON defectsdata.IndexData = indexes.IndexData
INNER JOIN worksmens ON worksmens.Id_WorkSmen = indexes.Id_WorkSmen
WHERE
defectsdata.DatePr = @A
AND
worksmens.Id_WorkSmen = @B
", connection.mySqlConnection);
                        myCommand.Parameters.Clear();
                        myCommand.Parameters.AddWithValue("A", item.Uid.Split('|')[0]);
                        myCommand.Parameters.AddWithValue("B", item.Uid.Split('|')[1]);
                        MySqlDataReader dataRead = (MySqlDataReader)myCommand.ExecuteReader();
                        while (dataRead.Read())
                        {
                            var itemPart = new TreeViewItem
                            {
                                Uid = dataRead.GetString(0) + "|" + dataRead.GetString(1) + "|"
                                + dataRead.GetString(2) + "|" + dataRead.GetString(1) + "/"
                                + dataRead.GetString(3) + " / плавка " + dataRead.GetString(0),
                                Tag = "part",
                                Header = "Плавка № " + dataRead.GetString(0),
                                ItemContainerStyle = archiveWindow.TreeView_arc.ItemContainerStyle
                            };
                            itemPart.Items.Add("*");
                            item.Items.Add(itemPart);
                        }
                        dataRead.Close();
                    }
                    catch { throw (new Exception("smena")); }
                }
                #endregion
                #region Tag part
                if (item.Tag.ToString()=="part")
                {
                    try
                    {
                        myCommand = new MySqlCommand(@"
SELECT
defectsdata.NumberTube,
defectsdata.FlDefectTube,
defectsdata.TimePr,
defectsdata.IndexData
FROM indexes
INNER JOIN defectsdata ON defectsdata.IndexData = indexes.IndexData
INNER JOIN worksmens ON worksmens.Id_WorkSmen = indexes.Id_WorkSmen
WHERE
defectsdata.DatePr = @A
AND
worksmens.Id_WorkSmen = @B
AND
defectsdata.NumberPart = @C
", connection.mySqlConnection);
                        myCommand.Parameters.Clear();
                        myCommand.Parameters.AddWithValue("A", item.Uid.Split('|')[1]);
                        myCommand.Parameters.AddWithValue("B", item.Uid.Split('|')[2]);
                        myCommand.Parameters.AddWithValue("C", item.Uid.Split('|')[0]);
                        MySqlDataReader dataReader = (MySqlDataReader)myCommand.ExecuteReader();

                        while (dataReader.Read())
                        {
                            var itemTube = new TreeViewItem
                            {
                                Uid = dataReader.GetString(3),
                                Tag = "tube0",
                                Header = "Труба №" + dataReader.GetString(0),
                                ItemContainerStyle = archiveWindow.TreeView_arc.ItemContainerStyle
                            };
                            if (dataReader.GetInt32(0) == 0)
                            {
                                itemTube.Header = "К.О. (" + dataReader.GetString(2) + ")";
                            }
                            if (dataReader.GetInt32(1) == 1)
                            {
                                var colBrush = new SolidColorBrush
                                {
                                    Color = Colors.Red
                                };
                                itemTube.Tag = "tube1";
                                itemTube.Foreground = colBrush;
                            }
                            item.Items.Add(itemTube);
                        }
                        dataReader.Close();
                    }
                    catch { throw (new Exception("part")); }
                }
                #endregion
            }
            catch (Exception ex)
            {
                Console.WriteLine("========================================");
                Console.WriteLine("ArchiveControl.cs");
                Console.WriteLine("Expander()  :  " + DateTime.Now.ToString());
                Console.WriteLine(ex);
            }
            Mouse.OverrideCursor = Cursors.Arrow;
            try { connection.Close(); connection = null; } catch { }
        }
Exemplo n.º 22
0
        private void Button_AddArtificialDefect_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var txtName = Textbox_ArtificialDefect.Text;
                if (txtName.Trim() != "")
                {
                    Connection connection = new Connection();
                    connection.Open();
                    MySqlCommand myCommand = new MySqlCommand(@"
INSERT INTO
listdefects (NameDefect)
VALUES (@NameDefect)
", connection.mySqlConnection);
                    myCommand.Parameters.Clear();
                    myCommand.Parameters.AddWithValue("NameDefect", txtName);
                    myCommand.ExecuteNonQuery();
                    connection.Close();
                    fill_dg_ArtificialDefect();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
Exemplo n.º 23
0
        //=======================================

        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            //var worker = sender as BackgroundWorker;
            CollectClass collectClass = new CollectClass();

            _countsLoaded = false;
            _countLastIndex = 0;

            _countYears.Clear();
            _countDefectsYears.Clear();
            _countMonths.Clear();
            _countDefectsMonths.Clear();
            _countDays.Clear();
            _countDefectsDays.Clear();
            _countSmens.Clear();
            _countDefectsSmens.Clear();
            _countParts.Clear();
            _countDefectsParts.Clear();

            Connection connection = null;
            MySqlCommand myCommand = null;
            MySqlDataReader dataReader = null;

            try
            {
                Console.WriteLine("Begin load Statistic " + DateTime.Now.ToString());
                #region last index
                try
                {
                    connection = new Connection();
                    connection.Open();
                }
                catch
                { throw (new Exception("Open Error")); }

                try
                {
                    myCommand = new MySqlCommand(@"
SELECT IndexData
FROM defectsdata
ORDER BY IndexData DESC
LIMIT 1", connection.mySqlConnection);
                }
                catch
                { throw (new Exception("Open Error")); }

                try
                {
                    dataReader = (MySqlDataReader)myCommand.ExecuteReader();
                    dataReader.Read();
                    _countLastIndex = dataReader.GetInt64(0);
                }
                catch
                { throw (new Exception("Read Error")); }

                try
                {
                    dataReader.Close();
                    connection.Close();
                }
                catch
                { throw (new Exception("Close Error")); }
                #endregion

                collectClass.Cyears(_countYears);
                collectClass.Cdyears(_countDefectsYears);
                collectClass.Cmonths(_countMonths);
                collectClass.Cdmonths(_countDefectsMonths);
                collectClass.Cdays(_countDays);
                collectClass.Cddays(_countDefectsDays);
                collectClass.Csmens(_countSmens);
                collectClass.Cdsmens(_countDefectsSmens);
                collectClass.Cparts(_countParts);
                collectClass.cdparts(_countDefectsParts);
                Console.WriteLine("End load Statistic " + DateTime.Now.ToString());
            }
            catch (Exception ex)
            {
                /*Console.WriteLine("========================================");
                Console.WriteLine("ArchiveControl.cs");
                Console.WriteLine("backgroundWorker1_DoWork()  :  " + DateTime.Now.ToString());
                Console.WriteLine(ex.Message);*/
                MessageBox.Show("Ошибка загрузки статистики");
                if (MainWindow.mainWindow.myThrArchive != null)
                {
                    archiveWindow.buttonReload.IsEnabled = true;
                }
            }
        }
Exemplo n.º 24
0
        public void fill_dg_ArtificialDefect()
        {
            try
            {
                Connection connection = new Connection();
                connection.Open();
                MySqlCommand myCommand = new MySqlCommand(@"
SELECT
  Id_NameDefect AS 'ID'
, NameDefect AS 'Искуственный дефект'
FROM listdefects
WHERE active = 1
", connection.mySqlConnection);
                DataSet dSet = new DataSet();
                MySqlDataAdapter dataAdapter = new MySqlDataAdapter(myCommand.CommandText, connection.mySqlConnection);
                dataAdapter.Fill(dSet);
                dg_ArtificialDefect.ItemsSource = dSet.Tables[0].DefaultView;
                connection.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
Exemplo n.º 25
0
 public int GetDb_Last_NumberTube()
 {
     int last = 0;
     if (MainWindow.mainWindow.Parameters["part"] == GetDb_Last_Part())
     {
         Connection connection = new Connection();
         try
         {
             connection = new Connection();
             connection.Open();
         } catch (Exception ex)
         {
             Console.WriteLine("========================================");
             Console.WriteLine("Parameters.cs");
             Console.WriteLine("GetDb_Last_NumberTube()  :  " + DateTime.Now.ToString());
             Console.WriteLine("Open BD");
             throw (ex);
         }
         MySqlCommand myCommand = new MySqlCommand(@"
         SELECT
         defectsdata.NumberTube
         FROM
         defectsdata
         ORDER BY
         defectsdata.IndexData DESC
         LIMIT 1", connection.mySqlConnection);
         MySqlDataReader mySqlReader = null;
         try
         {
             mySqlReader = (MySqlDataReader)myCommand.ExecuteReader();
         } catch (Exception ex)
         {
             Console.WriteLine("========================================");
             Console.WriteLine("Parameters.cs");
             Console.WriteLine("GetDb_Last_NumberTube()  :  " + DateTime.Now.ToString());
             Console.WriteLine("ExecuteReader");
             throw (ex);
         }
         try
         {
             while (mySqlReader.Read())
             {
                 last = mySqlReader.GetInt32(0);
             }
         } catch (Exception ex)
         {
             Console.WriteLine("========================================");
             Console.WriteLine("Parameters.cs");
             Console.WriteLine("GetDb_Last_NumberTube()  :  " + DateTime.Now.ToString());
             Console.WriteLine("Read");
             throw (ex);
         }
         try
         {
             mySqlReader.Close();
             connection.Close();
             connection = null;
         } catch (Exception ex)
         {
             Console.WriteLine("========================================");
             Console.WriteLine("Parameters.cs");
             Console.WriteLine("GetDb_Last_NumberTube()  :  " + DateTime.Now.ToString());
             Console.WriteLine("Close BD");
             throw (ex);
         }
     }
     return last;
 }
Exemplo n.º 26
0
        //
        public void fill_dg_Specs()
        {
            try
            {
                Connection connection = new Connection();
                connection.Open();
                MySqlCommand mySqlCommand = new MySqlCommand(@"
SELECT
 Id_Operator AS 'ID'
,Surname AS 'ФИО'
,LevelMD AS 'Уровень MD'
,LevelUSD AS 'Уровень USD'
FROM operators
WHERE active = 1", connection.mySqlConnection);
                var dataAdapter = new MySqlDataAdapter(mySqlCommand.CommandText, connection.mySqlConnection);
                var dSet = new DataSet();
                dataAdapter.Fill(dSet);
                //
                dg_Specs.ItemsSource = dSet.Tables[0].DefaultView;
                connection.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
Exemplo n.º 27
0
 public Dictionary<int, string> GetDb_ControlSamplesCurrent(int id)
 {
     var controlSamples = new Dictionary<int, string>();
     Connection connection = null;
     try
     {
         connection = new Connection();
         connection.Open();
     } catch (Exception ex)
     {
         Console.WriteLine("========================================");
         Console.WriteLine("Parameters.cs");
         Console.WriteLine("Dictionary GetDb_ControlSamplesCurrent()  :  " + DateTime.Now.ToString());
         Console.WriteLine("Open BD");
         throw (ex);
     }
     MySqlCommand myCommand = new MySqlCommand(@"
         SELECT
         controlsamples.Id_ControlSample,
         controlsamples.NameControlSample
         FROM
         controlsamples
         WHERE controlsamples.Id_SizeTube = @A", connection.mySqlConnection);
     try
     {
         myCommand.Parameters.AddWithValue("A", id);
     } catch (Exception ex)
     {
         Console.WriteLine("========================================");
         Console.WriteLine("Parameters.cs");
         Console.WriteLine("Dictionary GetDb_ControlSamplesCurrent()  :  " + DateTime.Now.ToString());
         Console.WriteLine("Add Parameters");
         throw (ex);
     }
     MySqlDataReader mySqlReader = null;
     try
     {
         mySqlReader = (MySqlDataReader)myCommand.ExecuteReader();
     } catch (Exception ex)
     {
         Console.WriteLine("========================================");
         Console.WriteLine("Parameters.cs");
         Console.WriteLine("Dictionary GetDb_ControlSamplesCurrent()  :  " + DateTime.Now.ToString());
         Console.WriteLine("ExecuteReader");
         throw (ex);
     }
     try
     {
         while (mySqlReader.Read())
         {
             controlSamples.Add(
                 mySqlReader.GetInt32(0),
                 mySqlReader.GetString(1));
         }
     } catch (Exception ex)
     {
         Console.WriteLine("========================================");
         Console.WriteLine("Parameters.cs");
         Console.WriteLine("Dictionary GetDb_ControlSamplesCurrent()  :  " + DateTime.Now.ToString());
         Console.WriteLine("Read");
         throw (ex);
     }
     try
     {
         mySqlReader.Close();
         connection.Close();
         connection = null;
     } catch (Exception ex)
     {
         Console.WriteLine("========================================");
         Console.WriteLine("Parameters.cs");
         Console.WriteLine("Dictionary GetDb_ControlSamplesCurrent()  :  " + DateTime.Now.ToString());
         Console.WriteLine("Close BD");
         throw (ex);
     }
     return controlSamples;
 }
Exemplo n.º 28
0
        //=================================================================================================================
        private int LastNumberTube(int part)
        {
            int last = 0;
            Connection connection = new Connection();
            try { connection.Open(); } catch
            {
                Console.WriteLine("========================================");
                Console.WriteLine("Write.cs");
                Console.WriteLine("LastNumberTube()");
                Console.WriteLine("Open for ExecuteReader");
            }
            MySqlCommand myCommand = new MySqlCommand(@"
SELECT
NumberTube, NumberPart
FROM defectsdata
WHERE NumberTube<>0
ORDER BY IndexData DESC
LIMIT 1", connection.mySqlConnection);
            MySqlDataReader mySqlReader = null; ;
            try
            {
                mySqlReader = (MySqlDataReader)myCommand.ExecuteReader();
            }
            catch
            {
                Console.WriteLine("========================================");
                Console.WriteLine("Write.cs");
                Console.WriteLine("LastNumberTube()");
                Console.WriteLine("ExecuteReader");
            }
            while (mySqlReader.Read())
            {
                try
                {
                    if ((mySqlReader.GetValue(mySqlReader.GetOrdinal("NumberTube")) == null) || (mySqlReader.GetInt32(mySqlReader.GetOrdinal("NumberPart")) != part))
                        last = 0;
                    else
                        last = mySqlReader.GetInt32(mySqlReader.GetOrdinal("NumberTube"));
                }
                catch
                {
                    Console.WriteLine("========================================");
                    Console.WriteLine("Write.cs");
                    Console.WriteLine("LastNumberTube()");
                    Console.WriteLine("ExecuteReader - READ NumberTube, NumberPart, NumberTube");
                }
            }
            try { mySqlReader.Close(); connection.Close(); }
            catch
            {
                Console.WriteLine("========================================");
                Console.WriteLine("Write.cs");
                Console.WriteLine("LastNumberTube()");
                Console.WriteLine("Close for ExecuteReader");
            }
            return last;
        }
Exemplo n.º 29
0
 public int GetDb_Last_SizeTubes()
 {
     int last = 0;
     Connection connection = null;
     try
     {
         connection = new Connection();
         connection.Open();
     } catch (Exception ex)
     {
         Console.WriteLine("========================================");
         Console.WriteLine("Parameters.cs");
         Console.WriteLine("GetDb_Last_SizeTubes()  :  " + DateTime.Now.ToString());
         Console.WriteLine("Open BD");
         throw (ex);
     }
     MySqlCommand myCommand = new MySqlCommand(@"
         SELECT
         indexes.Id_SizeTube
         FROM
         indexes
         ORDER BY
         indexes.Ind DESC
         LIMIT 1", connection.mySqlConnection);
     MySqlDataReader mySqlReader = null;
     try
     {
         mySqlReader = (MySqlDataReader)myCommand.ExecuteReader();
     } catch (Exception ex)
     {
         Console.WriteLine("========================================");
         Console.WriteLine("Parameters.cs");
         Console.WriteLine("GetDb_Last_SizeTubes()  :  " + DateTime.Now.ToString());
         Console.WriteLine("ExecuteReader");
         throw (ex);
     }
     try
     {
         while (mySqlReader.Read())
         {
             last = mySqlReader.GetInt32(0);
         }
     } catch (Exception ex)
     {
         Console.WriteLine("========================================");
         Console.WriteLine("Parameters.cs");
         Console.WriteLine("GetDb_Last_SizeTubes()  :  " + DateTime.Now.ToString());
         Console.WriteLine("Read");
         throw (ex);
     }
     try
     {
         mySqlReader.Close();
         connection.Close();
         connection = null;
     } catch (Exception ex)
     {
         Console.WriteLine("========================================");
         Console.WriteLine("Parameters.cs");
         Console.WriteLine("GetDb_Last_SizeTubes()  :  " + DateTime.Now.ToString());
         Console.WriteLine("Close BD");
         throw (ex);
     }
     return last;
 }
Exemplo n.º 30
0
 public void DoIt(byte[] buffForRead, List<byte> bufferRecive)
 {
     if (bufferRecive.Count < Writer.minLenTube)
     {
         Console.WriteLine("========================================");
         Console.WriteLine("Write_NewTube.cs");
         Console.WriteLine("DoIt()  :  " + DateTime.Now.ToString());
         Console.WriteLine("Very small tube : "+((double)bufferRecive.Count/6.0).ToString()+"метров");
         return;
     }
     try
     {
         Connection connection = new Connection();
         try { connection.Open(); } catch
         {
             Console.WriteLine("========================================");
             Console.WriteLine("Write_NewTube.cs");
             Console.WriteLine("DoIt()  :  " + DateTime.Now.ToString());
             Console.WriteLine("Open()");
             throw (new Exception("Error Write new tube : open bd"));
         }
         {
             MySqlCommand myCommand = defectsdata_sql(connection.mySqlConnection);
             defectsdata_param(myCommand, bufferRecive);
             try { myCommand.ExecuteNonQuery(); }
             catch
             {
                 Console.WriteLine("========================================");
                 Console.WriteLine("Write_NewTube.cs");
                 Console.WriteLine("DoIt()  :  " + DateTime.Now.ToString());
                 Console.WriteLine("defectsdata ExecuteNonQuery()");
                 throw (new Exception("Error Write new tube : write defectsdata"));
             }
         }
         Int64 lastIndex = lastIndex_defectsdata();
         {
             MySqlCommand myCommand = indexes_sql(connection.mySqlConnection);
             indexes_param(myCommand, lastIndex);
             try { myCommand.ExecuteNonQuery(); } catch
             {
                 Console.WriteLine("========================================");
                 Console.WriteLine("Write_NewTube.cs");
                 Console.WriteLine("DoIt()  :  " + DateTime.Now.ToString());
                 Console.WriteLine("indexes ExecuteNonQuery()");
                 throw (new Exception("Error Write new tube : write indexes"));
             }
         }
         try { connection.Close(); } catch
         {
             Console.WriteLine("========================================");
             Console.WriteLine("Write_NewTube.cs");
             Console.WriteLine("DoIt()  :  " + DateTime.Now.ToString());
             Console.WriteLine("Close()");
             throw (new Exception("Error Write new tube : close bd"));
         }
     }
     catch (Exception ex)
     {
         throw (ex);
     }
 }