Разработка АСР

ACP.cs – основная форма ACP

using System;

using System.Collections;

using System.Collections.Generic;

using System.Data;

using System.Data.Odbc;

using System.Globalization;

using System.IO;

using System.Threading;

using System.Windows.Forms;

using ACP.Properties;

using DevExpress.XtraEditors.Controls;

using DevExpress.XtraTreeList;

using DevExpress.XtraTreeList.Nodes;

using PostgreSql.Data.PostgreSqlClient;

using RKLib.ExportData;

using Telerik.WinControls.UI;

using System.Data.OleDb;

using DevExpress.XtraTreeList.Columns; 

namespace ACP

{

    public partial class ACP : Form

    {

        DataSet ds_elektro = new DataSet();

        DataSet ds = new DataSet();

        DataTable dt = new DataTable();

        DataTable dt_elektro = new DataTable();

        DataSet ds_otch = new DataSet();

        DataSet ds_otch_totals = new DataSet();

        private int count;

  

        public delegate void DelegateSetProgress(object sender, int value); 

        public ACP()

        { 

            InitializeComponent();

            ImageList imageList = new ImageList();

            buttonEdit1.Text = Properties.Settings.Default.Mdb;

            ListNodes();

            Nodes_elektro();

            marqueeProgressBarControl1.Properties.Stopped = true; 
 
 
 

        }

  

     

        public void CheckTable(string table_name)

        {

            PgConnection conn = new PgConnection("Server=" + Properties.Settings.Default.Server + ";Port=" + Properties.Settings.Default.Port + ";User Id=" + Properties.Settings.Default.User_id + ";Password=" + Properties.Settings.Default.Password + ";Database=" + Properties.Settings.Default.Database);

            conn.Open();

            PgCommand command_check = new PgCommand("SELECT 1 FROM pg_tables WHERE tablename = " + table_name, conn);

            int t = command_check.ExecuteNonQuery();

       

            conn.Close();

        }

      

        public void Nodes()

        {

            PgConnection conn = new PgConnection("Server=" + Properties.Settings.Default.Server + ";Port=" + Properties.Settings.Default.Port + ";User Id=" + Properties.Settings.Default.User_id + ";Password=" + Properties.Settings.Default.Password + ";Database=" + Properties.Settings.Default.Database);

            conn.Open(); 

            PgCommand pg_db = new PgCommand("SELECT COUNT(*) FROM nodes_prolog", conn);

            PgDataAdapter pg_da = new PgDataAdapter("SELECT id,abon_id,name_node FROM nodes_prolog", conn);

            PgDataReader dr = pg_db.ExecuteReader();

            dr.Read();

     

            pg_da.Fill(ds);

    

          

        

            dt = ds.Tables[0]; 

         

            conn.Close(); 

        }

 

        public void ListNodes()

        {

           

            Nodes();

         

     

                FillTreeView(dt);

      

            ds.Clear(); 

        } 

        public void Progress()

        {

            progressBarControl2.PerformStep();

            progressBarControl2.Update();

        }

      

        public void FillTreeView(DataTable dt)

        {

          

            DataRow[] rows = dt.Select("abon_id = 0"); 

         

            foreach (DataRow row in rows)

            { 

               

                TreeListNode parentNode = treeList1.AppendNode(new object[] { row["id"], row["abon_id"], row["name_node"],false }, null); 

                parentNode.Tag = row["id"];

          

           

                FillNode(parentNode, dt);

            }

         

        } 

    

  

        public void FillNode(TreeListNode parentNode, DataTable dt)

        { 

            DataRow[] rows = dt.Select(string.Format("abon_id = {0}", parentNode.Tag)); 

            foreach (DataRow row in rows)

            {

                

                TreeListNode parent_Node = treeList1.AppendNode(new object[] { row["id"], row["abon_id"], row["name_node"],false }, parentNode);

                parent_Node.Tag = row["id"];

              

            }

           

        }

        private void radMenuItem2_Click(object sender, System.EventArgs e)

        { 

           

            Nodes();

         

        }

        //Автоматическая вставка нодов в базу

        private void InsertIntoNodes(int parent_id, int type, int model, int device_id,

            string channel, int rd, int rh, int abon_id, DateTime ar0, DateTime ar1,

            DateTime ar2, DateTime ar3, DateTime ar4, DateTime ar5,

            DateTime ar6, DateTime ar7, DateTime ar8, String name_node, string addres,

            string telefon, string fax, string otv_lic, string ingener, string comment,

            int ns, int type_sv, string tel_nomer, DateTime nach_oprosa, DateTime konec_oprosa,

            string ipaddres, string ipport, string tepl_org, string local_number

            , PgConnection conn)

        {

            //ipaddres = "test";

            //name_node = "test";

            //channel = "test";

            string query_insert = "\'" + parent_id + "\',\'" + type + "\',\'" + model + "\',\'"

                                  + device_id.ToString() + "\',\'" + channel + "\',\'" + rd + "\',\'" + rh + "\',\'"

                                  + abon_id + "\', \'" + name_node + "\' ,\' "

                                  + addres + "\' ,\' " + telefon + "\' ,\' " + fax + "\' ,\' " + otv_lic + "\' ,\' " + ingener + "\' ,\' "

                                  + comment + "\' ,\'" + ns + "\',\'" + type_sv + "\',\' " + tel_nomer + "\' ,\' " + ipaddres + "\' ,\'" + ipport + "\',\' " + tepl_org + "\',\'"+local_number +"\'";

           //MessageBox.Show(query_insert);

            // textBox1.Text = query_insert;

            PgCommand insert_command = new PgCommand("SELECT * FROM NODES", conn);

            PgDataAdapter pgAdapter = new PgDataAdapter(insert_command);

            pgAdapter.TableMappings.Add("Table", "Nodes");

            pgAdapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;

            pgAdapter.InsertCommand = new PgCommand("SELECT insert_node(" + query_insert + ");", conn); 

            PgDataReader p_dr = pgAdapter.InsertCommand.ExecuteReader();

            p_dr.Read(); 

        } 
 

        private void Form1_Load(object sender, System.EventArgs e)

        {

            if (DesignMode) return; 

            //this.reportViewer1.RefreshReport();

        } 

        

         

       

        private void buttonEdit1_ButtonClick(object sender, ButtonPressedEventArgs e)

        {

            OpenFileDialog of = new OpenFileDialog();

            of.ShowDialog();

            buttonEdit1.Text = of.FileName.ToString();

            Properties.Settings.Default.Mdb = of.FileName.ToString();

            Properties.Settings.Default.Save();

        }

        private void SetInsertAccessPostgres()

        {

            label_nodes.Visible = true; 
 

            checkedListBoxControl1.Items.Clear();

            try

           {

                string connection_mdb = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +

                                        Properties.Settings.Default.Mdb;

                OleDbConnection o_conn = new OleDbConnection(connection_mdb);

                o_conn.Open();

                PgConnection conn =

                    new PgConnection("Server=" + Properties.Settings.Default.Server + ";Port=" +

                                     Properties.Settings.Default.Port + ";User Id=" +

                                     Properties.Settings.Default.User_id + ";Password=" +

                                     Properties.Settings.Default.Password + ";Database=" +

                                     Properties.Settings.Default.Database);

                conn.Open(); 

                 
 
 

                OleDbDataAdapter o_da =

                    new OleDbDataAdapter("SELECT * FROM NODES ORDER BY ID", o_conn);

                DataSet o_ds = new DataSet();

                DataTable o_dt = new DataTable(); 

           

                o_da.Fill(o_ds);

                o_dt = o_ds.Tables[0];

            

                int mass_l = o_dt.Rows.Count; 
 

                int i = 0;

                int new_nodes = 0; //Новых узлов

                int cur_nodes = 0; //Существующих

                string[] local_number;

                DateTime dt = DateTime.Now;

             

                progressBarControl2.Properties.Minimum = 0;

                progressBarControl2.Properties.Maximum = mass_l;

                

                foreach (DataRow row in o_dt.Rows)

                {

                    PgCommand pg_db = new PgCommand("SELECT id FROM nodes_prolog where parent_id = " + row["id"] + "AND device_id = " + row["device_id"],

                                                    conn);

                    PgDataReader dr = pg_db.ExecuteReader(); 
 
 
 
 

                    //Если  узел есть в базе, то не добавляем про него информацию )

                    if (dr.Read())

                    {

                      

                        checkedListBoxControl1.Items.Add(Convert.ToInt32(row["device_id"]) + "_" + row["channel"] + "_" + row["id"], false);

Разработка АСР