Example #1
0
        public int GetDiffByMinute(Time time)
        {
            int diff = 0;

            if (day != time.day)
            {
                diff = (24 + hour) * 60 - time.hour * 60 + minute - time.minute;
            }
            else
            {
                diff = day * 24 * 60 - time.day * 24 * 60 + hour * 60 - time.hour * 60 + minute - time.minute;
            }

            return diff;
        }
Example #2
0
        public int Getdiff(Time time)
        {
            int diff = 0;

            if (time.day != day)
            {
                diff = (hour - time.hour + 24) * 3600 + (minute - time.minute) * 60 + second - time.second;
                //diff = hour * 60 * 60 - (24 + time.hour) * 60 * 60 + minute * 60 - time.minute * 60 + second - time.second;
            }
            else
            {
                diff = (day - time.day) * 24 * 60 * 60  + (hour - time.hour) * 60 * 60 + (minute - time.minute) * 60 + second - time.second;
            }

            return diff;
        }
        // 用于获取正确的时间
        private Time getDateTime(String date, String time)
        {
            String[] DATE = date.ToString().Split('/');
            String[] TIME = time.ToString().Split(':');

            Time datetime = new Time(Convert.ToInt32(DATE[0]),
                                             Convert.ToInt32(DATE[1]),
                                             Convert.ToInt32(DATE[2]),
                                             Convert.ToInt32(TIME[0]),
                                             Convert.ToInt32(TIME[1]),
                                             Convert.ToInt32(TIME[2]));
            return datetime;
        }
        //public void getData(Time last, ScaleData data, DataSet ds)
        //{
        //    Time first = last.subtractMinutes(_model.DisplayInterval);
        //    data.FirstTime = first;
        //    int diff = last.get_diff_by_minute(first);
        //    data.getTime(last, diff);
        //    int rowCount = ds.Tables[0].Rows.Count;
        //    for (int i = 0; i < 2; ++i)
        //    {
        //        data.Depth[i] = ds.Tables[0].Rows[rowCount / 3 * (i + 1)]["DEPTH"].ToString();
        //        data.Pos[i] = rowCount / 3 * (i + 1);
        //    }
        //    _model.getData(ds);
        //}
        private void getData(object sender, EventArgs args)
        {
            DataSet dataSet = new DataSet();
            dataSet = conn.SelectDataSet("SELECT TOP 1 * FROM " + TableName + " WHERE WELLID = '" + WellID
                                            + "' AND WELLBOREID ='" + WellBoreID + "' ORDER BY TDATE DESC, TTIME DESC");

            if (dataSet.Tables[0].Rows.Count != 0)
            {

                String date = dataSet.Tables[0].Rows[0]["TDATE"].ToString();
                String time = dataSet.Tables[0].Rows[0]["TTIME"].ToString();
                // 数据截止时间
                Time last = new Time(date, time);
                Time first = last.SubtractMinutes(_model.DisplayInterval);
                date = first.ToDateString();
                time = first.ToTimeString();

                dataSet.Clear();
                dataSet.Dispose();

                DataSet ds = new DataSet();

                string str = "SELECT * FROM " + TableName + " Where (TDATE = '" + date + "' And TTime >= '" + time + "') Or (TDate >'" + date + "') AND WELLID = '" + WellID + "' AND WELLBOREID ='" + WellBoreID + "' ORDER BY TDATE asc,TTIME asc";

                //ds = conn.SelectDataSet("SELECT * FROM (SELECT * FROM " + TableName
                //                        + " WHERE TDATE >= '" + date + "') AS TEMP WHERE TEMP.TTIME >= '" + time + "' ORDER BY TEMP.TDATE asc, TEMP.TTIME asc");

                ds = conn.SelectDataSet(str);

                int N = ds.Tables[0].Rows.Count;

                // 数据起始时间
                first = getDateTime(ds.Tables[0].Rows[0]["TDATE"].ToString(),
                                    ds.Tables[0].Rows[0]["TTIME"].ToString());

                data.FirstTime = first;
                // 获取两时间的差值
                int diff = last.GetDiffByMinute(first);
                data.getTime(last, diff);

                int rowCount = ds.Tables[0].Rows.Count;
                for (int i = 0; i < 2; ++i)
                {
                    data.Depth[i] = ds.Tables[0].Rows[rowCount / 3 * (i + 1)]["DEPTMEAS"].ToString();
                    data.Pos[i] = rowCount / 3 * (i + 1);
                }

                _model.getData(ds);
                ds.Clear();
                ds.Dispose();

                adjustHeader();
                foreach (Column col in this.Columns)
                {
                    col.repaint(data);
                }
                Scale.repaintScale(data);
                _timer.Interval = _model.Interval;
            }
        }
Example #5
0
 public void getTime(Time now, int DisplayInterval)
 {
     datetime[2] = now;
     datetime[1] = now.SubtractMinutes(DisplayInterval / 3);
     datetime[0] = now.SubtractMinutes(DisplayInterval / 3 * 2);
 }
Example #6
0
        public Time SubtractHours(int Interval)
        {
            Time past = new Time(this.year, this.month, this.day, this.hour, this.minute, this.second);

            if (past.hour - Interval < 0)
            {
                if (past.day == 1)
                {
                    if (past.month == 1)
                    {
                        past.year -= 1;
                        past.month = 12;
                        past.day = 31;
                        past.hour = 24 + past.hour - Interval;
                    }
                    else
                    {
                        past.month -= 1;
                        past.day = MONTH[past.month];
                        past.hour = 24 + past.hour - Interval;
                    }
                }
                else
                {
                    past.day -= 1;
                    past.hour = 24 + past.hour - Interval;
                }
            }
            else
            {
                past.hour -= Interval;
            }

            return past;
        }
Example #7
0
        public void TestSubtractMinutes()
        {
            Time t1 = new Time(2000, 1, 2, 1, 1, 3);
            Time t2 = t1.SubtractMinutes(50);
            Assert.AreEqual(50, t1.GetDiffByMinute(t2));

            t1 = new Time(2000, 1, 2, 0, 1, 3);
            t2 = t1.SubtractMinutes(50);
            Assert.AreEqual(50, t1.GetDiffByMinute(t2));
        }
Example #8
0
        public void TestSubtractHours()
        {
            Time t1 = new Time(2000, 1, 2, 1, 1, 4);
            Time t2 = t1.SubtractHours(2);
            Assert.AreEqual(23, t2.hour);

            t1 = new Time(2000, 1, 2, 23, 3, 3);
            t2 = t1.SubtractHours(24);
            Assert.AreEqual(23, t2.hour);
            Assert.AreEqual(1, t2.day);
        }
Example #9
0
        public void TestGetDiffByMinute()
        {
            Time t1 = new Time(2000, 1, 1, 0, 3, 0);
            Time t2 = new Time(2000, 1, 1, 0, 5, 3);
            Assert.AreEqual(2, t2.GetDiffByMinute(t1));

            t1 = new Time(2000, 1, 1, 23, 59, 3);
            t2 = new Time(2000, 1, 2, 1, 6, 5);
            Assert.AreEqual(67, t2.GetDiffByMinute(t1));
        }
Example #10
0
        public void TestGetDiff()
        {
            // 基础测试
            Time t1 = new Time(2000, 1, 1, 0, 0, 0);
            Time t2 = new Time(2000, 1, 1, 0, 3, 1);
            Assert.AreEqual(181, t2.Getdiff(t1));

            // 当日期变更时的测试
            t1 = new Time(2000, 1, 1, 23, 59, 50);
            t2 = new Time(2000, 1, 2, 0, 1, 20);
            Assert.AreEqual(90, t2.Getdiff(t1));

            // 当月变更时的测试
            t1 = new Time(2000, 1, 31, 23, 58, 40);
            t2 = new Time(2000, 2, 1, 0, 4, 30);
            Assert.AreEqual(350, t2.Getdiff(t1));

            // 当年变更时的测试
            t1 = new Time(2000, 12, 31, 23, 59, 50);
            t2 = new Time(2001, 1, 1, 0, 3, 5);
            Assert.AreEqual(195, t2.Getdiff(t1));
        }
Example #11
0
        public Time SubtractMinutes(int Interval)
        {
            Time past = new Time(this.year, this.month, this.day, this.hour, this.minute, this.second);

            int hour = Interval / 60;
            int minu = Interval - hour * 60;

            past.hour -= hour;
            past.minute -= minu;

            if (past.minute < 0)
            {
                past.hour -= 1;
                past.minute += 60;
            }

            if (past.hour < 0)
            {
                past.day -= 1;
                past.hour += 24;
            }

            if (past.day < 1)
            {
                past.month -= 1;
                past.day += MONTH[past.month];
            }

            if (past.month < 1)
            {
                past.year -= 1;
                past.month = 12;
            }

            return past;
        }
Example #12
0
        public void drawGraphics(ScaleData sData)
        {
            // 获取本列中的所有数据
            List<ColumnHeaderData> list = _header.Data;

            for (int ii = 0; ii < list.Count; ++ii)
            {
                // 获取单项数据
                ColumnHeaderData c = list.ElementAt(ii);
                List<double> data = c.Data.DData;

                double min = c.Data.Min;
                double max = c.Data.Max;

                if(max==min)
                {
                    max = max + 1;
                }

                double span = max - min;

                double scale = _body.Height * 1.0 / 3.0;

                //Time ROOT = new Time(_model.TDATE._StringData.ElementAt(sData.pos[0]).ToString(),
                //                     _model.TTIME._StringData.ElementAt(sData.pos[0]).ToString());

                Time ROOT = sData.FirstTime;

                int rowInterval = sData.Datetime[0].Getdiff(sData.Datetime[2]) / 3;

                for (int i = 0; i < 3; ++ i)
                {
                    for (int j = i==0 ? 0 : sData.Pos[i-1]; j < sData.Pos[i]; ++j)
                    {
                        Time first = new Time(_model.TDATE.StringData.ElementAt(j).ToString(),
                                              _model.TTIME.StringData.ElementAt(j).ToString());

                        Time second = new Time(_model.TDATE.StringData.ElementAt(j + 1).ToString(),
                                              _model.TTIME.StringData.ElementAt(j + 1).ToString());
                        int interval = first.Getdiff(second);

                        Line line = new Line()
                        {
                            X1 = (data.ElementAt(j) - min) * this._body.Width / span,
                            Y1 = (ROOT.Getdiff(first)) * 1.0 / rowInterval * scale,
                            X2 = (data.ElementAt(j+1) - min) * this._body.Width / span,
                            Y2 = (ROOT.Getdiff(second)) * 1.0 / rowInterval * scale,
                            Stroke = colors[ii],
                            StrokeThickness = 0.8
                        };

                        _body.Children.Add(line);
                    }
                }
            }
        }