Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Data.OleDb;
- using System.Drawing;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace BD18_9_Server
- {
- public partial class Form1 : Form
- {
- public string connectString;
- public OleDbConnection myconect;
- public OleDbCommand comand;
- string zap, str = "";
- OpenFileDialog P = new OpenFileDialog();
- string name = "";
- public StreamWriter writer;
- public StreamReader reader;
- public FileStream file;
- public Thread t;
- public bool connect = false;
- public bool con = false;
- public bool Z = true;
- DataTable table;
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- }
- private void подключитьсяToolStripMenuItem_Click(object sender, EventArgs e)
- {
- P.Filter = "mdb files (*.mdb)|*.mdb";
- if (P.ShowDialog() == System.Windows.Forms.DialogResult.OK)
- {
- connectString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + P.FileName + ";";
- myconect = new OleDbConnection(connectString);
- name = P.FileName;
- }
- }
- private void button1_Click(object sender, EventArgs e)
- {
- connect = true;
- t = new Thread(new ThreadStart(MyMethod));
- t.Start();
- Text = "Активен";
- }
- private void button2_Click(object sender, EventArgs e)
- {
- Text = "Выключен";
- connect = false;
- }
- private void выходToolStripMenuItem_Click(object sender, EventArgs e)
- {
- this.Close();
- }
- public void MyMethod()
- {
- while (connect)
- {
- if (System.IO.File.Exists(@"D:\Test\flag.txt") && !con)
- {
- for (int i = 0; i < 10000000; i++)
- {
- }
- BeginInvoke(new Action(() => { text(); }));
- }
- if (System.IO.File.Exists(@"D:\Test\sql.txt") && con && Z)
- {
- Z = false;
- for (int i = 0; i < 10000000; i++)
- {
- }
- BeginInvoke(new Action(() => { sql(); }));
- }
- }
- }
- public void text()
- {
- con = true;
- StreamReader sr = File.OpenText(@"D:\Test\flag.txt");
- textBox1.Text = sr.ReadLine();
- sr.Close();
- }
- public void sql()
- {
- StreamReader sr = File.OpenText(@"D:\Test\sql.txt");
- zap = sr.ReadLine();
- richTextBox1.Text = zap;
- sr.Close();
- File.Delete(@"D:\Test\sql.txt");
- myconect.Open();
- table = new DataTable();
- myconect = new OleDbConnection(connectString);
- myconect.Open();
- comand = new OleDbCommand(zap, myconect);
- OleDbDataReader reader = comand.ExecuteReader();
- table.Load(reader);
- dataGridView1.DataSource = table;
- myconect.Close();
- file = new FileStream(@"D:\Test\data.txt", FileMode.Create);
- writer = new StreamWriter(file);
- try
- {
- for (int j = 0; j < dataGridView1.Rows.Count - 1; j++)
- {
- for (int i = 0; i < dataGridView1.Rows[j].Cells.Count; i++)
- {
- writer.Write(dataGridView1.Rows[j].Cells[i].Value + ":");
- }
- writer.WriteLine("");
- }
- }
- catch
- {
- MessageBox.Show("Ошибка при сохранении файла!");
- }
- writer.Close();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement