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

📄 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 页
字号:
                        }
                    }
                }
                if (sayac == dataGridView1.Rows.Count)
                {
                    dataGridView2.Rows[sat].Cells[4].Value = Convert.ToString(sayac) + " Columns";
                }
                else if (sayac >= 0)
                {
                    dataGridView2.Rows[sat].Cells[4].Value = Convert.ToString(sayac) + " of " + Convert.ToString(dataGridView1.Rows.Count) + " Columns";
                }
            }
            else if (sut == 0)
            {
                for (int i = 0; i < dataGridView1.Rows.Count; i++)
                {
                    if (dataGridView1.Rows[i].Cells[2].Value.ToString() == "True")
                    {
                        check[1, sat, i] = true;
                        dataGridView2.Rows[sat].Cells[0].Value = kolon1[sat, i];
                        nokey[sat] = 0;
                        dataGridView2.Rows[sat].Cells[2].ReadOnly = false;
                        prikey1[sat] = kolon1[sat, i];
                        check[0, sat, i] = true;
                        break;
                    }
                    else
                    {
                        check[1, sat, i] = false;
                        dataGridView2.Rows[sat].Cells[0].Value = "No Key Set";
                        nokey[sat] = 0;
                        dataGridView2.Rows[sat].Cells[2].ReadOnly = true;
                        prikey2[sat] = kolon1[sat, i];
                    }
                }
            }
            panel1.Visible = false;
            dataGridView1.Rows.Clear();
        }

        private void dataGridView1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            int x = e.RowIndex;
            int y = e.ColumnIndex;
            if ((dataGridView1.Columns[2].HeaderText == "   Pri_Key") && (y == 2))
            {
                if (keyset[sat] == 1)
                {
                    for (int i = 0; i < dataGridView1.Rows.Count; i++)
                    {
                        if (i != x)
                        {
                            ((DataGridViewCheckBoxCell)(dataGridView1.Rows[i].Cells[2])).Value = false;
                        }
                    }
                }
            }
        }

        private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            database1 = comboBox2.Text;
        }

        private void comboBox4_SelectedIndexChanged(object sender, EventArgs e)
        {
            database2 = comboBox4.Text;
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            
        }

        public void senkronizeet()
        {
            string table = "";
            richTextBox1.Text = "";
            for (int i = 0; i < tabControl4.TabPages.Count; i++)
            {
                table = tabControl4.TabPages[i].Text;
                DataGridView dg1 = (DataGridView)tabControl4.TabPages[table].Controls[table + "veri"];

                for (int j = 0; j < dg1.Rows.Count; j++)
                {
                    int doy = 0;
                    string sorgu = @"DELETE FROM [" + table + "] WHERE ";
                    string id = "";
                    int durum = 0;
                    int indisim = 0;
                    for (int k = 0; k < 20; k++)
                    {
                        if (dataGridView2.Rows[k].Cells[1].Value.ToString() == table)
                        {
                            id = dataGridView2.Rows[k].Cells[0].Value.ToString();
                            indisim = k;
                            if (dataGridView2.Rows[k].Cells[2].Style.BackColor.Name == "Yellow")
                            {
                                durum = 1;
                            }
                            break;
                        }
                    }
                    if (durum == 1) break;
                    sorgu += id + "=";
                    if ((dg1.Rows[j].Cells[1].Value.ToString() == "1") && (dg1.Rows[j].Cells[0].Value.ToString() == "True"))
                    {
                        try
                        {
                            int fgd = Convert.ToInt16(dg1.Rows[j].Cells[id + "2"].Value.ToString());
                            sorgu += dg1.Rows[j].Cells[id + "2"].Value.ToString();
                        }
                        catch
                        {
                            sorgu += "'" + dg1.Rows[j].Cells[id + "2"].Value.ToString() + "'";
                        }

                        sqlcon.nonquery(sorgu,connect(server2,database2));
                        richTextBox1.Text += '\n' + sorgu;
                        sorgu = @"INSERT INTO [" + table + "] (";
                        for (int k = 0; k < (dg1.Columns.Count - 2) / 2; k++)
                        {
                            sorgu += dg1.Columns[2 + 2 * k].Name.Remove(dg1.Columns[2 + 2 * k].Name.Length-1,1) + ",";
                        }
                        sorgu = sorgu.Remove(sorgu.Length - 1, 1);
                        sorgu = sorgu + ") VALUES (";
                        for (int k = 0; k < (dg1.Columns.Count - 2) / 2; k++)
                        {
                            string s = tipi1[indisim, k].ToLower();
                            string[] tipo = s.Split(' ');
                            if (tipo.Length == 2)
                            {
                                doy = 1;
                            }
                            string deg = dg1.Rows[j].Cells[2 + 2 * k].Value.ToString();
                            if ((s=="image")) deg = "NULL";
                            if (deg == "") deg = "NULL";
                            if ((s == "datetime") && (deg!="NULL"))
                            {
                                int m = deg.IndexOf(' ');
                                deg = deg.Remove(m);
                                string[] sam = deg.Split('.');
                                deg = sam[1] + "." + sam[0] + "." + sam[2];
                            }
                            
                            if ((deg!="NULL") && ((s == "ntext") || (s == "datetime") || (s == "char") || (s=="nchar") || (s == "money") || (s=="nvarchar") || (s=="text") || (s=="varchar")))
                            {
                                if (s == "money")
                                {
                                    int m = deg.IndexOf(',');
                                    deg = deg.Remove(m);
                                }
                                sorgu += "'" + deg + "',";
                            }
                            else
                            {
                                sorgu += deg + ",";
                            }
                        }
                        sorgu = sorgu.Remove(sorgu.Length - 1, 1);
                        sorgu += ")";
                        if (doy == 1)
                        {
                            sqlcon.identity(sorgu, connect(server2, database2), table);
                        }
                        else
                        {
                            sqlcon.nonquery(sorgu, connect(server2, database2));
                        }
                        richTextBox1.Text += '\n' + sorgu;
                    }
                    sorgu = @"DELETE FROM [" + table +"] WHERE ";
                    sorgu += id + "=";
                    if ((dg1.Rows[j].Cells[1].Value.ToString() == "3") && (dg1.Rows[j].Cells[0].Value.ToString() == "True"))
                    {
                        try
                        {
                            int fgd = Convert.ToInt16(dg1.Rows[j].Cells[id + "2"].Value.ToString());
                            sorgu += dg1.Rows[j].Cells[id + "2"].Value.ToString();
                        }
                        catch
                        {
                            sorgu += "'" + dg1.Rows[j].Cells[id + "2"].Value.ToString() + "'";
                        }
                        //sorgu += dg1.Rows[j].Cells[id + "2"].Value.ToString();
                        sqlcon.nonquery(sorgu, connect(server2, database2));
                        richTextBox1.Text += '\n' + sorgu;
                    }
                    if ((dg1.Rows[j].Cells[1].Value.ToString() == "2") && (dg1.Rows[j].Cells[0].Value.ToString() == "True"))
                    {
                        sorgu = @"INSERT INTO [" + table + "] (";
                        for (int k = 0; k < (dg1.Columns.Count - 2) / 2; k++)
                        {
                            sorgu += dg1.Columns[2 + 2 * k].Name.Remove(dg1.Columns[2 + 2 * k].Name.Length - 1, 1) + ",";
                        }
                        sorgu = sorgu.Remove(sorgu.Length - 1, 1);
                        sorgu = sorgu + ") VALUES (";
                        for (int k = 0; k < (dg1.Columns.Count - 2) / 2; k++)
                        {
                            string s = tipi1[indisim, k].ToLower();
                            string[] tipo = s.Split(' ');
                            if (tipo.Length == 2)
                            {
                                doy = 1;
                            }
                            string deg = dg1.Rows[j].Cells[2 + 2 * k].Value.ToString();
                            if ((s=="image")) deg = "NULL";
                            if (deg == "") deg = "NULL";
                            if (s == "datetime")
                            {
                                int m = deg.IndexOf(' ');
                                deg = deg.Remove(m);
                                string[] sam = deg.Split('.');
                                deg = sam[1] + "." + sam[0] + "." + sam[2];
                            }
                            if ((deg != "NULL") && ((s == "ntext") || (s == "char") || (s == "money") || (s == "nvarchar") || (s == "text") || (s == "varchar") || (s == "datetime")))
                            {
                                if (s == "money")
                                {
                                    int m = deg.IndexOf(',');
                                    deg = deg.Remove(m);
                                }
                                sorgu += "'" + deg + "',";
                            }
                            else
                            {
                                sorgu += deg + ",";
                            }
                        }
                        sorgu = sorgu.Remove(sorgu.Length - 1, 1);
                        sorgu += ")";
                        if (doy == 1)
                        {
                            sqlcon.identity(sorgu, connect(server2, database2), table);
                        }
                        else
                        {
                            sqlcon.nonquery(sorgu, connect(server2, database2));
                        }
                        richTextBox1.Text += '\n' + sorgu;
                    }
                }
            }
        }

        public void senkronizeyapi()
        {
            richTextBox1.Text = "";
            for (int i = 0; i < dataGridView2.Rows.Count; i++)
            {
                int[] indx = new int[20];
                if (dataGridView2.Rows[i].Cells[2].Value.ToString() == "True")
                {
                    if (dataGridView2.Rows[i].Cells[2].Style.BackColor.Name == "Blue")
                    {
                        if (dataGridView2.Rows[i].Cells[1].Value == null)
                        {
                            string tb2 = dataGridView2.Rows[i].Cells[3].Value.ToString();
                            string str = "DROP TABLE [";
                            str += tb2 + "]";
                            sqlcon.nonquery(str, connect(server2, database2));
                            richTextBox1.Text += str + '\n';
                        }
                        else if (dataGridView2.Rows[i].Cells[3].Value == null)
                        {
                            string tb1 = dataGridView2.Rows[i].Cells[1].Value.ToString();
                            string str = "CREATE TABLE [" + tb1 + "] (";
                            int say = 0;
                            for (int k = 0; k < 20; k++)
                            {
                                if (check1[i, k] == true)
                                {
                                    say = 1;
                                    str += kolon1[i, k] + " " + tipi1[i, k] + ",";
                                    if ((tipi1[i, k] == "char") || (tipi1[i, k] == "varchar") || (tipi1[i, k] == "nvarchar") || (tipi1[i, k] == "ntext") || (tipi1[i, k] == "text"))
                                    {
                                        if (Convert.ToInt64(uzunluk1[i, k]) < 8000)
                                        {
                                            str = str.Remove(str.Length - 1, 1);
                                            str += " (" + uzunluk1[i, k] + ") ,";
                                        }
                                    }
                                    str += " ";
                                }
                            }
                            if (say == 1)
                            {
                                if (prikey1[i] != null)
                                {
                                    str += "CONSTRAINT [PK_" + tb1 + "] PRIMARY KEY CLUSTERED ( [" + prikey1[i] + "] ASC )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] )";
                                }
                                else
                                {
                                    str = str.Remove(str.Length - 1, 1);
                                    str += " )";
                                }
                                sqlcon.nonquery(str, connect(server2, database2));
                                richTextBox1.Text += str + '\n';
                            }
                        }
                        else
                        {
                            int m = 0;
                            for (int k = 0; k < 20; k++)
                            {
                                int d1 = ayni[i, k, 0];
                                int d2 = ayni[i, k, 1];
                                if ((d1 == -1) || (d2 == -1))
                                {
                                    if (check1[i, m] == true)
                                    {
                                        
                                        if (kolon2[adtut[i, 1], k] != null)
                                        {
                                            string str = "ALTER 

⌨️ 快捷键说明

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