Beispiel #1
0
 public void GetActualVersion()
 {
     using (Network_SchemeEntities db = new Network_SchemeEntities(DBUtils.getConnString()))
     {
         try
         {
             if (db.Network_Versions.Count() == 0)
             {
                 version     = 0;
                 version_id  = 0;
                 starting_id = (version_id + 1) * 1000;
             }
             else
             {
                 Network_Versions version_obj = db.Network_Versions.FirstOrDefault
                                                    (p => p.ID == db.Network_Versions.Max(x => x.ID));
                 version     = version_obj.C_Version_Number;
                 version_id  = version_obj.ID;
                 starting_id = (version_id + 1) * 1000;
             }
         }
         catch
         {
             MessageBox.Show("Ошибка получения актуальной версии");
         }
     }
 }
        public void GetVersions()
        {
            label2.Text = "Версия: ";
            label4.Text = "Дата: ";
            using (Network_SchemeEntities db = new Network_SchemeEntities(DBUtils.getConnString()))
            {
                List <Network_Versions> db_versions;
                try
                {
                    db_versions = db.Network_Versions.OrderByDescending(p => p.C_Version_Number).ToList();
                }
                catch
                {
                    MessageBox.Show("Ошибка загрузки актуальной версии");
                    return;
                }

                List <Control> listControls = new List <Control>();
                foreach (Control control in flowLayoutPanel1.Controls)
                {
                    listControls.Add(control);
                }
                foreach (Control control in listControls)
                {
                    flowLayoutPanel1.Controls.Remove(control);
                    control.Dispose();
                }

                for (int i = 0; i < db_versions.Count; i++)
                {
                    Network_Versions db_version = db_versions[i];

                    Button button = new Button();
                    button.Size      = new Size(flowLayoutPanel1.Width - 6, 30);
                    button.Tag       = i;
                    button.BackColor = SystemColors.ButtonFace;
                    button.Text      = "Версия " + db_version.C_Version_Number;
                    flowLayoutPanel1.Controls.Add(button);

                    button.Click += delegate
                    {
                        workspace.LoadDB(db_version.ID, db_version.C_Version_Number);

                        label2.Text = "Версия: " + db_version.C_Version_Number;
                        label4.Text = "Дата: " + db_version.C_Date;

                        selected_version_id = db_version.ID;
                    };
                }
            }
        }
Beispiel #3
0
        public void SaveToDB()
        {
            using (Network_SchemeEntities db = new Network_SchemeEntities(DBUtils.getConnString()))
            {
                Network_Versions new_version = new Network_Versions();
                new_version.C_Date           = DateTime.Now.ToString("d/M/yyyy");
                new_version.C_Version_Number = version + 1;
                new_version.ID = version_id + 1;

                List <Network_Hardware>    db_devices     = new List <Network_Hardware>();
                List <Network_Settings>    db_settings    = new List <Network_Settings>();
                List <Network_Ports>       db_ports       = new List <Network_Ports>();
                List <Network_Connections> db_connections = new List <Network_Connections>();

                int connection_id = 0;
                foreach (NetDevice device in devices)
                {
                    Network_Hardware db_device = new Network_Hardware();
                    db_device.ID            = starting_id + device.id_real;
                    db_device.C_Interface_X = device.sprite.Location.X;
                    db_device.C_Interface_Y = device.sprite.Location.Y;
                    db_device.C_Name        = device.name;
                    db_device.C_Type        = device.type;
                    db_device.C_Status      = false;
                    db_device.C_Version     = new_version.ID;

                    db_devices.Add(db_device);

                    foreach (NetPort port in device.ports)
                    {
                        Network_Settings db_setting = new Network_Settings();
                        db_setting.ID                = starting_id + port.settings.id_real;
                        db_setting.C_IP              = port.settings.IP;
                        db_setting.C_Subnet_Mask     = port.settings.subnet_mask;
                        db_setting.C_Default_Gateway = port.settings.default_gateway;
                        db_setting.C_Version         = new_version.ID;

                        db_settings.Add(db_setting);

                        Network_Ports db_port = new Network_Ports();
                        db_port.ID            = starting_id + port.id_real;
                        db_port.C_Status      = port.enabled;
                        db_port.C_Version     = new_version.ID;
                        db_port.C_Hardware_ID = db_device.ID;
                        db_port.C_Settings_ID = db_setting.ID;

                        db_ports.Add(db_port);

                        if (port.connected_port != null)
                        {
                            Network_Connections db_connection = new Network_Connections();
                            db_connection.ID             = starting_id + connection_id;
                            db_connection.C_Version      = new_version.ID;
                            db_connection.C_From_Port_ID = starting_id + port.id_real;
                            db_connection.C_To_Port_ID   = starting_id + port.connected_port.id_real;
                            db_connections.Add(db_connection);

                            connection_id++;
                        }
                    }
                }

                using (var transaction = db.Database.BeginTransaction())
                {
                    try
                    {
                        db.Network_Versions.Add(new_version);

                        foreach (Network_Settings db_setting in db_settings)
                        {
                            db.Network_Settings.Add(db_setting);
                        }
                        foreach (Network_Hardware db_device in db_devices)
                        {
                            db.Network_Hardware.Add(db_device);
                        }
                        foreach (Network_Ports db_port in db_ports)
                        {
                            db.Network_Ports.Add(db_port);
                        }
                        foreach (Network_Connections db_connection in db_connections)
                        {
                            db.Network_Connections.Add(db_connection);
                        }

                        db.SaveChanges();
                        transaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Ошибка cохранения версии : " + ex.ToString());
                        transaction.Rollback();
                    }
                }
            }
            MessageBox.Show("Успешно сохранена версия : " + (version + 1));
            GetActualVersion();
        }