Пример #1
0
        public bool UpdateLineStatusWithTime(string client, string line, bool on, string strEventTime)
        {
            try
            {
                if (string.IsNullOrEmpty(strEventTime))
                    return false;

                DateTime eventTime;

                if (!DateTime.TryParse(strEventTime, out eventTime))
                    return false;

                using (DB db = new DB())
                {
                    LineStatus lineStat = (from o in db.LineStatus
                                           where o.Client == client
                                           && o.Line == line
                                           select o).FirstOrDefault();

                    bool result = false;

                    if (lineStat != null)
                    {
                        if (on != lineStat.Status || lineStat.Status == true)//Only log False once, but constantly update time for True
                        {
                            lineStat.Status = on;
                            lineStat.EventTime = eventTime;

                            result = db.SaveChanges() > 0;
                        }
                    }
                    else
                    {
                        lineStat = new LineStatus();
                        lineStat.Client = client;
                        lineStat.Line = line;
                        lineStat.Status = on;
                        lineStat.ShiftStart = "06:00:00";
                        lineStat.Timezone = "Eastern Standard Time";
                        lineStat.EventTime = eventTime;

                        db.AddToLineStatus(lineStat);

                        result = db.SaveChanges() > 0;
                    }

                    if (result == true)
                    {
                        DBHelper.UpdateAscommPing(client, DateTime.Now, line, true);
                    }

                    return result;
                }
            }
            catch (Exception ex)
            {
                String fileName = this.Server.MapPath("~/App_Data/log.txt");
                File.AppendAllText(fileName, ex.ToString());
                throw ex;
            }
        }