• 两个数据库同步表数据,一分钟一次


    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    
    namespace GT.Client
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void timer1_Tick(object sender, EventArgs e)
            {
                InItPlan();
                InItPlanDetail();
            }
    
            public DataRow CreateDataRow(DataTable inserttable,DataRow dr) 
            {
                DataRow tempdr = inserttable.NewRow();
                tempdr["I_PLAN_ID"] = Convert.ToInt32(dr["I_PLAN_ID"]);
                tempdr["E_PLAN_TYPE"] = Convert.ToInt32(dr["E_PLAN_TYPE"]);
                tempdr["E_PLAN_STATE"] = Convert.ToInt32(dr["E_PLAN_STATE"]);
                tempdr["I_PLAN_SUBNO"] = Convert.ToInt32(dr["I_PLAN_SUBNO"]);
                tempdr["I_PLAN_NO"] = Convert.ToInt32(dr["I_PLAN_NO"]);
                tempdr["C_TRANUM"] = dr["C_TRANUM"].ToString();
                tempdr["I_CUTNUM"] = Convert.ToInt32(dr["I_CUTNUM"]);
                tempdr["I_QZ_ID"] = Convert.ToInt32(dr["I_QZ_ID"]);
                tempdr["D_CREATE"] = Convert.ToDateTime(dr["D_CREATE"]);
                tempdr["C_TRANUM_SEND"] = dr["C_TRANUM_SEND"].ToString();
                tempdr["I_LOCOM_ID"] = Convert.ToInt32(dr["I_LOCOM_ID"]);
                tempdr["I_DCZ_ID"] = Convert.ToInt32(dr["I_DCZ_ID"]);
                tempdr["C_DCZ_ID"] = dr["C_DCZ_ID"].ToString();
                tempdr["E_TURN_TYPE"] = Convert.ToInt32(dr["E_TURN_TYPE"]);
                tempdr["D_PL_START"] = Convert.ToDateTime(dr["D_PL_START"]);
                tempdr["D_PL_END"] = Convert.ToDateTime(dr["D_PL_END"]);
                tempdr["D_START"] = Convert.ToDateTime(dr["D_START"]);
                tempdr["D_END"] = Convert.ToDateTime(dr["D_END"]);
                tempdr["I_RANGE_ID"] = Convert.ToInt32(dr["I_RANGE_ID"]);
                tempdr["D_SEND"] = Convert.ToDateTime(dr["D_SEND"]);
                tempdr["C_REMARK"] = dr["C_REMARK"].ToString();
                tempdr["B_PUR_PRINT"] = Convert.ToInt32(dr["B_PUR_PRINT"]);
                tempdr["I_GETNUM"] = Convert.ToInt32(dr["I_GETNUM"]);
                tempdr["I_REMAIN"] = Convert.ToInt32(dr["I_REMAIN"]);
                return tempdr;
    
            }
    
            public void InItPlan() 
            {
                string strSql = "select * from DM_PL_PLANLIST WITH (NOLOCK)";
                DataTable dt = ADOTools.ExcuteDataTable(ADOTools.OTHERCONNECTION_STR, strSql);
                string mystrSql = "select * from t_dcd_planlist WITH (NOLOCK)";
                DataTable mydt = ADOTools.ExcuteDataTable(ADOTools.LOCALCONNECTION_STR, mystrSql);
                DataTable inserttable = mydt.Clone();//仅复制表结构
    
                IEnumerable<DataRow> query2 = dt.AsEnumerable().Except(mydt.AsEnumerable(), DataRowComparer.Default);
                DataTable dt3 = query2.CopyToDataTable();
                foreach (DataRow dr in dt.Rows)
                {
                    if (mydt.Rows.Count > 0)
                    {
                        DataRow[] drlist = mydt.Select("I_PLAN_ID =" + dr["I_PLAN_ID"].ToString() + "");
                        if (drlist.Length == 0)
                        {
                            inserttable.Rows.Add(CreateDataRow(inserttable, dr));
                        }
                    }
                    else
                    {
                        inserttable.Rows.Add(CreateDataRow(inserttable, dr));
                    }
    
                }
                if (inserttable.Rows.Count > 0)
                {
                    ADOTools.BulkInsert(ADOTools.LOCALCONNECTION_STR, inserttable, "t_dcd_planlist");
                }
            
            }
    
            public void InItPlanDetail()
            {
                string strSql = "select * from DM_PL_PLANTEXT WITH (NOLOCK)";
                DataTable dt = ADOTools.ExcuteDataTable(ADOTools.OTHERCONNECTION_STR, strSql);
                string mystrSql = "select * from t_dcd_plantext WITH (NOLOCK)";
                DataTable mydt = ADOTools.ExcuteDataTable(ADOTools.LOCALCONNECTION_STR, mystrSql);
                DataTable inserttable = mydt.Clone();//仅复制表结构
    
                IEnumerable<DataRow> query2 = dt.AsEnumerable().Except(mydt.AsEnumerable(), DataRowComparer.Default);
                DataTable dt3 = query2.CopyToDataTable();
                foreach (DataRow dr in dt.Rows)
                {
                    if (mydt.Rows.Count > 0)
                    {
                        DataRow[] drlist = mydt.Select("I_TEXT_ID =" + dr["I_TEXT_ID"].ToString() + "");
                        if (drlist.Length == 0)
                        {
                            inserttable.Rows.Add(CreateDataRowDetail(inserttable, dr));
                        }
                    }
                    else
                    {
                        inserttable.Rows.Add(CreateDataRowDetail(inserttable, dr));
                    }
    
                }
                if (inserttable.Rows.Count > 0)
                {
                    ADOTools.BulkInsert(ADOTools.LOCALCONNECTION_STR, inserttable, "t_dcd_plantext");
                }
    
            }
    
    
            public DataRow CreateDataRowDetail(DataTable inserttable, DataRow dr)
            {
                DataRow tempdr = inserttable.NewRow();
                tempdr["I_PLAN_ID"] = Convert.ToInt32(dr["I_PLAN_ID"]);
                tempdr["I_TEXT_ID"] = Convert.ToInt32(dr["I_TEXT_ID"]);
                tempdr["I_CUT_NO"] = Convert.ToInt32(dr["I_CUT_NO"]);
                tempdr["I_YARD_ID"] = Convert.ToInt32(dr["I_YARD_ID"]);
                tempdr["I_LINE_ID"] = Convert.ToInt32(dr["I_LINE_ID"]);
                tempdr["E_PORT"] = Convert.ToInt32(dr["E_PORT"]);
                tempdr["I_MODE"] = Convert.ToInt32(dr["I_MODE"]);
                tempdr["I_CARNUM"] = Convert.ToInt32(dr["I_CARNUM"]);
                tempdr["E_CUT_STATUS"] = Convert.ToInt32(dr["E_CUT_STATUS"]);
                tempdr["I_REMAIN"] = Convert.ToInt32(dr["I_REMAIN"]);
                tempdr["C_REMARK"] =dr["C_REMARK"].ToString();
                return tempdr;
    
            }
        }
    }
    萌橙 你瞅啥?
  • 相关阅读:
    android KK版本号,如何更改蓝牙设备类型
    C# DataTable的詳細使用方法
    JAVA进阶-注解
    Android -- Looper.prepare()和Looper.loop() —深入版
    Java面试宝典2013版(超长版)
    HttpClient使用具体解释
    中间件
    Java笔试题集锦
    BDB (Berkeley DB)数据库简单介绍(转载)
    struts2 通配符简化配置
  • 原文地址:https://www.cnblogs.com/daimaxuejia/p/9492560.html
Copyright © 2020-2023  润新知