Example #1
0
        //public void InitializeClass(string i_sClassID, string i_sClassName, string i_sNamespace, string i_sDescription)
        //{
        //    List<SqlParameter> a = new List<SqlParameter>();
        //    a.Add(new SqlParameter("sID", SqlDbType.VarChar, 100));
        //    a[a.Count - 1].Value = i_sClassID;
        //    a.Add(new SqlParameter("sName", SqlDbType.VarChar, 100));
        //    a[a.Count - 1].Value = i_sClassName;
        //    a.Add(new SqlParameter("sNamespace", SqlDbType.VarChar, 100));
        //    a[a.Count - 1].Value = i_sNamespace;
        //    a.Add(new SqlParameter("sDescription", SqlDbType.VarChar, 2000));
        //    a[a.Count - 1].Value = i_sDescription;
        //    CallSPROC("cClass_Register", a);
        //}

        //public void InitializeClassActions(string i_sClassID, List<cObjectProxy> i_aActions)
        //{
        //    for (int i = 0; i < i_aActions.Count; i++)
        //    {
        //        List<SqlParameter> a = new List<SqlParameter>();
        //        a.Add(new SqlParameter("sClassID", SqlDbType.VarChar, 100));
        //        a[a.Count - 1].Value = i_sClassID;
        //        a.Add(new SqlParameter("iActionID", SqlDbType.Int, 0));
        //        a[a.Count - 1].Value = Convert.ToInt32(i_aActions[i].sID);
        //        a.Add(new SqlParameter("sActionName", SqlDbType.VarChar, 100));
        //        a[a.Count - 1].Value = i_aActions[i].sName;
        //        CallSPROC("cClassAction_Register", a);
        //    }
        //}

        public static string ValidateSQLUpdateParameter(enDataType i_enDataType, string i_sPropertyName, string i_sPropertyValue)
        {
            string sValue = cMSSQL.RemoveUnacceptableSQLCharacters(i_sPropertyValue);

            if (i_sPropertyValue != sValue)
            {
                throw new cInvalidFilterParameterValueException("Suspicious Characters/SQL: " + i_sPropertyName + " = " + i_sPropertyValue);
            }
            string sCode = string.Empty;

            switch (i_enDataType)
            {
            case enDataType.Boolean:
                sCode = Convert.ToBoolean(i_sPropertyValue) ? "1" : "0";
                break;

            case enDataType.Int32:
                sCode = Convert.ToInt32(i_sPropertyValue).ToString();
                break;

            case enDataType.Int64:
                sCode = Convert.ToInt64(i_sPropertyValue).ToString();
                break;

            case enDataType.DateTime:
                sCode = "'" + Convert.ToDateTime(i_sPropertyValue).ToString() + "'";
                break;

            case enDataType.Currency:
                sCode = Convert.ToSingle(i_sPropertyValue).ToString();
                break;

            case enDataType.String:
            case enDataType.NameOfPerson:
            case enDataType.EMailID:
            case enDataType.Phone:
            case enDataType.URL:
            {
                if (i_sPropertyValue.Contains("%"))
                {
                    throw new cInvalidFilterParameterValueException("'%' found : " + i_sPropertyName + " = " + i_sPropertyValue);
                }
                sCode = "'" + i_sPropertyValue + "'";
            }
            break;

            case enDataType.ObjectReference:
                sCode = Convert.ToInt64(i_sPropertyValue).ToString();
                break;

            case enDataType.Float:
                sCode = Convert.ToSingle(i_sPropertyValue).ToString();
                break;

            default:
                throw new cInvalidFilterParameterValueException("Unknown datatype");
            }
            return(sCode);
        }
Example #2
0
        public static enDataType GetPropertyDataTypeFromPrefix(string i_sName)
        {
            string sPrefix = string.Empty;

            for (int i = 0; i < i_sName.Length; i++)
            {
                if (LOWERCASE.Contains(i_sName[i].ToString()))
                {
                    sPrefix += i_sName[i];
                }
                else
                {
                    break;
                }
            }
            enDataType en = enDataType.String;

            switch (sPrefix)
            {
            case "b":
                return(enDataType.Boolean);

            case "i":
                return(enDataType.Int32);

            case "l":
                return(enDataType.Int64);

            case "s":
                return(enDataType.String);

            case "dt":
                return(enDataType.DateTime);

            case "m":
                return(enDataType.Currency);

            case "nm":
                return(enDataType.NameOfPerson);

            case "eml":
                return(enDataType.EMailID);

            case "ph":
                return(enDataType.Phone);

            case "url":
                return(enDataType.URL);

            case "obj":
                return(enDataType.ObjectReference);

            case "f":
                return(enDataType.Float);
            }
            return(en);
        }
Example #3
0
 public cProperty(string i_sName, string i_sDescriptiveName, string i_sDescprition, enDataType i_enType, int i_iSize, bool i_bIsUnique, bool i_bIsSearchable)
 {
     sName = i_sName;
     m_sDescriptiveName = i_sDescriptiveName;
     sDescription       = i_sDescprition;
     enType             = i_enType;
     iSize         = i_iSize;
     bIsUnique     = i_bIsUnique;
     bIsSearchable = i_bIsSearchable;
 }
Example #4
0
 public cProperty(string i_sName, string i_sDescriptiveName, string i_sDescprition, enDataType i_enType, int i_iSize, bool i_bIsUnique, bool i_bIsSearchable)
 {
     sName = i_sName;
     m_sDescriptiveName = i_sDescriptiveName;
     sDescription = i_sDescprition;
     enType = i_enType;
     iSize = i_iSize;
     bIsUnique = i_bIsUnique;
     bIsSearchable = i_bIsSearchable;
 }
Example #5
0
        /// <summary>
        /// loads the systemsdata to a file
        /// </summary>
        /// <param name="File">json-file to save</param>
        /// <param name="Stationtype"></param>
        public void saveSystemData(string Filename, enDataType Systemtype, bool BackupOldFile)
        {
            string newFile, backupFile;

            newFile    = String.Format("{0}_new{1}", Path.Combine(Path.GetDirectoryName(Filename), Path.GetFileNameWithoutExtension(Filename)), Path.GetExtension(Filename));
            backupFile = String.Format("{0}_bak{1}", Path.Combine(Path.GetDirectoryName(Filename), Path.GetFileNameWithoutExtension(Filename)), Path.GetExtension(Filename));

            File.WriteAllText(newFile, JsonConvert.SerializeObject(m_Systems[(int)Systemtype]));

            // we delete the current file not until the new file is written without errors

            rotateSaveFiles(Filename, newFile, backupFile, BackupOldFile);
        }
Example #6
0
        /// <summary>
        /// loads the systemsdata from a file
        /// </summary>
        /// <param name="File">json-file to load</param>
        /// <param name="Stationtype"></param>
        public void loadSystemData(string Filename, enDataType Systemtype, bool createNonExistingFile)
        {
            if (File.Exists(Filename))
            {
                m_Systems[(int)Systemtype] = JsonConvert.DeserializeObject <List <EDSystem> >(File.ReadAllText(Filename));
            }
            else
            {
                m_Systems[(int)Systemtype] = new List <EDSystem>();

                if (createNonExistingFile)
                {
                    saveSystemData(Filename, Systemtype, true);
                }
            }
        }
Example #7
0
        /// <summary>
        /// get all stations for a system from a particular list
        /// </summary>
        /// <param name="Systemname"></param>
        /// <returns></returns>
        public List <EDStation> getStations(string Systemname, enDataType wantedType)
        {
            List <EDStation> retValue;

            EDSystem SystemData = m_Systems[(int)wantedType].Find(x => x.Name == Systemname);

            if (SystemData != null)
            {
                retValue = m_Stations[(int)wantedType].FindAll(x => x.SystemId == SystemData.Id);
            }
            else
            {
                retValue = new List <EDStation>();
            }

            return(retValue);
        }
        public ListViewSorter(ListView lvw, int nColumn, enDataType nDataType)
        {
            m_ListView    = lvw;
            m_nSortColumn = nColumn;
            m_nDataType   = nDataType;

            lvw.ListViewItemSorter = this;
            if (SortOrder.Ascending == lvw.Sorting)
            {
                lvw.Sorting = SortOrder.Descending;
            }
            else
            {
                lvw.Sorting = SortOrder.Ascending;
            }

            lvw.Sort();
            SetColumnSortIcon(lvw, nColumn, lvw.Sorting);
        }
        /// <summary>
        /// loads the systemsdata from a file
        /// </summary>
        /// <param name="File">json-file to load</param>
        /// <param name="Stationtype"></param>
        public void loadSystemData(string Filename, enDataType Systemtype, bool createNonExistingFile)
        { 
            if (File.Exists(Filename))
                m_Systems[(int)Systemtype]   = JsonConvert.DeserializeObject<List<EDSystem>>(File.ReadAllText(Filename));
            else
            { 
                m_Systems[(int)Systemtype] = new List<EDSystem>();

                if (createNonExistingFile)
                    saveSystemData(Filename, Systemtype, true);
            }
                
        }
 /// <summary>
 /// returns a cloned list of the stations
 /// </summary>
 public List<EDStation> cloneStations(enDataType Stationtype)
 { 
     return JsonConvert.DeserializeObject<List<EDStation>>(JsonConvert.SerializeObject(m_Stations[(int)Stationtype]));
 }
 /// <summary>
 /// returns a cloned list of the systems
 /// </summary>
 public List<EDSystem> cloneSystems(enDataType Systemstype)
 { 
     return JsonConvert.DeserializeObject<List<EDSystem>>(JsonConvert.SerializeObject(m_Systems[(int)Systemstype]));
 }
        private List <SerieViewModel> GetSeriesStackedBarChart(List <HistoryStateModel> data, List <string> categories, enDataType chart)
        {
            var series = new List <SerieViewModel>();

            var serieProd = new SerieViewModel();

            serieProd.name  = enState.Production.ToLocalizedString(_contextService.GetContext().ActualLanguage.InitialsLanguage);
            serieProd.color = CommonViewService.GetColorState(enState.Production);
            serieProd.data  = new List <int>();

            var seriePause = new SerieViewModel();

            seriePause.name  = enState.Pause.ToLocalizedString(_contextService.GetContext().ActualLanguage.InitialsLanguage);
            seriePause.color = CommonViewService.GetColorState(enState.Pause);
            seriePause.data  = new List <int>();

            var serieManual = new SerieViewModel();

            serieManual.name  = enState.Manual.ToLocalizedString(_contextService.GetContext().ActualLanguage.InitialsLanguage);
            serieManual.color = CommonViewService.GetColorState(enState.Manual);
            serieManual.data  = new List <int>();

            var serieError = new SerieViewModel();

            serieError.name  = enState.Error.ToLocalizedString(_contextService.GetContext().ActualLanguage.InitialsLanguage);
            serieError.color = CommonViewService.GetColorState(enState.Error);
            serieError.data  = new List <int>();

            // create data foreach categories (operator or shift)
            foreach (var categorie in categories)
            {
                var dataCategorie = new List <HistoryStateModel>();

                switch (chart)
                {
                case enDataType.Operators:
                    dataCategorie = data.Where(w => w.Operator == categorie).ToList();
                    break;
                }

                if (dataCategorie.Count == 0)
                {
                    continue;
                }

                var totalOn = dataCategorie.Where(w => w.enState != enState.Offline).Select(s => s.ElapsedTime).Sum();

                var stateProd = dataCategorie.FirstOrDefault(w => w.enState == enState.Production);

                if (stateProd != null)
                {
                    var     totalProd = stateProd.ElapsedTime;
                    decimal?percProd  = Common.GetPercentage(totalProd, totalOn);
                    serieProd.data.Add(((decimal)percProd).RoundToInt());
                }
                else
                {
                    serieProd.data.Add(0);
                }

                var stateManual = dataCategorie.FirstOrDefault(w => w.enState == enState.Manual);

                if (stateManual != null)
                {
                    var     totalManual = stateManual.ElapsedTime;
                    decimal?percManual  = Common.GetPercentage(totalManual, totalOn);
                    serieManual.data.Add(((decimal)percManual).RoundToInt());
                }
                else
                {
                    serieManual.data.Add(0);
                }

                var statePause = dataCategorie.FirstOrDefault(w => w.enState == enState.Pause);

                if (statePause != null)
                {
                    var     totalPause = statePause.ElapsedTime;
                    decimal?percPause  = Common.GetPercentage(totalPause, totalOn);
                    seriePause.data.Add(((decimal)percPause).RoundToInt());
                }
                else
                {
                    seriePause.data.Add(0);
                }

                var stateError = dataCategorie.FirstOrDefault(w => w.enState == enState.Error);

                if (stateError != null)
                {
                    var     totalError = stateError.ElapsedTime;
                    decimal?percError  = Common.GetPercentage(totalError, totalOn);
                    serieError.data.Add(((decimal)percError).RoundToInt());
                }
                else
                {
                    serieError.data.Add(0);
                }
            }

            series.Add(serieError);
            series.Add(seriePause);
            series.Add(serieManual);
            series.Add(serieProd);

            return(series);
        }
Example #13
0
        public void SaveBlobsFromTable(string table, string idcolumn, string datacolumn, enDataType datatype, string savepath)
        {
            switch (DatabaseType)
            {
            case enDatabaseType.MySql:
                mysqlConnector.SaveBlobsFromTable(table, idcolumn, datacolumn, datatype.ToString(), savepath); break;

            case enDatabaseType.MSSql:
                mssqlConnector.SaveBlobsFromTable(table, idcolumn, datacolumn, datatype.ToString(), savepath); break;

            case enDatabaseType.FireBird:
                throw new NotImplementedException("Funksjon ikke tilgjengelig for FireBird-db");
            }
        }
Example #14
0
        /// <summary>
        ///     Ritorna gli allarmi n base a tipo di dati da visualizzare in base al tipo di aggregazione
        /// </summary>
        /// <param name="machine"></param>
        /// <param name="period"></param>
        /// <param name="dataType"></param>
        /// <param name="actualMachineGroup"></param>
        /// <returns>Lista dei dettagli degli stati</returns>
        public List <HistoryMessageModel> GetAggregationMessages(MachineInfoModel machine, PeriodModel period,
                                                                 enDataType dataType, string actualMachineGroup = null)
        {
            try
            {
                var cl = _languageService.GetCurrentLanguage() ?? 0;

                var machineGroup = _context.Set <MachineGroup>()
                                   .FirstOrDefault(n => n.MachineGroupName == actualMachineGroup)?.Id;

                List <int> messTypes = (new int[] { 11, 12 }).ToList();
                bool       limitTime = true;
                var        role      = _accountService.GetLoggedUser().Role;
                if (role == enRole.Assistance || role == enRole.RandD || role == enRole.Administrator)
                {
                    messTypes.Add(13);
                    limitTime = false;
                }

                var queryResult = _historyMessageRepository
                                  .GetHistoryMessage(machine.Id, period.StartDate, period.EndDate, machineGroup, messTypes, limitTime);
                switch (dataType)
                {
                case enDataType.Historical:
                    switch (period.Aggregation)
                    {
                    case enAggregation.Day:
                    {
                        int?Func(HistoryMessage hs)
                        {
                            return(hs.Period);
                        }

                        const string typeHistory = "d";
                        var          result      = BuildAggregationList(queryResult, typeHistory, Func);
                        return(result.ToList());
                    }

                    case enAggregation.Week:
                    {
                        int?Func(HistoryMessage hs)
                        {
                            return(hs.Day.HasValue
                                        ? (int?)hs.Day.Value.Year * 100 + hs.Day.Value.GetWeekNumber()
                                        : null);
                        }

                        const string typeHistory = "w";
                        var          result      = BuildAggregationList(queryResult, typeHistory, Func);
                        return(result.ToList());
                    }

                    case enAggregation.Month:
                    {
                        int?Func(HistoryMessage hs)
                        {
                            return(hs.Day.HasValue ? (int?)hs.Day.Value.Year * 100 + hs.Day.Value.Month : null);
                        }

                        const string typeHistory = "m";
                        var          result      = BuildAggregationList(queryResult, typeHistory, Func);
                        return(result.ToList());
                    }

                    case enAggregation.Quarter:
                    {
                        int?Func(HistoryMessage hs)
                        {
                            return(hs.Day.HasValue
                                        ? (int?)hs.Day.Value.Year * 100 + GetQuarter(hs.Day ?? DateTime.UtcNow)
                                        : null);
                        }

                        const string typeHistory = "q";
                        var          result      = BuildAggregationList(queryResult, typeHistory, Func);
                        return(result.ToList());
                    }

                    case enAggregation.Year:
                    {
                        int?Func(HistoryMessage hs)
                        {
                            return(hs.Day.HasValue ? (int?)hs.Day.Value.Year * 100 + hs.Day.Value.Year : null);
                        }

                        const string typeHistory = "y";
                        var          result      = BuildAggregationList(queryResult, typeHistory, Func);
                        return(result.ToList());
                    }
                    }

                    break;

                case enDataType.Summary:
                    var historyMessagesSummary = _historyMessageRepository
                                                 .GetHistoryMessage(machine.Id, period.StartDate, period.EndDate, machineGroup, messTypes, limitTime)
                                                 .GroupBy(g => new
                    {
                        g.MachineId,
                        Description = g.GetDescription(cl),
                        g.MessagesIndex.MessageCode,
                        g.MessagesIndex?.MessageTypeId
                    }).ToList().Select(s => new AggregationMessageModel
                    {
                        Id          = s.Max(m => m.Id),
                        Code        = s.Key.MessageCode,
                        Count       = s.Sum(i => i.Count),
                        Day         = s.Max(i => i.Day),
                        MachineId   = s.Key.MachineId,
                        TypeHistory = "y",
                        Description = s.Key.Description,
                        Type        = s.Key.MessageTypeId
                    }).ToList();

                    return(historyMessagesSummary.BuildAdapter().AdaptToType <List <HistoryMessageModel> >());
                }
            }
            catch (Exception ex)
            {
                var errMessage = string.Format(ex.GetStringLog(),
                                               machine.Id.ToString(),
                                               string.Concat(period.StartDate.ToString(), " - ", period.EndDate.ToString(), " - ",
                                                             period.Aggregation.ToString()),
                                               dataType.ToString());
                LogService.WriteLog(errMessage, LogService.TypeLevel.Error, ex);
            }

            return(new List <HistoryMessageModel>());
        }
Example #15
0
        private void Data_Proc(byte[] data)
        {
            try
            {
                Console.WriteLine("[Data수신]" + Fnc.ByteArray2HexString(data, " "));
                //헤더 체크
                if (!Fnc.bytesEqual(data, 0, _bytHeader, 0, _bytHeader.Length))
                {
                    Log_Write("헤더 불일치", enCmdType.None, true);
                    return;
                }

                string log = string.Empty;

                enCmdType cmd = enCmdType.None;

                //20~21 명령 타입
                switch (data[20])
                {
                case 0x54:           //read command
                    cmd = enCmdType.Read;
                    break;

                case 0x58:           //write command
                    cmd = enCmdType.Write;
                    break;

                case 0xBD:
                    byte[] bytData = new byte[] { 0x01, 0xff };
                    Server.Send(bytData);
                    break;

                default:
                    break;
                }

                if (cmd == enCmdType.None)
                {
                    return;
                }

                //22-23데이터타입
                enDataType dType = enDataType.Block;

                if (data[22] != 0x14)
                {
                    dType = enDataType.Unit;
                }


                //24-25 예약

                //26-27 변수 개수
                int cnt = fnc.ByteToInt(data, 26, 2);

                int     idx  = 28;
                int     ridx = 30;
                DataRow dr;
                string  add = string.Empty;
                byte[]  send;
                int     value;
                int     vLen;

                //log = string.Format("[{0}]", cmd);

                if (dType == enDataType.Block)
                {
                    vLen = fnc.ByteToInt(data, idx, 2);
                    cnt  = fnc.ByteToInt(data, idx + 2 + vLen, 2);

                    cnt = Multiple > 1 ? cnt / Multiple : cnt;
                }

                if (cmd == enCmdType.Read)
                {
                    if (dType == enDataType.Unit)
                    {
                        send = new byte[32 + cnt * 4];
                    }
                    else
                    {
                        send = new byte[32 + cnt * 2];
                    }
                }
                else
                {
                    send = new byte[30];
                }


                for (int i = 0; i < cnt; i++)
                {
                    //처음이거나 처리단위가 유닛이면
                    if (i == 0 || dType == enDataType.Unit)
                    {
                        //28-29 변수명 길이
                        vLen = fnc.ByteToInt(data, idx, 2);
                        idx += 2;

                        //30~   변수명
                        add  = fnc.BytesToAscii(data, idx, vLen);
                        add  = fnc.Address_SetAddType(add, Multiple);
                        idx += vLen;
                    }
                    else
                    {   //블록단위(연속처리)
                        add = fnc.Address_NetGet(add);
                    }

                    if (_dtAdd.Select(string.Format("Address = '{0}'", add)).Length > 0)
                    {
                        dr = _dtAdd.Select(string.Format("Address = '{0}'", add))[0];
                    }
                    else
                    {
                        dr            = _dtAdd.NewRow();
                        dr["Address"] = add;
                        dr["Value"]   = 0;
                        _dtAdd.Rows.Add(dr);
                    }


                    if (cmd == enCmdType.Read)
                    {
                        if (dType == enDataType.Unit)
                        {
                            //data size
                            fnc.ByteSetIntValue(send, ridx, 2, 2);
                            ridx += 2;
                        }

                        //datavalue
                        fnc.ByteSetIntValue(send, ridx, 2, Fnc.obj2int(dr["Value"]));
                        ridx += 2;

                        //if (i == 0 && dType == enDataType.Block & cnt > 1)
                        //    log += string.Format("[{0}", add);
                        //else if (i == 0 || dType == enDataType.Unit)
                        //    log += string.Format("[{0}] ", add);

                        log += string.Format("[{0}]{1} ", add, dr["Value"]);
                    }
                    else if (cmd == enCmdType.Write)
                    {
                        //값 길이
                        vLen = fnc.ByteToInt(data, idx, 2);
                        idx += 2;

                        //값
                        value = fnc.ByteToInt(data, idx, vLen);
                        value = Multiple > 1 ? value / Multiple : value;

                        log += string.Format("[{0}]{1}=>{2} ", add, dr["Value"], value);

                        dr["Value"] = value;
                        idx        += 2;
                    }
                }

                //if (cmd == enCmdType.Read && dType == enDataType.Block && cnt > 1)
                //{
                //    log += string.Format("~{0}] ", add);
                //}


                _bytHeader.CopyTo(send, 0);

                //plc info 10~11
                send[11] = 1;

                //cpu info [A0]XGK [A4]XGI [A8]XGR
                send[12] = data[12];

                //source of frame
                send[13] = 0x11;

                //invoke id
                send[14] = data[14];
                send[15] = data[15];

                //length
                fnc.ByteSetIntValue(send, 16, 2, send.Length);

                //response type
                if (cmd == enCmdType.Read)
                {
                    send[20] = 0x55;
                    //data type
                    send[22] = data[22];

                    //data cnt
                    fnc.ByteSetIntValue(send, 28, 2, cnt);

                    //data size
                    //fnc.ByteSetIntValue(send, 30, 2, 2);
                }
                else if (cmd == enCmdType.Write)
                {
                    send[20] = (byte)(dType == enDataType.Block ? 0x59 : 0x58);
                    send[20] = 0x59;
                    //data type
                    send[22] = data[22];

                    //data cnt
                    fnc.ByteSetIntValue(send, 28, 2, cnt);
                }



                Log_Write(log, cmd, false);

                Server.Send(send);
            }
            catch (Exception ex)
            {
                ProcException(ex, "Data_Proc");
            }
        }
 /// <summary>
 /// returns all systems
 /// </summary>
 public List<EDSystem> getSystems(enDataType Systemtype)
 { 
     return m_Systems[(int)Systemtype];
 }
        /// <summary>
        /// loads the systemsdata to a file
        /// </summary>
        /// <param name="File">json-file to save</param>
        /// <param name="Stationtype"></param>
        public void saveSystemData(string Filename, enDataType Systemtype, bool BackupOldFile)
        { 
            string newFile, backupFile;

            newFile = String.Format("{0}_new{1}", Path.Combine(Path.GetDirectoryName(Filename), Path.GetFileNameWithoutExtension(Filename)), Path.GetExtension(Filename));
            backupFile = String.Format("{0}_bak{1}", Path.Combine(Path.GetDirectoryName(Filename), Path.GetFileNameWithoutExtension(Filename)), Path.GetExtension(Filename));

            File.WriteAllText(newFile, JsonConvert.SerializeObject(m_Systems[(int)Systemtype]));
            
            // we delete the current file not until the new file is written without errors

            rotateSaveFiles(Filename, newFile, backupFile, BackupOldFile);
        }
Example #18
0
 /// <summary>
 /// returns a cloned list of the systems
 /// </summary>
 public List <EDSystem> cloneSystems(enDataType Systemstype)
 {
     return(JsonConvert.DeserializeObject <List <EDSystem> >(JsonConvert.SerializeObject(m_Systems[(int)Systemstype])));
 }
Example #19
0
 /// <summary>
 /// returns a cloned list of the stations
 /// </summary>
 public List <EDStation> cloneStations(enDataType Stationtype)
 {
     return(JsonConvert.DeserializeObject <List <EDStation> >(JsonConvert.SerializeObject(m_Stations[(int)Stationtype])));
 }
        /// <summary>
        /// get all stations for a system from a particular list
        /// </summary>
        /// <param name="Systemname"></param>
        /// <returns></returns>
        public List<EDStation> getStations(string Systemname, enDataType wantedType)
        {
            List<EDStation> retValue;

            EDSystem SystemData = m_Systems[(int)wantedType].Find(x => x.Name==Systemname);

            if (SystemData != null)
                retValue = m_Stations[(int)wantedType].FindAll(x => x.SystemId==SystemData.Id);
            else
                retValue = new List<EDStation>();

            return retValue;
        }
Example #21
0
 /// <summary>
 /// returns all systems
 /// </summary>
 public List <EDSystem> getSystems(enDataType Systemtype)
 {
     return(m_Systems[(int)Systemtype]);
 }
 /// <summary>
 /// returns all stations
 /// </summary>
 public List<EDStation> getStations(enDataType Stationtype)
 { 
     return m_Stations[(int)Stationtype];
 }
Example #23
0
 /// <summary>
 /// returns all stations
 /// </summary>
 public List <EDStation> getStations(enDataType Stationtype)
 {
     return(m_Stations[(int)Stationtype]);
 }
Example #24
0
        //public void InitializeClass(string i_sClassID, string i_sClassName, string i_sNamespace, string i_sDescription)
        //{
        //    List<SqlParameter> a = new List<SqlParameter>();
        //    a.Add(new SqlParameter("sID", SqlDbType.VarChar, 100));
        //    a[a.Count - 1].Value = i_sClassID;
        //    a.Add(new SqlParameter("sName", SqlDbType.VarChar, 100));
        //    a[a.Count - 1].Value = i_sClassName;
        //    a.Add(new SqlParameter("sNamespace", SqlDbType.VarChar, 100));
        //    a[a.Count - 1].Value = i_sNamespace;
        //    a.Add(new SqlParameter("sDescription", SqlDbType.VarChar, 2000));
        //    a[a.Count - 1].Value = i_sDescription;
        //    CallSPROC("cClass_Register", a);
        //}

        //public void InitializeClassActions(string i_sClassID, List<cObjectProxy> i_aActions)
        //{
        //    for (int i = 0; i < i_aActions.Count; i++)
        //    {
        //        List<SqlParameter> a = new List<SqlParameter>();
        //        a.Add(new SqlParameter("sClassID", SqlDbType.VarChar, 100));
        //        a[a.Count - 1].Value = i_sClassID;
        //        a.Add(new SqlParameter("iActionID", SqlDbType.Int, 0));
        //        a[a.Count - 1].Value = Convert.ToInt32(i_aActions[i].sID);
        //        a.Add(new SqlParameter("sActionName", SqlDbType.VarChar, 100));
        //        a[a.Count - 1].Value = i_aActions[i].sName;
        //        CallSPROC("cClassAction_Register", a);
        //    }
        //}

        public static string ValidateSQLUpdateParameter(enDataType i_enDataType, string i_sPropertyName, string i_sPropertyValue)
        {
            string sValue = cMSSQL.RemoveUnacceptableSQLCharacters(i_sPropertyValue);
            if (i_sPropertyValue != sValue) throw new cInvalidFilterParameterValueException("Suspicious Characters/SQL: " + i_sPropertyName + " = " + i_sPropertyValue);
            string sCode = string.Empty;
            switch (i_enDataType)
            {
                case enDataType.Boolean:
                    sCode = Convert.ToBoolean(i_sPropertyValue) ? "1" : "0";
                    break;
                case enDataType.Int32:
                    sCode = Convert.ToInt32(i_sPropertyValue).ToString();
                    break;
                case enDataType.Int64:
                    sCode = Convert.ToInt64(i_sPropertyValue).ToString();
                    break;
                case enDataType.DateTime:
                    sCode = "'" + Convert.ToDateTime(i_sPropertyValue).ToString() + "'";
                    break;
                case enDataType.Currency:
                    sCode = Convert.ToSingle(i_sPropertyValue).ToString();
                    break;
                case enDataType.String:
                case enDataType.NameOfPerson:
                case enDataType.EMailID:
                case enDataType.Phone:
                case enDataType.URL:
                    {
                        if (i_sPropertyValue.Contains("%")) throw new cInvalidFilterParameterValueException("'%' found : " + i_sPropertyName + " = " + i_sPropertyValue);
                        sCode = "'" + i_sPropertyValue + "'";
                    }
                    break;
                case enDataType.ObjectReference:
                    sCode = Convert.ToInt64(i_sPropertyValue).ToString();
                    break;
                case enDataType.Float:
                    sCode = Convert.ToSingle(i_sPropertyValue).ToString();
                    break;
                default:
                    throw new cInvalidFilterParameterValueException("Unknown datatype");
            }
            return sCode;
        }
 public void SaveBlobsFromTable(string table, string idcolumn, string datacolumn, enDataType datatype, string savepath)
 {
     switch (DatabaseType)
     {
         case enDatabaseType.MySql:
             mysqlConnector.SaveBlobsFromTable(table, idcolumn, datacolumn, datatype.ToString(), savepath); break;
         case enDatabaseType.MSSql:
             mssqlConnector.SaveBlobsFromTable(table, idcolumn, datacolumn, datatype.ToString(), savepath); break;
         case enDatabaseType.FireBird:
             throw new NotImplementedException("Funksjon ikke tilgjengelig for FireBird-db");
     }
 }
Example #26
0
        /// <summary>
        ///     Ritorna gli aggregati pieces in base al tipo di aggregazione
        /// </summary>
        /// <param name="machine"></param>
        /// <param name="period"></param>
        /// <param name="dataType"></param>
        /// <returns>Lista dei dettagli degli stati</returns>
        public List <HistoryPieceModel> GetAggregationPieces(MachineInfoModel machine, PeriodModel period,
                                                             enDataType dataType)
        {
            var result = new List <HistoryPieceModel>();

            try
            {
                var query = _context.Set <HistoryPiece>().Where(hp => hp.MachineId == machine.Id &&
                                                                hp.Day >= period.StartDate &&
                                                                hp.Day <= period.EndDate);
                switch (dataType)
                {
                case enDataType.Dashboard:
                    result = query.Where(hp => hp.Shift == null && hp.Operator == null).ToList()
                             .GroupBy(g => g.System).Select(n => new HistoryPieceModel
                    {
                        Id                   = n.Max(i => i.Id),
                        CompletedCount       = n.Sum(i => i.CompletedCount),
                        Day                  = n.Max(i => i.Day),
                        ElapsedTime          = n.Sum(i => i.ElapsedTime),
                        ElapsedTimeProducing = n.Sum(i => i.ElapsedTimeProducing),
                        ElapsedTimeCut       = n.Sum(i => i.ElapsedTimeCut),
                        ElapsedTimeWorking   = n.Sum(i => i.ElapsedTimeWorking),
                        ElapsedTimeTrim      = n.Sum(i => i.ElapsedTimeTrim),
                        MachineId            = machine.Id,
                        Operator             = null,
                        Period               = null,
                        PieceLengthSum       = n.Sum(i => i.PieceLengthSum),
                        RedoneCount          = n.Sum(i => i.RedoneCount),
                        Shift                = null,
                        System               = n.Key,
                        TypeHistory          = "d"
                    }).ToList();
                    break;

                case enDataType.Historical:
                {
                    var queryResult = query.Where(hp => hp.Shift == null && hp.Operator == null).ToList();
                    switch (period.Aggregation)
                    {
                    case enAggregation.Day:
                    {
                        int?Func(HistoryPiece hs)
                        {
                            return(hs.Period);
                        }

                        const string typeHistory = "d";
                        var          res         = BuildAggregationList(queryResult, typeHistory, Func);
                        return(res.ToList());
                    }

                    case enAggregation.Week:
                    {
                        int?Func(HistoryPiece hs)
                        {
                            return(hs.WeekOfYearDay);
                        }

                        const string typeHistory = "w";
                        var          res         = BuildAggregationList(queryResult, typeHistory, Func);
                        return(res.ToList());
                    }

                    case enAggregation.Month:
                    {
                        int?Func(HistoryPiece hs)
                        {
                            return(hs.Day.Month);
                        }

                        const string typeHistory = "m";
                        var          res         = BuildAggregationList(queryResult, typeHistory, Func);
                        return(res.ToList());
                    }

                    case enAggregation.Quarter:
                    {
                        int?Func(HistoryPiece hs)
                        {
                            return(hs.QuarteOfYearDay);
                        }

                        const string typeHistory = "q";
                        var          res         = BuildAggregationList(queryResult, typeHistory, Func);
                        return(res.ToList());
                    }

                    case enAggregation.Year:
                    {
                        int?Func(HistoryPiece hs)
                        {
                            return(hs.Day.Year);
                        }

                        const string typeHistory = "y";
                        var          res         = BuildAggregationList(queryResult, typeHistory, Func);
                        return(res.ToList());
                    }
                    }

                    break;
                }

                case enDataType.Operators:
                    result = query.Where(hp => hp.Shift == null && hp.Operator != null).ToList()
                             .GroupBy(g => new { g.System, g.Operator })
                             .Select(n => new HistoryPieceModel
                    {
                        Id                   = n.Max(i => i.Id),
                        CompletedCount       = n.Sum(i => i.CompletedCount),
                        Day                  = n.Max(i => i.Day),
                        ElapsedTime          = n.Sum(i => i.ElapsedTime),
                        ElapsedTimeProducing = n.Sum(i => i.ElapsedTimeProducing),
                        ElapsedTimeCut       = n.Sum(i => i.ElapsedTimeCut),
                        ElapsedTimeWorking   = n.Sum(i => i.ElapsedTimeWorking),
                        ElapsedTimeTrim      = n.Sum(i => i.ElapsedTimeTrim),
                        MachineId            = machine.Id,
                        Operator             = n.Key.Operator,
                        Period               = null,
                        PieceLengthSum       = n.Sum(i => i.PieceLengthSum),
                        RedoneCount          = n.Sum(i => i.RedoneCount),
                        Shift                = null,
                        System               = n.Key.System,
                        TypeHistory          = "d"
                    }).ToList();
                    break;
                }
            }
            catch (Exception ex)
            {
                var errMessage = string.Format(ex.GetStringLog(),
                                               machine.Id.ToString(),
                                               string.Concat(period.StartDate.ToString(CultureInfo.InvariantCulture), " - ", period.EndDate.ToString(CultureInfo.InvariantCulture), " - ",
                                                             period.Aggregation.ToString(),
                                                             dataType.ToString()));
                LogService.WriteLog(errMessage, LogService.TypeLevel.Error, ex);
            }

            return(result);
        }
Example #27
0
        /// <summary>
        ///     Ritorna gli aggregati degli stati in mase al tipo di aggregazione
        /// </summary>
        /// <param name="machine"></param>
        /// <param name="period"></param>
        /// <param name="dataType"></param>
        /// <returns>Lista dei dettagli degli stati</returns>
        public List <HistoryStateModel> GetAggregationStates(MachineInfoModel machine, PeriodModel period,
                                                             enDataType dataType)
        {
            try
            {
                IEnumerable <HistoryState> queryResult;
                switch (dataType)
                {
                case enDataType.Dashboard:
                    queryResult = _historyStateRepository.Get(hs => hs.Day <= period.EndDate &&
                                                              hs.Day >= period.StartDate &&
                                                              hs.MachineId == machine.Id &&
                                                              hs.Shift == null &&
                                                              hs.Operator == null);
                    return(BuildHistoryStateModelsOperatorDashboard(queryResult));

                case enDataType.Operators:
                    queryResult = _historyStateRepository.Get(hs => hs.Day <= period.EndDate &&
                                                              hs.Day >= period.StartDate &&
                                                              hs.MachineId == machine.Id &&
                                                              hs.Shift == null &&
                                                              hs.Operator != null);
                    return(BuildHistoryStateModelsOperatorDashboard(queryResult));

                case enDataType.Historical:
                {
                    queryResult = _historyStateRepository.Get(hs => hs.Day <= period.EndDate &&
                                                              hs.Day >= period.StartDate &&
                                                              hs.MachineId == machine.Id &&
                                                              hs.Shift == null &&
                                                              hs.Operator == null, null, "State");
                    switch (period.Aggregation)
                    {
                    case enAggregation.Day:
                    {
                        int?Func(HistoryState hs)
                        {
                            return(hs.Period);
                        }

                        const string typeHistory = "d";
                        var          result      = BuildAggregationList(queryResult, typeHistory, Func);
                        return(result.ToList());
                    }

                    case enAggregation.Week:
                    {
                        int?Func(HistoryState hs)
                        {
                            if (hs.Day != null)
                            {
                                return(hs.Day.Value.Year * 100 + hs.Day.Value.GetWeekNumber());
                            }
                            return(null);
                        }

                        const string typeHistory = "w";
                        var          result      = BuildAggregationList(queryResult, typeHistory, Func);
                        return(result.ToList());
                    }

                    case enAggregation.Month:
                    {
                        int?Func(HistoryState hs)
                        {
                            if (hs.Day != null)
                            {
                                return(hs.Day.Value.Year * 100 + hs.Day.Value.Month);
                            }
                            return(null);
                        }

                        const string typeHistory = "m";
                        var          result      = BuildAggregationList(queryResult, typeHistory, Func);
                        return(result.ToList());
                    }

                    case enAggregation.Quarter:
                    {
                        int?Func(HistoryState hs)
                        {
                            if (hs.Day != null)
                            {
                                return(hs.Day.Value.Year * 100 + hs.Day.Value.GetQuarter());
                            }
                            return(null);
                        }

                        const string typeHistory = "q";
                        var          result      = BuildAggregationList(queryResult, typeHistory, Func);
                        return(result.ToList());
                    }

                    case enAggregation.Year:
                    {
                        int?Func(HistoryState hs)
                        {
                            if (hs.Day != null)
                            {
                                return(hs.Day.Value.Year * 100 + hs.Day.Value.Year);
                            }
                            return(null);
                        }

                        const string typeHistory = "y";
                        var          result      = BuildAggregationList(queryResult, typeHistory, Func);
                        return(result.ToList());
                    }
                    }

                    break;
                }
                }
            }
            catch (Exception ex)
            {
                var errMessage = string.Format(ex.GetStringLog(),
                                               machine.Id.ToString(),
                                               string.Concat(period.StartDate.ToString(CultureInfo.InvariantCulture), " - ",
                                                             period.EndDate.ToString(CultureInfo.InvariantCulture), " - ", period.Aggregation.ToString()),
                                               dataType.ToString());
                LogService.WriteLog(errMessage, LogService.TypeLevel.Error, ex);
            }

            return(null);
        }