Ejemplo n.º 1
0
        //根据表名的到该表字段名
        private void listBox_Field_Init(string TableName)
        {
            PublicBD.Path = System.Windows.Forms.Application.StartupPath + "/Resave/System.xml";
            PublicBD.DB   = "MSSQL";
            PublicBD.ReInit();
            _51Data   dt        = PublicBD.db.dt as _51Data;
            DataTable datatable = dt.Select("SysColumns", new string [] { "Name" }, "Where id=Object_Id('" + TableName + "')");


            if (datatable != null && datatable.Rows.Count > 0)
            {
                for (int i = 0; i < datatable.Rows.Count; i++)
                {
                    listBox_Field.Items.Add(datatable.Rows[i][0]);
                }
            }
        }
Ejemplo n.º 2
0
        //测试成功,表List初始化
        private bool listBox_Table_Init()
        {
            listBox_Table.Items.Clear();
            PublicBD.Path = System.Windows.Forms.Application.StartupPath + "/Resave/System.xml";
            PublicBD.DB   = "MSSQL";
            PublicBD.ReInit();
            _51Data   dt        = PublicBD.db.dt as _51Data;
            DataTable datatable = dt.Select("sys.indexes a , sys.objects b , sys.dm_db_partition_stats c", new string [] { "b.name as tablename ,c.row_count as datacount" },
                                            "where a.[object_id] = b.[object_id] AND b.[object_id] = c.[object_id] AND a.index_id = c.index_id AND a.index_id < 2 AND b.is_ms_shipped = 0");

            if (datatable != null && datatable.Rows.Count > 0)
            {
                for (int i = 0; i < datatable.Rows.Count; i++)
                {
                    listBox_Table.Items.Add(datatable.Rows[i][0].ToString());
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 3
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            PubObject.PubObjectInit(imageList2);
            IList <Service.Model.YY_RTU_Basic> rtus = null;

            ExecCommandList.LC = new List <Command>();


            ExecServiceList.Lsm = Program.wrx.XMLObj.LsM; //读取服务信息
            buttonItem1.Text   += "[" + ProName + "]";


            AddControls();               //根据xml文件动态添加服务显示灯控件
            TcpControl.TcpClient_Init(); //tcp与服务交互初始化


            PublicBD.Path = Program.xmlpath;
            PublicBD.ReInit();
            //连接数据库
            if (PublicBD.ConnectState)
            {
                //得到RTU列表
                rtus = Service.PublicBD.db.GetRTUList("");
                //得到命令列表
                ExecCommandList.Commands = Service.PublicBD.db.GetRTUCommandList();
                //得到命令临时表中的要发送的召测命令
                ExecRTUList.SetLrdm(rtus);

                //提示可能是自动入库的测站信息
                AlertFomrShow(rtus);

                //显示数据窗体控件
                buttonItem_dataShow_Click(null, null);
            }
            else
            {
                //显示系统设置窗体控件
                buttonItem_SetSystem_Click(null, null);
            }



            ////根据服务在线状态更新服务显示灯
            Thread updcontrols = new Thread(new ThreadStart(ThreadUpdControls));

            // 设置为背景线程,主线程一旦退出,该线程也不等待而立即结束
            updcontrols.IsBackground = true;
            updcontrols.Start();



            //添加明文数据
            Thread adddata = new Thread(new ThreadStart(ThreadAddData));

            // 设置为背景线程,主线程一旦退出,该线程也不等待而立即结束
            adddata.IsBackground = true;
            adddata.Start();


            Thread ReConnect = new Thread(new ThreadStart(ThreadReConnect));

            ReConnect.IsBackground = true;
            ReConnect.Start();
        }
Ejemplo n.º 4
0
        private void DBtoDB()
        {
            #region 读取转存字段配置信息
            List <DataResaveClass> list   = xmlToList <DataResaveClass>(ReadFieldToFieldXML());
            List <string>          tables = new List <string>();
            foreach (var item in list)
            {
                tables.Add(item.TableName);
            }
            tables = tables.Distinct().ToList();
            #endregion


            List <string> fields;
            List <object> values;
            List <object> values_1;
            string        whereAnd = "";
            foreach (var table in tables)
            {
                var l = from L in list where table == L.TableName select L;
                fields   = new List <string>();
                values   = new List <object>();
                values_1 = new List <object>();
                foreach (var item in l)
                {
                    fields.Add(item.NewField);

                    if (item.OldField == "元    素" || item.OldField == "其    他")
                    {
                        values.Add(item.Value);
                        values_1.Add(item.Value);
                        bool b = true;
                        if (item.OldField == "元    素")
                        {
                            if (b)
                            {
                                whereAnd += " and ItemID='" + item.Value + "'";
                                b         = false;
                            }
                            else
                            {
                                whereAnd += " or ItemID='" + item.Value + "'";
                            }
                        }
                    }
                    else if (item.OldField == "站    号")
                    {
                        values.Add("[0]");
                        values_1.Add("[0]");
                    }
                    else if (item.OldField == "监测时间")
                    {
                        values.Add("[1]");
                        values_1.Add("[1]");
                    }
                    else if (item.OldField == "接收时间")
                    {
                        values.Add("[2]");
                        values_1.Add("[2]");
                    }
                    else if (item.OldField == "值")
                    {
                        values.Add("[3]");
                        values_1.Add("[3]");
                    }
                }
                #region 读取原始数据库中的数据
                string datetime = ReadDateTimeXML();
                datetime      = DateTime.Parse(datetime).AddSeconds(-60).ToString("yyyy-MM-dd HH:mm:ss");
                PublicBD.Path = System.Windows.Forms.Application.StartupPath + "/System.xml";
                PublicBD.DB   = "MSSQL";
                PublicBD.ReInit();
                _51Data dt = PublicBD.db.dt as _51Data;


                DataTable datatable = dt.Select("YY_DATA_AUTO", new string[] { "*" }, "where DOWNDATE>='" + datetime + "'" + whereAnd);
                #endregion

                if (datatable != null && datatable.Rows.Count > 0)
                {
                    for (int i = 0; i < datatable.Rows.Count; i++)
                    {
                        for (int j = 0; j < values.Count; j++)
                        {
                            if (values_1[j].ToString() == "[0]")
                            {
                                values[j] = datatable.Rows[i]["STCD"].ToString();
                            }
                            else if (values_1[j].ToString() == "[1]")
                            {
                                values[j] = datatable.Rows[i]["TM"].ToString();
                            }
                            else if (values_1[j].ToString() == "[2]")
                            {
                                values[j] = datatable.Rows[i]["DOWNDATE"].ToString();
                            }
                            else if (values_1[j].ToString() == "[3]")
                            {
                                values[j] = datatable.Rows[i]["DATAVALUE"].ToString();
                            }
                        }

                        //写入转存库,并记录成功失败数量
                        PublicBD.Path = System.Windows.Forms.Application.StartupPath + "/Resave/System.xml";
                        PublicBD.DB   = "MSSQL";
                        PublicBD.ReInit();
                        _51Data newdt = PublicBD.db.dt as _51Data;

                        int B = newdt.Insert_1(table, fields.ToArray(), values.ToArray());
                        if (B == 1)
                        {
                            Success++;
                        }
                        else if (B == 2)
                        {
                            Key++;
                        }
                        else
                        {
                            Failure++;
                        }
                    }
                }
            }
        }