Exemple #1
0
		public AISClass(String source, DateTime dateStart) {
			Source = new SourceInfo(source);

			DateStart = dateStart.Date;
			DateEnd = DateStart.AddHours(24);
			Dates = new List<DateTime>();
			DateTime date = DateStart.AddMinutes(30);
			while (date <= DateEnd) {
				Dates.Add(date);
				date = date.AddMinutes(30);
			}
		}
Exemple #2
0
        public bool SetStatus(DateTime date)
        {
            //полпути
            var halfPath = (DateDestination - DateStart).TotalMinutes / 2;

            bool result = false;

            if (date >= DateStart.AddMinutes(-60) && date < DateStart.AddMinutes(-30))
            {
                if (Status != 0)
                {
                    result = true; Status = 0; OnPropertyChanged("Status");
                }
            }
            else if (date >= DateStart.AddMinutes(-30) && date < DateStart)
            {
                if (Status != 1)
                {
                    result = true; Status = 1; OnPropertyChanged("Status");
                }
            }
            else if (date >= DateStart && date < DateDestination.AddMinutes(-(halfPath + halfPath / 2)))
            {
                if (Status != 2)
                {
                    result = true; Status = 2; OnPropertyChanged("Status");
                }
            }
            else if (date >= DateStart.AddMinutes(halfPath / 2) && date < DateDestination.AddMinutes(-(halfPath / 2)))
            {
                if (Status != 3)
                {
                    result = true; Status = 3; OnPropertyChanged("Status");
                }
            }
            else if (date >= DateDestination.AddMinutes(-(halfPath / 2)) && date < DateDestination)
            {
                if (Status != 4)
                {
                    result = true; Status = 4; OnPropertyChanged("Status");
                }
            }
            else if (date >= DateDestination)
            {
                if (Status != 5)
                {
                    result = true; Status = 5; OnPropertyChanged("Status");
                }
            }

            return(result);
        }
Exemple #3
0
        public AISClass(String source, DateTime dateStart)
        {
            //Source = new SourceInfo(source);

            Objs = new List <int>();
            string[] arr = source.Split(',');
            foreach (string s in arr)
            {
                Objs.Add(Convert.ToInt32(s));
            }
            ObjType = Objs.Count > 1 ? 0 : 2;

            DateStart = dateStart.Date;
            DateEnd   = DateStart.AddHours(24);
            Dates     = new List <DateTime>();
            DateTime date = DateStart.AddMinutes(30);

            while (date <= DateEnd)
            {
                Dates.Add(date);
                date = date.AddMinutes(30);
            }
        }
Exemple #4
0
        public bool changeVal(string key, int hh, int min, string newVal, ref string changedVal, ref string message)
        {
            Logger.info(String.Format("Изменение значения по объекту [{0}] [{1}:{2}]:", key, hh, min));
            DateTime   date   = DateStart.AddMinutes(min).AddHours(hh);
            DataRecord rec    = Data[key];
            string     oldVal = rec.Values[date];


            Logger.info(String.Format("==={0}: Дата: {1} OldVal={2} newVal={3}", rec.Name, date.ToString("dd.MM.yyyy HH:mm"), oldVal, newVal));

            bool result = true;

            /*changedVal = newVal;
             * message = String.Format("Изменено значение [{0}] [{1}] ====== OldVal={2} ======  newVal={3} ",
             *              date.ToString("dd.MM.yyyy HH:mm"), rec.Name, oldVal, newVal);
             * return result;*/

            SqlConnection con = getConnection();

            try {
                con.Open();
                SqlTransaction trans = con.BeginTransaction();
                Logger.info(String.Format("======Удаление значения"));
                string comSTR = "";
                comSTR = String.Format("DELETE FROM DATA WHERE OBJECT={0} AND OBJTYPE={1} AND ITEM={2} AND PARNUMBER=12 AND DATA_DATE='{3}'",
                                       rec.Source.Obj, rec.Source.ObjType, rec.Source.Item, date.ToString(DateFormat));
                Logger.info(comSTR);
                SqlCommand command = new SqlCommand(comSTR, con);
                command.Transaction = trans;
                command.ExecuteNonQuery();
                Logger.info(String.Format("=========OK"));

                if (newVal != "---")
                {
                    Logger.info(String.Format("======Вставка значения"));
                    comSTR = String.Format("INSERT INTO Data (parnumber, object, objtype, item, value0, value1, data_date, rcvstamp, season, appid, p2kstatus, p2kstatush) SELECT	12, {0}, {1}, {2}, {3}, {3}, '{4}', '{4}', {5}, 2, 0, 0",
                                           rec.Source.Obj, rec.Source.ObjType, rec.Source.Item, newVal.Replace(",", "."), date.ToString(DateFormat), CurrentSeason);
                    Logger.info(comSTR);
                    command             = new SqlCommand(comSTR, con);
                    command.Transaction = trans;
                    command.ExecuteNonQuery();
                    Logger.info(String.Format("=========OK"));
                }
                Logger.info(String.Format("======Применение транзакции"));
                trans.Commit();
                Logger.info(String.Format("=========OK"));
                message = String.Format("Изменено значение [{0}] [{1}] ====== OldVal={2} ======  newVal={3} ",
                                        date.ToString("dd.MM.yyyy HH:mm"), rec.Name, oldVal, newVal);
            } catch (Exception e) {
                Logger.info(String.Format("===Ошибка в транзакции, значение не изменено " + e.ToString()));
                con.Close();
                result     = false;
                changedVal = rec.Values[date];
            }

            try {
                Logger.info(String.Format("======Чтение значения"));
                if (con.State != System.Data.ConnectionState.Open)
                {
                    con.Open();
                }
                string comSTR = "";
                comSTR = String.Format("SELECT VALUE0 FROM DATA WHERE OBJECT={0} AND OBJTYPE={1} AND ITEM={2} AND PARNUMBER=12 AND DATA_DATE='{3}'",
                                       rec.Source.Obj, rec.Source.ObjType, rec.Source.Item, date.ToString(DateFormat));
                SqlCommand command = new SqlCommand(comSTR, con);
                object     nv      = command.ExecuteScalar();
                if (nv == null)
                {
                    changedVal       = "---";
                    rec.Values[date] = "---";
                    Logger.info(String.Format("========значение не найдено: {0}", changedVal));
                }
                else
                {
                    double val = Convert.ToDouble(nv);
                    rec.Values[date] = String.Format("{0:0.##}", val).Replace(",", ".");
                    changedVal       = rec.Values[date];
                    Logger.info(String.Format("========получено значение: {0}", changedVal));
                }
                con.Close();
            } catch (Exception e) {
                Logger.info("===Ошибка при чтении нового значения " + e.ToString());
            }
            try {
                if (con.State == System.Data.ConnectionState.Open)
                {
                    con.Close();
                }
            } catch { }

            return(result);
        }