Exemplo n.º 1
0
        private void saveToCSV()
        {
            int eventType = tCmb_LogsType.SelectedIndex + 1;
            List <UIDataGrid> gridList;
            DataGrid          grid;

            switch (eventType)
            {
            case (int)LOG_TABLE_TYPE.LOG_TABLE_TYPE_CALIBRATION:
            {
                logFiles = new LogToFile("Incom_Utility_Calibration_Log", "csv");
                grid     = grid_LogCal;
                gridList = logCalList;
                break;
            }

            case (int)LOG_TABLE_TYPE.LOG_TABLE_TYPE_ALARM:
            {
                logFiles = new LogToFile("Incom_Utility_Alarm_Log", "csv");
                grid     = grid_LogAlarm;
                gridList = logAlarmList;
                break;
            }

            case (int)LOG_TABLE_TYPE.LOG_TABLE_TYPE_FAULT:
            {
                logFiles = new LogToFile("Incom_Utility_Fault_Log", "csv");
                grid     = grid_LogFault;
                gridList = logFaultList;
                break;
            }

            case (int)LOG_TABLE_TYPE.LOG_TABLE_TYPE_WARNING:
            {
                logFiles = new LogToFile("Incom_Utility_Warining_Log", "csv");
                grid     = grid_LogWarning;
                gridList = logWarningList;
                break;
            }

            case (int)LOG_TABLE_TYPE.LOG_TABLE_TYPE_REFLEX:
            {
                logFiles = new LogToFile("Incom_Utility_Reflex_Log", "csv");
                grid     = grid_LogRelfex;
                gridList = logReflexList;
                break;
            }

            case (int)LOG_TABLE_TYPE.LOG_TABLE_TYPE_INFO:
            {
                logFiles = new LogToFile("Incom_Utility_Info_Log", "csv");
                grid     = grid_LogInfo;
                gridList = logInfoList;
                break;
            }

            default:
            {
                return;
            }
            }

            string filePath = logFiles.Checked();

            if (filePath == null)
            {
                return;
            }

            string strHeader  = "";
            int    columCount = grid.Columns.Count;

            for (int i = 0; i < columCount; i++)
            {
                if (i == grid.Columns.Count - 1)
                {
                    strHeader += grid.Columns[i].Header.ToString();
                    break;
                }
                strHeader += grid.Columns[i].Header.ToString() + ",";
            }
            logFiles.SetDataHeader(strHeader);

            for (int i = 0; i < gridList.Count; i++)
            {
                string strWrite = UIDataGrid.getDataToStr(gridList[i], columCount);
                logFiles.Write(strWrite);
            }

            logFiles.Unchecked();
            MessageBox.Show("Saved CSV file");
        }