コード例 #1
0
        public static int InsertDataTask(GatewayDataCell gdc_itm)
        {
            int result;

            try
            {
                if (GateWayRefreshQueue.wq_data == null)
                {
                    GateWayRefreshQueue.wq_data = new WorkQueue <GatewayDataCell>(10000, "GateWayData");
                    GateWayRefreshQueue @object = new GateWayRefreshQueue();
                    GateWayRefreshQueue.wq_data.UserWork += new UserWorkEventHandler <GatewayDataCell>(@object.QueueWork4Data);
                }
                GateWayRefreshQueue.wq_data.EnqueueItem(gdc_itm);
                result = 1;
            }
            catch (Exception ex)
            {
                DebugCenter.GetInstance().appendToFile("DBERROR~~~~~~~~~~~DBERROR : " + ex.Message + "\n" + ex.StackTrace);
                result = -1;
            }
            return(result);
        }
コード例 #2
0
        public void QueueWork4Data(object sender, WorkQueue <GatewayDataCell> .EnqueueEventArgs e)
        {
            DbCommand    dbCommand    = null;
            DbDataReader dbDataReader = null;

            if (this.con == null || this.con.State != ConnectionState.Open)
            {
                if (this.con != null)
                {
                    try
                    {
                        this.con.Close();
                    }
                    catch (Exception)
                    {
                    }
                }
                try
                {
                    if (DBUrl.SERVERMODE)
                    {
                        this.con = this.getConnection();
                    }
                    else
                    {
                        string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + DBUrl.DEFAULT_HOST_PATH + ";Jet OLEDB:Database Password="******"DBERROR~~~~~~~~~~~DBERROR : " + ex.Message + "\n" + ex.StackTrace);
                }
            }
            try
            {
                GatewayDataCell item = e.Item;
                dbCommand             = this.con.CreateCommand();
                dbCommand.CommandText = string.Concat(new string[]
                {
                    "select eleflag from gatewaytable where gid='",
                    item.GatewayID,
                    "' and bid='",
                    item.BranchID,
                    "' and sid='",
                    item.SubmeterID,
                    "' "
                });
                object obj = dbCommand.ExecuteScalar();
                if (obj == null || obj is DBNull || Convert.ToInt32(obj) < 1)
                {
                    dbCommand.Dispose();
                }
                else
                {
                    dbCommand.Dispose();
                    int num = Convert.ToInt32(obj);
                    dbCommand             = this.con.CreateCommand();
                    dbCommand.CommandText = string.Concat(new string[]
                    {
                        "select * from gatewaylastpd where bid='",
                        item.BranchID,
                        "' and sid='",
                        item.SubmeterID,
                        "' "
                    });
                    dbDataReader = dbCommand.ExecuteReader();
                    if (dbDataReader.HasRows)
                    {
                        dbDataReader.Read();
                        int      num2     = MyConvert.ToInt32(dbDataReader.GetValue(2));
                        double   @double  = dbDataReader.GetDouble(3);
                        DateTime dateTime = dbDataReader.GetDateTime(4);
                        dbDataReader.Close();
                        dbDataReader.Dispose();
                        dbCommand.Dispose();
                        if (num == num2)
                        {
                            double num3  = item.PD - @double;
                            double num4  = 0.0;
                            double num5  = 0.0;
                            double num6  = 0.0;
                            bool   flag  = this.checkweek(dateTime);
                            bool   flag2 = this.checkday(dateTime);
                            bool   flag3 = this.checkhour(dateTime);
                            if (flag)
                            {
                                num4 = num3;
                            }
                            if (flag2)
                            {
                                num5 = num3;
                            }
                            if (flag3)
                            {
                                num6 = num3;
                            }
                            dbCommand             = this.con.CreateCommand();
                            dbCommand.CommandText = "select lasttime from currentpue ";
                            obj = dbCommand.ExecuteScalar();
                            string text  = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, 0, 0).ToString("yyyy-MM-dd HH:mm:ss");
                            string text2 = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0).ToString("yyyy-MM-dd HH:mm:ss");
                            string text3 = this.getweek().ToString("yyyy-MM-dd HH:mm:ss");
                            if (obj == null || obj is DBNull)
                            {
                                if (num == 1)
                                {
                                    dbCommand.CommandText = string.Concat(new object[]
                                    {
                                        "insert into currentpue (curhour,curday,curweek,ithourpue,nonithourpue,itdaypue,nonitdaypue,itweekpue,nonitweekpue,lasttime) values(#",
                                        text,
                                        "#,#",
                                        text2,
                                        "#,#",
                                        text3,
                                        "#,",
                                        num6,
                                        ",0,",
                                        num5,
                                        ",0,",
                                        num4,
                                        ",0,#",
                                        DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                                        "# ) "
                                    });
                                }
                                else
                                {
                                    if (num == 2)
                                    {
                                        dbCommand.CommandText = string.Concat(new object[]
                                        {
                                            "insert into currentpue (curhour,curday,curweek,ithourpue,nonithourpue,itdaypue,nonitdaypue,itweekpue,nonitweekpue,lasttime) values(#",
                                            text,
                                            "#,#",
                                            text2,
                                            "#,#",
                                            text3,
                                            "#,0,",
                                            num6,
                                            ",0,",
                                            num5,
                                            ",0,",
                                            num4,
                                            ",#",
                                            DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                                            "# ) "
                                        });
                                    }
                                }
                                if (DBUrl.SERVERMODE)
                                {
                                    dbCommand.CommandText = dbCommand.CommandText.Replace("#", "'");
                                }
                            }
                            else
                            {
                                DateTime dt_time = Convert.ToDateTime(obj);
                                string   text4   = "";
                                if (this.checkweek(dt_time))
                                {
                                    if (this.checkday(dt_time))
                                    {
                                        if (this.checkhour(dt_time))
                                        {
                                            if (num == 1)
                                            {
                                                text4 = string.Concat(new object[]
                                                {
                                                    "update currentpue set curhour=#",
                                                    text,
                                                    "#,curday=#",
                                                    text2,
                                                    "#,curweek=#",
                                                    text3,
                                                    "#,ithourpue=ithourpue+",
                                                    num6,
                                                    ",itdaypue=itdaypue+",
                                                    num5,
                                                    ",itweekpue=itweekpue+",
                                                    num4,
                                                    ",lasttime=#",
                                                    DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                                                    "# "
                                                });
                                            }
                                            else
                                            {
                                                if (num == 2)
                                                {
                                                    text4 = string.Concat(new object[]
                                                    {
                                                        "update currentpue set curhour=#",
                                                        text,
                                                        "#,curday=#",
                                                        text2,
                                                        "#,curweek=#",
                                                        text3,
                                                        "#,nonithourpue=nonithourpue+",
                                                        num6,
                                                        ",nonitdaypue=nonitdaypue+",
                                                        num5,
                                                        ",nonitweekpue=nonitweekpue+",
                                                        num4,
                                                        ",lasttime=#",
                                                        DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                                                        "# "
                                                    });
                                                }
                                            }
                                        }
                                        else
                                        {
                                            if (num == 1)
                                            {
                                                text4 = string.Concat(new object[]
                                                {
                                                    "update currentpue set curhour=#",
                                                    text,
                                                    "#,curday=#",
                                                    text2,
                                                    "#,curweek=#",
                                                    text3,
                                                    "#,nonithourpue=0,ithourpue=",
                                                    num6,
                                                    ",itdaypue=itdaypue+",
                                                    num5,
                                                    ",itweekpue=itweekpue+",
                                                    num4,
                                                    ",lasttime=#",
                                                    DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                                                    "# "
                                                });
                                            }
                                            else
                                            {
                                                if (num == 2)
                                                {
                                                    text4 = string.Concat(new object[]
                                                    {
                                                        "update currentpue set curhour=#",
                                                        text,
                                                        "#,curday=#",
                                                        text2,
                                                        "#,curweek=#",
                                                        text3,
                                                        "#,ithourpue=0,nonithourpue=",
                                                        num6,
                                                        ",nonitdaypue=nonitdaypue+",
                                                        num5,
                                                        ",nonitweekpue=nonitweekpue+",
                                                        num4,
                                                        ",lasttime=#",
                                                        DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                                                        "# "
                                                    });
                                                }
                                            }
                                        }
                                    }
                                    else
                                    {
                                        if (num == 1)
                                        {
                                            text4 = string.Concat(new object[]
                                            {
                                                "update currentpue set curhour=#",
                                                text,
                                                "#,curday=#",
                                                text2,
                                                "#,curweek=#",
                                                text3,
                                                "#,ithourpue=",
                                                num6,
                                                ",nonithourpue=0,itdaypue=",
                                                num5,
                                                ",nonitdaypue=0,itweekpue=itweekpue+",
                                                num4,
                                                ",lasttime=#",
                                                DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                                                "# "
                                            });
                                        }
                                        else
                                        {
                                            if (num == 2)
                                            {
                                                text4 = string.Concat(new object[]
                                                {
                                                    "update currentpue set curhour=#",
                                                    text,
                                                    "#,curday=#",
                                                    text2,
                                                    "#,curweek=#",
                                                    text3,
                                                    "#,nonithourpue=",
                                                    num6,
                                                    ",ithourpue=0,nonitdaypue=",
                                                    num5,
                                                    ",itdaypue=0,nonitweekpue=nonitweekpue+",
                                                    num4,
                                                    ",lasttime=#",
                                                    DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                                                    "# "
                                                });
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    text4 = string.Concat(new string[]
                                    {
                                        "update currentpue set curhour=#",
                                        text,
                                        "#,curday=#",
                                        text2,
                                        "#,curweek=#",
                                        text3,
                                        "#,ithourpue=0,nonithourpue=0,itdaypue=0,nonitdaypue=0,itweekpue=0,nonitweekpue=0,lasttime=#",
                                        DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                                        "# "
                                    });
                                }
                                if (DBUrl.SERVERMODE)
                                {
                                    text4 = text4.Replace("#", "'");
                                }
                                dbCommand.CommandText = text4;
                            }
                            DbTransaction dbTransaction = this.con.BeginTransaction();
                            dbCommand.Transaction = dbTransaction;
                            dbCommand.ExecuteNonQuery();
                            dbCommand.Transaction.Commit();
                            dbTransaction.Dispose();
                            dbCommand.Dispose();
                        }
                        this.ModifyLastPD(this.con, item.BranchID, item.SubmeterID, num, item.PD, item.RecordTime, "UPDATE");
                    }
                    else
                    {
                        dbDataReader.Close();
                        dbDataReader.Dispose();
                        dbCommand.Dispose();
                        this.ModifyLastPD(this.con, item.BranchID, item.SubmeterID, num, item.PD, item.RecordTime, "INSERT");
                    }
                }
            }
            catch (Exception ex2)
            {
                DebugCenter.GetInstance().appendToFile("DBERROR~~~~~~~~~~~DBERROR : " + ex2.Message + "\n" + ex2.StackTrace);
                if (dbDataReader != null)
                {
                    try
                    {
                        dbDataReader.Close();
                        dbDataReader.Dispose();
                    }
                    catch (Exception)
                    {
                    }
                }
                if (dbCommand != null)
                {
                    try
                    {
                        dbCommand.Transaction.Rollback();
                        dbCommand.Dispose();
                    }
                    catch (Exception)
                    {
                    }
                }
            }
        }