Exemplo n.º 1
0
        private void UpSert(string Dept, string Site, string Panel, string Alarm, string AlarmType, CurrentUser cuser)
        {
            /* Find If Department Exists or Insert it */
            lkup_department dept = new lkup_department(cuser);
            dept.department_code = Dept;
            dept.LoadSingle();
            if (dept.isNew)
            {
                dept.department_code_description = Dept;
                string desc = dept.ChangedFieldsDescription();
                if (!dept.save())
                {
                    error = new ImportError();
                    error.errorMessage = dept.saveErrorText;
                    error.fieldFQR = dept.friendlySingluarName();
                    error.lineNumber = _line;
                    _importproblems.Add(error);
                }
                else
                {
                    iitem = new ImportedItem(_line, true, dept.friendlySingluarName(), desc);
                    _importeditems.Add(iitem);
                }
            }

            lkup_site site = new lkup_site(cuser);
            site.department_code = Dept;
            site.site_code = Site;
            site.LoadSingle();
            if (site.isNew)
            {
                site.site_code_description = Site;
                string desc = site.ChangedFieldsDescription();
                if (!site.save())
                {
                    error = new ImportError();
                    error.errorMessage = site.saveErrorText;
                    error.fieldFQR = site.friendlySingluarName();
                    error.lineNumber = _line;
                    _importproblems.Add(error);
                }
                else
                {
                    iitem = new ImportedItem(_line, true, site.friendlySingluarName(), desc);
                    _importeditems.Add(iitem);
                }
            }

            lkup_panel panel = new lkup_panel(cuser);
            panel.panel_code = Panel;
            panel.site_code = Site;
            panel.LoadSingle();
            if (panel.isNew)
            {
                panel.alarm_device_code = Alarm;
                panel.panel_code_description = Panel;
                string desc = panel.ChangedFieldsDescription();
                if (!panel.save())
                {
                    error = new ImportError();
                    error.errorMessage = panel.saveErrorText;
                    error.fieldFQR = panel.friendlySingluarName();
                    error.lineNumber = _line;
                    _importproblems.Add(error);
                }
                else
                {
                    iitem = new ImportedItem(_line, true, panel.friendlySingluarName(), desc);
                    _importeditems.Add(iitem);
                }
            }

            lkup_alarm_device alarm = new lkup_alarm_device(cuser);
            alarm.panel_code = Panel;
            alarm.alarm_device_code = Alarm;
            alarm.alarm_type_code = AlarmType;
            alarm.LoadSingle();
            if (alarm.isNew)
            {
                alarm.alarm_device_code_description = Alarm;
                string desc = alarm.ChangedFieldsDescription();
                if (!alarm.save())
                {
                    error = new ImportError();
                    error.errorMessage = alarm.saveErrorText;
                    error.fieldFQR = alarm.friendlySingluarName();
                    error.lineNumber = _line;
                    _importproblems.Add(error);
                }
                else
                {
                    iitem = new ImportedItem(_line, true, alarm.friendlySingluarName(), desc);
                    _importeditems.Add(iitem);
                }
            }
        }
Exemplo n.º 2
0
        public void doImport(bool preview)
        {
            if (!File.Exists(fullFileName))
            {
                error = new ImportError();
                error.errorMessage = fullFileName + " does not exist.";
                _importproblems.Add(error);
                return;
            }
            CurrentUser cuser = new CurrentUser();
            cuser.userName = this.UserName;
            cuser.Load();
            using (StreamReader sr = File.OpenText(fullFileName))
            {
                String inputLine;
                /* Read Header */
                inputLine = sr.ReadLine();
                if (inputLine != null)
                {
                    Dictionary<string, string> headers = this.deviceHeaders;
                    string[] lineHeaders = inputLine.Split('\t');
                    int col = 0;
                    foreach (string str in lineHeaders)
                    {
                        if (headers.ContainsKey(str))
                        {
                            headers[str] = col.ToString();
                            col++;
                        }
                    }
                    Dictionary<string, string> mapFields = this.fieldsMap;
                    string deptcode="", sitecode="", panelcode="", alarmcode="", alarmtype="";
                    _line = 0;
                    while ((inputLine = sr.ReadLine()) != null)
                    {
                        /* Read File Each Line */
                        string[] lineFields = inputLine.Split('\t');
                        _line++;
                        tbl_alarm_time_details alarmDet = new tbl_alarm_time_details(cuser);
                        foreach(string fieldname in headers.Keys)
                        {

                            int idx;
                            int.TryParse(headers[fieldname], out idx);
                            object value = lineFields[idx];

                            PropertyInfo pi = alarmDet.GetType().GetProperty(mapFields[fieldname]);
                            if (pi != null)
                            {
                                value = IntelWebDataConverter.toType(lineFields[idx], pi.PropertyType, "Line: [" + _line.ToString() + "] Field: [" + fieldname + "] Value: [" + (lineFields[idx] ?? "") + "]");

                                pi.SetValue(alarmDet, value, null);

                                if (fieldname.Equals("DEPT/REG"))
                                {
                                    deptcode = value.ToString();
                                }

                                if (fieldname.Equals("SITE"))
                                {
                                    sitecode = value.ToString();
                                }

                                if (fieldname.Equals("PANEL"))
                                {
                                    panelcode = value.ToString();
                                }

                                if (fieldname.Equals("ALARM DEVICE"))
                                {
                                    alarmcode = value.ToString();
                                }
                                if (fieldname.Equals("ALARM TYPE"))
                                {
                                    alarmtype = value.ToString();
                                }
                            }
                        }
                        UpSert(deptcode, sitecode, panelcode, alarmcode, alarmtype, cuser);
                        alarmDet.tier_code = tierCode;
                        alarmDet.LoadSingle();
                        bool isnew = alarmDet.isNew;
                        string desc = alarmDet.ChangedFieldsDescription();
                        if (!alarmDet.save())
                        {
                            error = new ImportError();
                            error.errorMessage = alarmDet.saveErrorText;
                            error.fieldFQR = alarmDet.friendlySingluarName();
                            error.lineNumber = _line;
                            _importproblems.Add(error);
                        }
                        else
                        {
                            iitem = new ImportedItem(_line, isnew, alarmDet.friendlySingluarName(), desc);
                            _importeditems.Add(iitem);
                        }
                    }
                }
            }
            _enddate = DateTime.Now;
        }