⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.cs

📁 This program is compare the data in sql server. And you can syncronize the table and views this is v
💻 CS
📖 第 1 页 / 共 5 页
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.Sql;
using System.Data.SqlClient;
using Microsoft.SqlServer.Server;
using System.Collections;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.Serialization;


namespace SQLDataCompare
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        public void getir()
        {
            MessageBox.Show("asd");
        }

        int[, ,] ayni;
        bool[, ,] check;
        bool[,] check1;
        public string[] adi1;
        public string[,] kolon1;
        public string[,] tipi1;
        public int[] tip1;
        public int[] tip2;
        public string[,] uzunluk1;
        public string[] prikey1;
        public string[] adi2;
        public string[,] kolon2;
        public string[,] tipi2;
        public string[,] uzunluk2;
        public string[] prikey2;
        public int[,] afd; 
        sql sqlcon = new sql();
        public int xkor = 0;
        public int ykor = 0;
        int[,] adtut = new int[20, 2];
        int[] nokey;
        int[] keyset;
        int[] kar;
        string server1 = "";
        string server2 = "";
        string database1 = "";
        string database2 = "";
        string username1 = "";
        string username2 = "";
        string pass1 = "";
        string pass2 = "";
        int global1 = 0;
        int global2 = 0;
        int sat = 0;
        int sut = 0;
        string[] where;

        public string connect(string server, string database)
        {
            //if (((global1 == 0) && (server==server1)) || ((global2 == 0) && (server==server2)))
            //{
                return "Data Source =" + server + ";Integrated Security=SSPI;Initial Catalog=" + database;
            //}
            //else
            //{
            //    if (server1 == server)
            //    {
            //        return "Data Source =" + server + ";Integrated Security=SSPI;Initial Catalog=" + database + ";User Id=" + username1 + ";password=" + pass1;
            //    }
            //    else
            //    {
            //        return "Data Source =" + server + ";Integrated Security=SSPI;Initial Catalog=" + database + ";User Id=" + username2 + ";password=" + pass2;
            //    }
            //}

        }

        public void serveryukle()
        {
            DataTable dt = new DataTable();
            dt = sqlcon.sqlsorgu("SELECT  DISTINCT  hostname FROM master.dbo.sysprocesses", connect(".", "Master"));
            comboboxdoldur(dt, comboBox1, "hostname");
            comboboxdoldur(dt, comboBox3, "hostname");
            radioButton1.Select();
            radioButton3.Select();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            richTextBox2.Text = DateTime.Now.ToString() + "  --> Program was opened." + '\n';
            serveryukle();
        }

        public void comboboxdoldur(DataTable dt, ComboBox com, string kolon)
        {
            foreach (DataRow dr1 in dt.Rows)
            {
                string str = dr1[kolon].ToString();
                str = str.Trim();
                if (str.Length != 0)
                {
                    com.Items.Add(str);
                }
            }
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            server1 = comboBox1.SelectedText;
            comboBox2.Items.Clear();
            DataTable dt = new DataTable();
            dt = sqlcon.sqlsorgu("select name from sysdatabases", connect(server1, "Master"));
            comboboxdoldur(dt, comboBox2, "name");
        }

        private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)
        {
            server2 = comboBox3.SelectedText;
            comboBox4.Items.Clear();
            DataTable dt = new DataTable();
            dt = sqlcon.sqlsorgu("select name from sysdatabases", connect(server2, "Master"));
            comboboxdoldur(dt, comboBox4, "name");
        }

        public void datagridekle(TabControl tabcon, TabPage tabp)
        {
            DataGridView datagrid = new DataGridView();
            //datagrid.Name = name;
            TabPage a = new TabPage();

            tabPage7.Controls.Add(datagrid);
            datagrid.Columns.Add("asd", "asd");
        }

        public void veridoldur(DataTable dt, string table, string serv)
        {

            SqlConnection con = new SqlConnection();

            con.ConnectionString = connect(serv, "sdfgh");

            con.Open();

            SqlCommand cmd = new SqlCommand();

            cmd.Connection = con;

            string sorgu = "INSERT INTO " + table + " (";

            for (int i = 0; i < dt.Columns.Count; i++)
            {
                if (dt.Columns[i].DataType.Name.ToLower() != "byte[]")
                {
                    sorgu += dt.Columns[i].ColumnName + ",";
                }
            }

            sorgu = sorgu.Remove(sorgu.Length - 1, 1);
            sorgu += " ) VALUES (";

            foreach (DataRow dr in dt.Rows)
            {
                string sorgum = sorgu;
                for (int i = 0; i < dt.Columns.Count; i++)
                {
                    //if (dt.Columns[i].DataType.Name != "image")
                    //{
                    string saf = dt.Columns[i].DataType.Name.ToLower();
                    MessageBox.Show(saf);
                    if ((saf == "string") || (saf == "datetime") || (saf == "decimal"))
                    {
                        sorgum += "'" + dr[i].ToString() + "',";
                    }
                    else if (dt.Columns[i].DataType.Name.ToLower() == "byte[]")
                    {
                        ;
                    }
                    else
                    {
                        sorgum += dr[i].ToString() + ",";
                    }
                    //}
                }
                sorgum = sorgum.Remove(sorgum.Length - 1, 1);
                sorgum += ")";
                cmd.CommandText = sorgum;
                cmd.ExecuteNonQuery();
            }

            con.Close();
        }

        public void dinamikcellmouseclick(object sender, DataGridViewCellMouseEventArgs e)
        {
            if (tabControl1.SelectedTab.Text == "Compare")
            {
                if (tabControl2.SelectedTab.Text == "Rows Different")
                {
                    string table = tabControl4.SelectedTab.Text;
                    int indx=tabControl4.SelectedIndex;
                    DataGridView dg = (DataGridView)tabControl4.TabPages[table].Controls[table + "bilgi"];
                    DataGridView dg1 = (DataGridView)tabControl4.TabPages[table].Controls[table + "veri"];
                    if (e.Y < 120)
                    {
                        if ((e.ColumnIndex == 0) && (e.RowIndex>0))
                        {
                            if (afd[indx, e.RowIndex] == 1)
                            {
                                for (int i = 0; i < dg1.Rows.Count; i++)
                                {
                                    if (dg1.Rows[i].Cells[1].Value.ToString() == e.RowIndex.ToString())
                                    {
                                        dg1.Rows[i].Cells[0].Value = false;
                                        dg1.Rows[i].Cells[0].ReadOnly = true;
                                    }
                                }
                                afd[indx, e.RowIndex] = 0;
                            }
                            else
                            {
                                for (int i = 0; i < dg1.Rows.Count; i++)
                                {
                                    if (dg1.Rows[i].Cells[1].Value.ToString() == e.RowIndex.ToString())
                                    {
                                        dg1.Rows[i].Cells[0].ReadOnly = false;
                                        dg1.Rows[i].Cells[0].Value = true;
                                    }
                                }
                                afd[indx, e.RowIndex] = 1;
                            }
                        }
                        else if ((e.ColumnIndex == -1) && (e.RowIndex >= 0))
                        {
                            for (int i = 0; i < dg1.Rows.Count; i++)
                            {
                                dg1.Rows[i].Visible = true;
                                if (dg1.Rows[i].Cells[1].Value.ToString() != e.RowIndex.ToString())
                                {
                                    dg1.Rows[i].Visible = false;
                                }
                            }
                        }
                        else
                        {
                            for (int i = 0; i < dg1.Rows.Count; i++)
                            {
                                dg1.Rows[i].Visible = true;
                            }
                        }
                    }
                }
            }
        }

        public void dtbasekar(DataTable dt1, DataTable dt2, string table1)
        {
            string pk = "";
            int in1 = 0;
            int in2 = 0;
            afd = new int[20,4];
            for (int i = 0; i < 20; i++)
            {
                for (int j=0;j<4;j++)
                    afd[i,j] = 1;
            }
            for (int i = 0; i < 20; i++)
            {
                if (adi1[i] == table1)
                {
                    pk = prikey1[i];
                    break;
                }
            }

            int a = 0;
            DataGridView dg = new DataGridView();
            DataGridViewCheckBoxColumn cbc = new DataGridViewCheckBoxColumn();
            dg.Columns.Add(cbc);

            dg.Columns[0].Name = "insert";
            dg.Columns[0].HeaderText = "INSERT";
            dg.Columns.Add("Value", "Value");
            foreach (DataColumn dr1 in dt1.Columns)
            {
                if (dr1.ColumnName.ToString() == pk)
                {
                    in1 = a;
                }
                dg.Columns.Add(dr1.ColumnName.ToString() + "1", dr1.ColumnName.ToString() + "1");
                dg.Columns.Add(dr1.ColumnName.ToString() + "2", dr1.ColumnName.ToString() + "2");
                a++;
            }
            TabPage tp = new TabPage();
            dg.AllowUserToAddRows = false;
            dg.AllowUserToDeleteRows = false;
            dg.Name = table1 + "veri";
            int ay = 0;
            int fark1 = 0;
            int fark2 = 0;
            int fark = 0;
            int verisay1 = dt1.Rows.Count;
            int verisay2 = dt2.Rows.Count;
            int asa = 0;
            asa = verisay1;
            for (int i = 0; i < asa; i++)
            {
                DataGridViewRow dr = new DataGridViewRow();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -