Exemple #1
0
        public static async void Update(string pcName, string admPass, string biosPass, string model)//Update PC if it was exist
        {
            if (model == "" || model == null)
            {
                MessageBox.Show("Необходимо указать модель компьютера.");
                return;
            }
            SqlCommand command = new SqlCommand("UPDATE [Table] SET PcName=@PcName, Date=@Date, Responsibility=@Responsibility, AdmPass=@AdmPass, BiosPass=@BiosPass, pcModel=@Model WHERE PcName=@PcName", connection);

            command.Parameters.AddWithValue("PcName", pcName.ToUpper());
            command.Parameters.AddWithValue("Date", DateTime.Today);
            command.Parameters.AddWithValue("Responsibility", Environment.UserName);
            command.Parameters.AddWithValue("AdmPass", Crypter.RSAEncrypt(admPass));
            command.Parameters.AddWithValue("BiosPass", Crypter.RSAEncrypt(biosPass));
            command.Parameters.AddWithValue("Model", model);


            try
            {
                await command.ExecuteNonQueryAsync();

                MessageBox.Show("Запись обновлена успешно.");
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        }
Exemple #2
0
        public static async void ImportDB(string connect)
        {
            SqlConnection con = new SqlConnection(@" Data Source = (LocalDB)\MSSQLLocalDB; AttachDbFilename =" + connect + "; Integrated Security = True"); //Connection to second DB

            SqlDataReader reader = null;

            await con.OpenAsync();

            SqlCommand SelectCommand = new SqlCommand("SELECT * FROM [Table]", con);

            Comps.compsList.Clear();
            reader = await SelectCommand.ExecuteReaderAsync();

            //Reading all DB and get list
            while (await reader.ReadAsync())
            {
                Comps comp = new Comps();
                comp.PcName         = reader[1].ToString();
                comp.Responsibility = reader[3].ToString();
                try
                {
                    comp.AdmPass  = Crypter.RSADecrypt(reader[4].ToString());
                    comp.BiosPass = Crypter.RSADecrypt(reader[5].ToString());
                    comp.Date     = reader[2].ToString();
                }
                catch
                {
                    comp.AdmPass  = reader[4].ToString();
                    comp.BiosPass = reader[5].ToString();
                    comp.Date     = null;
                }
                Comps.compsList.Add(comp);
            }

            reader.Close();
            con.Close();

            SqlCommand command = new SqlCommand("INSERT INTO [Table] (PcName, Date, Responsibility, AdmPass, BiosPass)VALUES(UPPER(@PcName), @Date, @Responsible, @AdmPass, @BiosPass)", connection);

            foreach (Comps comp in Comps.compsList)
            {
                command.Parameters.Clear();
                command.Parameters.AddWithValue("PcName", comp.PcName);
                if (comp.Date != null && comp.Date.Length > 1)
                {
                    command.Parameters.AddWithValue("Date", DateTime.Parse(comp.Date));
                }
                else
                {
                    command.Parameters.AddWithValue("Date", DBNull.Value);
                }
                command.Parameters.AddWithValue("Responsible", comp.Responsibility);
                command.Parameters.AddWithValue("AdmPass", Crypter.RSAEncrypt(comp.AdmPass));
                command.Parameters.AddWithValue("BiosPass", Crypter.RSAEncrypt(comp.BiosPass));
                command.ExecuteNonQuery();
            }
        }
Exemple #3
0
        public static async void Add(string pcName, string admPass, string biosPass, string model) //Insert new PC
        {
            SqlCommand command = new SqlCommand("INSERT INTO [Table] (PcName, Date, Responsibility, AdmPass, BiosPass, pcModel)VALUES(UPPER(@PcName), @Date, @Responsible, @AdmPass, @BiosPass, @Model)", connection);

            command.Parameters.AddWithValue("PcName", pcName);
            command.Parameters.AddWithValue("Date", DateTime.Today);
            command.Parameters.AddWithValue("Responsible", Environment.UserName);
            command.Parameters.AddWithValue("AdmPass", Crypter.RSAEncrypt(admPass));
            command.Parameters.AddWithValue("BiosPass", Crypter.RSAEncrypt(biosPass));
            command.Parameters.AddWithValue("Model", model);

            try
            {
                await command.ExecuteNonQueryAsync();

                UpdateLastPC();

                MessageBox.Show("Запись добавлена успешно.");
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        }