Exemplo n.º 1
0
        private static String SetLocalDefectIngot(Add_F Dialog)
        {
            String LocaDefectIngot = String.Empty;

            foreach (Control TypeControl in Dialog.splitContainer1.Panel2.Controls)
            {
                if (TypeControl is CheckBox)
                {
                    CheckBox Temp = TypeControl as CheckBox;

                    if (Temp.Checked)
                    {
                        LocaDefectIngot += Temp.Text + "_";
                    }
                }
                else
                {
                    continue;
                }
            }

            if (LocaDefectIngot != String.Empty && LocaDefectIngot[LocaDefectIngot.Length - 1] == '_')
            {
                LocaDefectIngot = LocaDefectIngot.Remove(LocaDefectIngot.Length - 1, 1);
            }

            return(LocaDefectIngot);
        }
Exemplo n.º 2
0
 private static void GetLocalDefectIngot(Add_F Dialog, String [] DefectLocIngot)
 {
     foreach (String Name in DefectLocIngot)
     {
         foreach (Control TypeControl in Dialog.splitContainer1.Panel2.Controls)
         {
             if (TypeControl is CheckBox)
             {
                 if (TypeControl.Text == Name)
                 {
                     (TypeControl as CheckBox).Checked = true;
                 }
             }
             else
             {
                 continue;
             }
         }
     }
 }
Exemplo n.º 3
0
        private static void SetComboBox(Add_F Dialog)
        {
            Dialog.NumBrigade_CB.DataSource    = SystemArgs.Brigades;
            Dialog.NumBrigade_CB.DisplayMember = "Name";
            Dialog.NumBrigade_CB.ValueMember   = "ID";

            Dialog.Description_CB.DataSource    = SystemArgs.Descriptions;
            Dialog.Description_CB.DisplayMember = "Name";
            Dialog.Description_CB.ValueMember   = "ID";

            Dialog.Diameter_CB.DataSource    = SystemArgs.Diameters;
            Dialog.Diameter_CB.DisplayMember = $"Name";
            Dialog.Diameter_CB.ValueMember   = "ID";

            Dialog.NumSmeny_CB.DataSource    = SystemArgs.Smeny;
            Dialog.NumSmeny_CB.DisplayMember = $"Name";
            Dialog.NumSmeny_CB.ValueMember   = "ID";

            Dialog.NumTS_CB.DataSource    = SystemArgs.TSN;
            Dialog.NumTS_CB.DisplayMember = $"Name";
            Dialog.NumTS_CB.ValueMember   = "ID";

            Dialog.TypeDefect_CB.DataSource    = SystemArgs.TypesDefect;
            Dialog.TypeDefect_CB.DisplayMember = $"Name";
            Dialog.TypeDefect_CB.ValueMember   = "ID";

            Dialog.TypeAlloy_CB.DataSource    = SystemArgs.TypesAlloy;
            Dialog.TypeAlloy_CB.DisplayMember = $"Name";
            Dialog.TypeAlloy_CB.ValueMember   = "ID";

            Dialog.LocationProduction_CB.DataSource    = SystemArgs.DefectLocProduction;
            Dialog.LocationProduction_CB.DisplayMember = $"Name";
            Dialog.LocationProduction_CB.ValueMember   = "ID";

            Dialog.ProgressMark_CB.DataSource    = SystemArgs.ProgressMark;
            Dialog.ProgressMark_CB.DisplayMember = $"Name";
            Dialog.ProgressMark_CB.ValueMember   = "ID";
        }
Exemplo n.º 4
0
        public static void ChangePosition(Position Position)
        {
            if (!SystemArgs.StatusConnect)
            {
                MessageBox.Show("Не удалось подключиться в базе данных", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                SystemArgs.PrintLog("Ошибка при подключении к БД");
                return;
            }

            Add_F Dialog = new Add_F();

            Dialog.Text = "Изменение параметров позиции";

            DateTime DateCreate = Position.DateCreate;

            SetComboBox(Dialog);

            Dialog.NumTS_CB.SelectedIndex              = SystemArgs.TSN.FindIndex(p => Position.NumTS.ID == p.ID);
            Dialog.Description_CB.SelectedIndex        = SystemArgs.Descriptions.FindIndex(p => Position.Description.ID == p.ID);
            Dialog.NumSmeny_CB.SelectedIndex           = SystemArgs.Smeny.FindIndex(p => Position.NumSmeny.ID == p.ID);
            Dialog.NumBrigade_CB.SelectedIndex         = SystemArgs.Brigades.FindIndex(p => Position.NumBrigade.ID == p.ID);
            Dialog.Diameter_CB.SelectedIndex           = SystemArgs.Diameters.FindIndex(p => Position.Diameter.ID == p.ID);
            Dialog.TypeDefect_CB.SelectedIndex         = SystemArgs.TypesDefect.FindIndex(p => Position.Defect.ID == p.ID);
            Dialog.TypeAlloy_CB.SelectedIndex          = SystemArgs.TypesAlloy.FindIndex(p => Position.TypeAlloy.ID == p.ID);
            Dialog.LocationProduction_CB.SelectedIndex = SystemArgs.DefectLocProduction.FindIndex(p => Position.DefectLocProduction.ID == p.ID);
            Dialog.ProgressMark_CB.SelectedIndex       = SystemArgs.ProgressMark.FindIndex(p => Position.ProgressMark.ID == p.ID);

            Dialog.Calendar_MC.SelectionStart = Position.DateFormation;
            Dialog.Address_TB.Text            = Position.Address;
            Dialog.Correction_TB.Text         = Position.Correction;
            Dialog.Count_TB.Text   = Position.Count.ToString();
            Dialog.NumMelt_TB.Text = Position.NumMelt;
            Dialog.Reason_TB.Text  = Position.Reason;
            Dialog.Weight_TB.Text  = Position.Weight.ToString();

            if (Position.DefectLocIngot != null)
            {
                String[] DefectLocIngot = Position.DefectLocIngot.Split('_');

                GetLocalDefectIngot(Dialog, DefectLocIngot);
            }

            SystemArgs.PrintLog("Получение текущих данных выбранного объекта успешно завершено");

            if (Dialog.ShowDialog() == DialogResult.OK)
            {
                String LocDefIngot = SetLocalDefectIngot(Dialog);

                using (var Connect = new NpgsqlConnection(SystemArgs.ConnectString))
                {
                    Connect.Open();

                    Position Temp = new Position(Position.ID, DateCreate, Dialog.Calendar_MC.SelectionStart.Date, Dialog.NumMelt_TB.Text.Trim(), Convert.ToInt64(Dialog.Count_TB.Text.Trim()),
                                                 Convert.ToDouble(Dialog.Weight_TB.Text.Trim()), LocDefIngot, Dialog.Correction_TB.Text.Trim(), Dialog.Address_TB.Text.Trim(), Dialog.Reason_TB.Text.Trim(), (TSN)Dialog.NumTS_CB.SelectedItem, (ListBrigades)Dialog.NumBrigade_CB.SelectedItem,
                                                 (DefectProduction)Dialog.LocationProduction_CB.SelectedItem, (ListSmen)Dialog.NumSmeny_CB.SelectedItem, (TypesDefect)Dialog.TypeDefect_CB.SelectedItem, (TypesAlloy)Dialog.TypeAlloy_CB.SelectedItem,
                                                 (DescriptionDefect)Dialog.Description_CB.SelectedItem, (DiameterIngot)Dialog.Diameter_CB.SelectedItem, (ProgressMark)Dialog.ProgressMark_CB.SelectedItem);

                    using (var Command = new NpgsqlCommand($"UPDATE public.\"Ingot\"" +
                                                           $"SET   \"SysDateCreate\" = '{Temp.DateCreate}', \"DateFormation\" ='{Temp.DateFormation}', \"NumMelt\" = '{Temp.NumMelt}', \"CountIngot\" = {Temp.Count}," +
                                                           $"  \"WeightIngots\" = {Temp.WeightDB}, \"DefectLocIngot\" = '{Temp.DefectLocIngot}', \"Correction\" = '{Temp.Correction}', \"Address\" = '{Temp.Address}'," +
                                                           $"  \"Reason\" ='{Temp.Reason}', \"NumTSN\" = {Temp.NumTS.ID}, \"NumBrigade\" = {Temp.NumBrigade.ID}, \"DefLocProduction\" = {Temp.DefectLocProduction.ID}," +
                                                           $"  \"NumSmen\" = {Temp.NumSmeny.ID}, \"Defect\" = {Temp.Defect.ID}, \"TypeAlloy\" = {Temp.TypeAlloy.ID}, \"Description\" = {Temp.Description.ID}, \"Diameter\" = {Temp.Diameter.ID}," +
                                                           $"  \"ProgressMark\" = {Temp.ProgressMark.ID}" +
                                                           $"WHERE \"ID\" = {Temp.ID};", Connect))
                    {
                        Command.ExecuteNonQuery();
                    }

                    SystemArgs.Positions.Remove(Position);
                    SystemArgs.Positions.Add(Temp);

                    Connect.Close();
                }

                SystemArgs.PrintLog("Изменение параметров позиции успешно завершено");
            }
        }
Exemplo n.º 5
0
        public static void AddPosition()
        {
            if (!SystemArgs.StatusConnect)
            {
                MessageBox.Show("Не удалось подключиться в базе данных", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                SystemArgs.PrintLog("Ошибка при подключении к БД");
                return;
            }

            try
            {
                Add_F Dialog = new Add_F();

                DateTime DateCreate = DateTime.Now;

                SetComboBox(Dialog);

                if (Dialog.ShowDialog() == DialogResult.OK)
                {
                    String LocDefIngot = SetLocalDefectIngot(Dialog);

                    Int64 ID = -1;

                    using (var Connect = new NpgsqlConnection(SystemArgs.ConnectString))
                    {
                        Connect.Open();

                        using (var Command = new NpgsqlCommand($"SELECT last_value FROM \"Ingot_ID_seq\"", Connect))
                        {
                            using (var Reader = Command.ExecuteReader())
                            {
                                while (Reader.Read())
                                {
                                    ID = Reader.GetInt64(0);
                                }
                            }
                        }

                        Position Temp = new Position(ID + 1, DateCreate, Dialog.Calendar_MC.SelectionStart.Date, Dialog.NumMelt_TB.Text.Trim(), Convert.ToInt64(Dialog.Count_TB.Text.Trim()),
                                                     Convert.ToDouble(Dialog.Weight_TB.Text.Trim()), LocDefIngot, Dialog.Correction_TB.Text.Trim(), Dialog.Address_TB.Text.Trim(), Dialog.Reason_TB.Text.Trim(), (TSN)Dialog.NumTS_CB.SelectedItem, (ListBrigades)Dialog.NumBrigade_CB.SelectedItem,
                                                     (DefectProduction)Dialog.LocationProduction_CB.SelectedItem, (ListSmen)Dialog.NumSmeny_CB.SelectedItem, (TypesDefect)Dialog.TypeDefect_CB.SelectedItem, (TypesAlloy)Dialog.TypeAlloy_CB.SelectedItem,
                                                     (DescriptionDefect)Dialog.Description_CB.SelectedItem, (DiameterIngot)Dialog.Diameter_CB.SelectedItem, (ProgressMark)Dialog.ProgressMark_CB.SelectedItem);

                        using (var Command = new NpgsqlCommand($"INSERT INTO public.\"Ingot\"(" +
                                                               "\"SysDateCreate\", \"DateFormation\", \"NumMelt\", \"CountIngot\", \"WeightIngots\", \"DefectLocIngot\", \"Correction\"," +
                                                               " \"Address\", \"Reason\", \"NumTSN\", \"NumBrigade\", \"DefLocProduction\", \"NumSmen\", \"Defect\", \"TypeAlloy\", \"Description\", \"Diameter\", \"ProgressMark\")" +
                                                               $"VALUES('{Temp.DateCreate}', '{Temp.DateFormation}', '{Temp.NumMelt}', {Temp.Count}, {Temp.WeightDB}, '{Temp.DefectLocIngot}', '{Temp.Correction}', '{Temp.Address}', '{Temp.Reason}' ," +
                                                               $" {Temp.NumTS.ID}, {Temp.NumBrigade.ID}, {Temp.DefectLocProduction.ID}, {Temp.NumSmeny.ID}, {Temp.Defect.ID}, {Temp.TypeAlloy.ID}, {Temp.Description.ID}, {Temp.Diameter.ID}, {Temp.ProgressMark.ID});", Connect))
                        {
                            Command.ExecuteNonQuery();
                        }

                        SystemArgs.Positions.Add(Temp);

                        Connect.Close();
                    }

                    SystemArgs.PrintLog("Добавление позиции успешно завершено");
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Ошибка при добавлении данных на сервер", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                SystemArgs.PrintLog("Ошибка при получении данных с сервера");
                return;
            }
        }