• Home
  • PS
  • C#
  • Perl
  • MSSQL
  • MariaDB
  • Linux
  • Docker
  • MacOS
  • PG
  • Exchange Server
  • Windows
  • Other

Собираем информацию через WMI в БД MSSQL

Details
Written by: po3dno
Category: C#
Created: 08 December 2015
Hits: 1086

            string pc = System.Environment.MachineName;

            if (args.Count() == 1)

                pc =  args[0];

 

            // Ограничение на поле class = 33 символа

            string[] List = new string[] {

                "Win32_BaseBoard",

                "Win32_BIOS",

                "Win32_ComputerSystem",

                //"Win32_Environment",

                "Win32_LogicalDisk",

                "Win32_NetworkAdapter",

                "Win32_OperatingSystem", 

                "Win32_NetworkAdapterConfiguration"

            };

Read more …

Настройки в ini файле на C#W

Details
Written by: Senka
Category: C#
Created: 11 June 2013
Hits: 1495

  

            IniFile ini = new IniFile("./config.ini");

            if (ini.IniReadValue("Settings", "Server") != "")

                servername = ini.IniReadValue("Settings", "Server");

 

            IniFile ini = new IniFile("config.ini");

            ini.IniWriteValue("Settings", "Server", servername);

 

Read more …

Открываем файл на C#

Details
Written by: Senka
Category: C#
Created: 11 June 2013
Hits: 1361

openFileDialog1.Filter = "xlsx files (*.xlsx)|*.xlsx|xml files (*.xml)|*.xml|All files (*.*)|*.*";

openFileDialog1.FilterIndex = 1;

if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)

{

    textBox1.Text = openFileDialog1.FileName;

// От типа файла запускаем процедуру обработки

    switch (openFileDialog1.FilterIndex)

    {

        case 1: // XLSX

            parseXLSX(openFileDialog1.FileName);

            break;

        case 2: // XML

            XmlTextReader reader = new XmlTextReader(openFileDialog1.FileName);

            parseXML(reader);

            break;

    }

}

 

Читаем XLSL на C#

Details
Written by: Senka
Category: C#
Created: 11 June 2013
Hits: 1294

private DataTable openXLSX(string filename)

{

    OleDbConnection connection = null;

    OleDbCommand command = null;

    OleDbDataAdapter adapter = null;

    DataSet dataset = new DataSet();

    try

    {

        connection = new OleDbConnection(string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=\"Excel 12.0 Xml;HDR=YES;IMEX=1\";", filename));

        connection.Open();

 

        DataTable sheetsName = connection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { null, null, null, "Table" });

 

        string firstSheetName = sheetsName.Rows[0][2].ToString();

 

        command = new OleDbCommand(string.Format("SELECT * FROM [{0}]",firstSheetName),  connection);

        //command.CommandType = CommandType.Text;

        adapter = new OleDbDataAdapter(command);

        adapter.Fill(dataset);

    }

    catch (Exception exception)

    {

        MessageBox.Show(exception.ToString());

    }

    finally

    {

        if (connection.State == ConnectionState.Open)

            connection.Close();

        connection.Dispose();

        command.Dispose();

        adapter.Dispose();

    }

    return dataset.Tables[0];

}

 

//dataGridView1.DataSource = dt;

//dataGridView1.Update();

POST запрос на C#

Details
Written by: Senka
Category: C#
Created: 11 June 2013
Hits: 1316

private static string POST(string Url, string Data)

{

    System.Net.WebRequest req = System.Net.WebRequest.Create(Url);

    req.Method = "POST";

    req.Timeout = 60000;

    req.ContentType = "application/x-www-form-urlencoded";

 

    UTF8Encoding utf8 = new UTF8Encoding();

    byte[] sentData = utf8.GetBytes(Data);

    //byte[] sentData = Encoding.GetEncoding(1251).GetBytes(Data);

    //sentData = Encoding.Convert(1251, "utf-8", sentData);

 

    req.ContentLength = sentData.Length;

    System.IO.Stream sendStream = req.GetRequestStream();

    sendStream.Write(sentData, 0, sentData.Length);

    sendStream.Close();

    System.Net.WebResponse res = req.GetResponse();

    System.IO.Stream ReceiveStream = res.GetResponseStream();

    System.IO.StreamReader sr = new System.IO.StreamReader(ReceiveStream, Encoding.UTF8);

    //Кодировка указывается в зависимости от кодировки ответа сервера

    Char[] read = new Char[256];

    int count = sr.Read(read, 0, 256);

    string Out = String.Empty;

    while (count > 0)

    {

        String str = new String(read, 0, count);

        Out += str;

        count = sr.Read(read, 0, 256);

    }

    return Out;

}

Page 2 of 2

  • 1
  • 2

Login Form

  • Forgot your password?
  • Forgot your username?

Statistics

  • Users 2
  • Articles 164
  • Articles View Hits 149004