Ejemplo n.º 1
0
 public void LoadReport(string reportname, string reportsconfig)
 {
     if (reportname.Length > 0)
     {
         ReportName = reportname;
         byte[] image = Data.GetReportData(reportname);
         if (image != null)
         {
             MemIniFile mif = new MemIniFile(String.Empty);
             mif.FromString(reportsconfig);
             this.PrintAuto   = mif.ReadBool(reportname, "PrintAuto", false);
             this.PrintTime   = mif.ReadDate(reportname, "PrintTime", DateTime.Parse("08:05:00"));
             this.PrintPeriod = mif.ReadInteger(reportname, "PrintPeriod", 0);
             //------------------------------------------
             SelList.Clear();
             PlotList.Clear();
             GC.Collect();
             string          content = Encoding.Unicode.GetString(image);
             PrinterSettings ps      = printDocument.PrinterSettings;
             string[]        lines   = content.Split(new string[] { "\r\n" }, StringSplitOptions.None);
             ImportLines(ref ps, lines);
             printDocument.PrinterSettings = ps;
             Update();
         }
     }
 }
Ejemplo n.º 2
0
        private static string configString(string content, string channelkey)
        {
            MemIniFile mif = new MemIniFile(String.Empty);

            mif.FromString(content);
            if (mif.SectionExists(servname) && mif.KeyExists(servname, channelkey))
            {
                return(mif.ReadString(servname, channelkey, String.Empty));
            }
            return(String.Empty);
        }
Ejemplo n.º 3
0
        private void saveCustomReportProps()
        {
            //Data.SetReportProps(printReport.ReportName, printReport.PrintAuto,
            //    printReport.PrintTime, printReport.PrintPeriod);
            MemIniFile mif = new MemIniFile(String.Empty);

            mif.FromString(Properties.Settings.Default.ReportsConfig);
            mif.WriteString(internalname, "ReportName", printReport.ReportName);
            mif.WriteBool(internalname, "PrintAuto", printReport.PrintAuto);
            mif.WriteDate(internalname, "PrintTime", printReport.PrintTime);
            mif.WriteInteger(internalname, "PrintPeriod", printReport.PrintPeriod);
            //mif.UpdateFile();
            Properties.Settings settings = Properties.Settings.Default;
            settings.ReportsConfig = mif.ToString();
            settings.Save();
        }
Ejemplo n.º 4
0
        private void AutoPrintReports(DateTime now)
        {
            MemIniFile mif = new MemIniFile(String.Empty);

            mif.FromString(Properties.Settings.Default.ReportsConfig);
            // выбор автозапускаемых отчётов на текущее время в список list
            List <string> list = new List <string>();

            foreach (string section in mif.ReadSections())
            {
                bool auto = mif.ReadBool(section, "PrintAuto", false);
                if (auto)
                {
                    string   name   = mif.ReadString(section, "ReportName", section);
                    DateTime time   = mif.ReadDate(section, "PrintTime", DateTime.Parse("08:05:00"));
                    int      period = mif.ReadInteger(section, "PrintPeriod", 0);
                    if (period == 0) // ежедневно
                    {
                        if (time.Hour == now.Hour && time.Minute == now.Minute)
                        {
                            list.Add(name);
                        }
                    }
                    else if (period == 1) // ежемесячно 1 числа
                    {
                        if (now.Day == 1 && time.Hour == now.Hour &&
                            time.Minute == now.Minute)
                        {
                            list.Add(name);
                        }
                    }
                }
            }
            // отправка на печать отчётов, печатаемых в настоящий момент
            foreach (string name in list)
            {
                using (PrintDocument printDoc = new PrintDocument())
                {
                    printDoc.PrintPage += printDoc_PrintPage;
                    printReport         = new PrintReport(printDoc);
                    printReport.LoadReport(name, Properties.Settings.Default.ReportsConfig);
                    printDoc.Print();
                    printDoc.PrintPage -= printDoc_PrintPage;
                }
            }
        }
Ejemplo n.º 5
0
        public static void StartFetch(string[] args)
        {
            string ApplicationStartupPath = (args.Length >= 1) ? args[0] : String.Empty;
            string ConfigContent          = (args.Length >= 2) ? args[1] : String.Empty;

            Station = (args.Length >= 3) ? int.Parse(args[2]) : 0;
            //
            MemIniFile mif = new MemIniFile(String.Empty);

            mif.FromString(ConfigContent);
            string section = "FetchServices";

            if (mif.SectionExists(section) &&
                mif.KeyExists(section, servname) &&
                mif.ReadBool(section, servname, false) &&
                mif.SectionExists(servname))
            {
                string[] keys = mif.ReadSectionKeys(servname);
                foreach (string key in keys)
                {
                    int channel;
                    if (key.StartsWith("Channel") &&
                        int.TryParse(key.Substring(7), out channel))
                    {
                        string desc = "Канал " + channel + " сервера опроса";
                        Data.SendToSystemLog(Station, "Опрос KR500", desc + " загружен");
                        string           ClientID = Data.ClientLogin(String.Empty, "F", Station, desc + " KR500");
                        BackgroundWorker worker   = new BackgroundWorker();
                        workers.Add(new Tuple <string, BackgroundWorker>(
                                        ClientID, worker));
                        worker.DoWork                    += worker_DoWork;
                        worker.ProgressChanged           += worker_ProgressChanged;
                        worker.WorkerSupportsCancellation = true;
                        //worker.WorkerReportsProgress = true;
                        worker.RunWorkerAsync(new Tuple <string, string, string, int, string>(
                                                  ClientID, ApplicationStartupPath, ConfigContent, channel, key));
                    }
                }
            }
        }
Ejemplo n.º 6
0
        private static void worker_DoWork(object sender, DoWorkEventArgs e)
        {
            Tuple <int, string, string, exitApp, string, int> args =
                (Tuple <int, string, string, exitApp, string, int>)e.Argument;
            int        channel = args.Item1;
            string     info    = args.Item2;
            MemIniFile mif     = new MemIniFile(String.Empty);

            mif.FromString(args.Item3);
            exitApp DoExitApp = args.Item4;
            string  ClientID  = args.Item5;
            int     timeout   = args.Item6;

            string section = "Application";
            int    station = mif.ReadInteger(section, "Station", 1);
            string ApplicationStartupPath = mif.ReadString(section, "StartupPath", ".");
            bool   Registered             = mif.ReadBool(section, "Registered", false);
            bool   Bonus = mif.ReadBool(section, "Bonus", false);

            Data.RestoreSQLsettingsFromString(args.Item3);
            BackgroundWorker worker     = (BackgroundWorker)sender;
            DateTime         TurnOnTime = DateTime.Now;
            IDictionary <string, IPointPlugin> plugins =
                PointPlugin.LoadPlugin(ApplicationStartupPath + "\\Points.Modbus.dll");

            // Инициализация, создание баз, если их раньше не было
            Settings.CreateDataAndFetchBases();
            string desc = "Канал " + channel + " сервера опроса";

            // Заполнение списка для опроса
            LoadFirst(worker, ClientID, channel, plugins);

            bool _exit     = false;
            bool _continue = true;

            while (_continue)
            {
                if (!Data.ImLive(ClientID, "F", Station, desc + " Modbus"))
                {
                    ClientID = Data.ClientLogin(ClientID, "F", station, desc + " Modbus");
                }
                string[] command = Data.GetClientCommand(ClientID);
                //if (command[0].Equals("RELOAD"))
                //{
                //}
                if (!Registered)
                {
                    if (DateTime.Now.AddHours(-2.5) > TurnOnTime)
                    {
                        Bonus = false;
                    }
                }
                if (Registered || Bonus)
                {
                    try
                    {
                        FetchBase(worker, ClientID, channel, info, timeout, plugins);
                        Thread.Sleep(50);
                    }
                    catch (Exception ex)
                    {
                        Data.SendToSystemLog(0, "Опрос Modbus", ex.Message);
                    }
                }
                else
                if (!_exit)
                {
                    _exit = true;
                    Data.SendToSystemLog(Station,
                                         "Опрос Modbus", "Прекращена работа неавторизованного сервера опроса");
                    DoExitApp();
                }
            }
        }
Ejemplo n.º 7
0
        private static void worker_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker        worker = (BackgroundWorker)sender;
            Tuple <string, exitApp> args   = (Tuple <string, exitApp>)e.Argument;

            MemIniFile mif = new MemIniFile(String.Empty);

            mif.FromString(args.Item1);
            string  section = "Application";
            int     station = mif.ReadInteger(section, "Station", 1);
            string  ApplicationStartupPath = mif.ReadString(section, "StartupPath", ".");
            bool    Registered             = mif.ReadBool(section, "Registered", false);
            bool    Bonus     = mif.ReadBool(section, "Bonus", false);
            exitApp DoExitApp = args.Item2;

            Data.RestoreSQLsettingsFromString(args.Item1);
            DateTime TurnOnTime = DateTime.Now;
            // Загрузка плагина виртуальных точек
            IDictionary <string, IPointPlugin> plugins =
                PointPlugin.LoadPlugin(ApplicationStartupPath + "\\Points.Virtuals.dll");

            // Инициализация, создание баз, если их раньше не было
            Settings.CreateDataAndFetchBases();
            // Загрузка виртуальных точек из базы данных
            Data.LoadBase(plugins);
            string desc = "Сервер опроса виртуальных значений";

            Data.SendToSystemLog(station, "Опрос виртуальных", "Сервер опроса загружен");
            ClientID = Data.ClientLogin(ClientID, "F", Station, desc);
            // Заполнение списка для опроса
            LoadFirst(worker);
            bool _exit     = false;
            bool _continue = true;

            while (_continue)
            {
                _continue = !worker.CancellationPending;
                if (!Data.ImLive(ClientID, "F", Station, desc))
                {
                    ClientID = Data.ClientLogin(ClientID, "F", Station, desc);
                }
                string[] command = Data.GetClientCommand(ClientID);
                //if (command[0].Equals("RELOAD"))
                //{
                //}
                if (!Registered)
                {
                    if (DateTime.Now.AddHours(-2.5) > TurnOnTime)
                    {
                        Bonus = false;
                    }
                }
                if (Registered || Bonus)
                {
                    try
                    {
                        FetchBase(worker, plugins);
                        Thread.Sleep(50);
                    }
                    catch (Exception ex)
                    {
                        Data.SendToSystemLog(0, "Опрос виртуальных", ex.Message);
                    }
                }
                else
                if (!_exit)
                {
                    _exit = true;
                    Data.SendToSystemLog(station,
                                         "Опрос виртуальных", "Прекращена работа неавторизованного сервера опроса");
                    DoExitApp();
                }
            }
        }