Ejemplo n.º 1
0
        private static void TakePhotoTp5(SWSDataContext db, GuangDaiService.CorePlatformWebServiceClient ws, int stationId, string wscid)
        {
            //  List<control_command> commands = db.control_command.Where(c => c.station_id == stationId && c.tp.Trim() == "5" && c.state == 0).ToList();
            List <control_command> commands = db.ExecuteQuery <control_command>("SELECT * FROM dbo.control_command WHERE station_id=" + stationId + " AND state=0 AND tp='5'").ToList();

            foreach (control_command command in commands)
            {
                if (command.COUNT == null)
                {
                    command.COUNT = 0;
                }
                try
                {
                    gong_kuang_config gongkuang = db.gong_kuang_config.SingleOrDefault(c => c.id == command.gong_kuang_id);
                    if (gongkuang == null)  //如果找不到command对应和gongkuangid,则把这条command标记为执行失败。
                    {
                        LogMg.AddError("找不到控制命令所对应的工况配置信息");
                        command.execute_result    = 0; //标记为执行失败
                        command.state             = 1; // 就当已经执行过
                        command.execute_comment   = "执行失败,找不到控制命令所对应的工况配置信息";
                        command.complete_datetime = DateTime.Now;
                        db.SubmitChanges();
                        continue;
                    }
                    byte address = (byte)gongkuang.address;

                    GuangDaiService.config config = ws.doConfig(wscid, Convert.ToInt32(gongkuang.write_register), (int)command.read_or_write, Convert.ToInt32(command.value), "");
                    LogMg.AddDebug(String.Format(" ws.doConfig({0},{1}, {2}, {3}, {4})   返回结果是   result={5}   value={6}   message={7}  ", wscid, gongkuang.write_register, command.read_or_write, "-1", "", config.result, config.value, config.message));
                    command.state = 1;  //标志为已发送
                    if (config.result == true)
                    {
                        command.execute_result    = 1; //标记为执行成功
                        command.execute_comment   = "执行写操作成功";
                        gongkuang.write_value     = command.value;
                        gongkuang.execute_comment = "执行写操作成功";
                    }
                    else
                    {
                        command.execute_result    = 0; //标记为执行失败
                        command.execute_comment   = "执行广岱拍照操作失败";
                        gongkuang.execute_comment = "执行广岱拍照操作失败";
                    }

                    gongkuang.execute_datetime = DateTime.Now;
                    command.complete_datetime  = DateTime.Now;
                }
                catch (Exception ex)
                {
                    command.execute_result  = 0; //标记为执行失败
                    command.execute_comment = "执行广岱拍照操作失败,服务程序出现了异常";
                    // MessageQueue.Enqueue_DataInfo(string.Format("接收时间:【{0}】,站点:{1},   执行工况配置失败.程序出现异常,请查看日志.  ", DateTime.Now, station.name));
                    LogMg.AddError(ex);
                }
                finally
                {
                    command.complete_datetime = DateTime.Now;
                }
                try
                {
                    db.SubmitChanges();
                }
                catch (Exception ex)
                {
                    LogMg.AddError(ex.ToString());
                }
            }
        }
Ejemplo n.º 2
0
        private static void ExecuteGuangDaiOrder(object state)
        {
            try
            {
                Args           arg = (Args)state;
                SWSDataContext db  = new SWSDataContext(ConnectStringHelper.GetConnection(SysConfig.userProfile.DbAddress, arg.dbName, SysConfig.userProfile.DbUserName, SysConfig.userProfile.DbPassword));

                GuangDaiService.CorePlatformWebServiceClient ws = new GuangDaiService.CorePlatformWebServiceClient(arg.gdServerCfg);
                SWS_DBDataContext            SWS_DB             = new SWS_DBDataContext(ConnectStringHelper.GetConnection(SysConfig.userProfile.DbAddress, SysConfig.userProfile.DbName, SysConfig.userProfile.DbUserName, SysConfig.userProfile.DbPassword));
                List <guangdai_station_link> links = SWS_DB.guangdai_station_link.ToList();
                String wscid = getWscId(arg, db, links);
                if (String.IsNullOrEmpty(wscid))
                {
                    LogMg.AddDebug("站点id=" + arg.station_id + "  找不到对应的wscId");
                    return;
                }
                //把那些不需要执行了的数据 state设置为1,  就当这行指令已经执行过了
                List <int> giveUpCommands = db.ExecuteQuery <int>("SELECT id FROM dbo.control_command  WHERE station_id=" + arg.station_id + " AND (state=0 OR state IS NULL) AND id NOT IN (SELECT MAX(id) FROM dbo.control_command   WHERE  station_id=" + arg.station_id + " AND   (state=0 OR state IS NULL)  GROUP BY gong_kuang_id,read_or_write) ").ToList();
                if (giveUpCommands.Count > 0)
                {
                    db.ExecuteCommand("UPDATE dbo.control_command SET state=1 WHERE id in(" + string.Join(", ", giveUpCommands) + ")");
                }
                //db.ExecuteCommand("UPDATE dbo.control_command SET state=1 WHERE station_id=" + arg.station_id + " AND (state=0 OR state IS NULL) AND id NOT IN (SELECT MAX(id) FROM dbo.control_command   WHERE  station_id=" + arg.station_id + " AND   (state=0 OR state IS NULL)  GROUP BY gong_kuang_id,read_or_write) ");
                //获取需要执行的指令
                List <control_command> commands = db.ExecuteQuery <control_command>("SELECT * FROM dbo.control_command WHERE id IN(SELECT MAX(id) as id  FROM dbo.control_command   WHERE  station_id=" + arg.station_id + " AND communication_mode=4  AND  tp is NULL AND   (state=0 OR state IS NULL)  GROUP BY gong_kuang_id,read_or_write) ORDER BY add_datetime").ToList();

                TakePhotoTp5(db, ws, arg.station_id, wscid);
                for (int i = 0; i < commands.Count; i++)
                {
                    control_command command = commands[i];
                    if (command.COUNT == null)
                    {
                        command.COUNT = 0;
                    }
                    try
                    {
                        gong_kuang_config gongkuang = db.gong_kuang_config.SingleOrDefault(c => c.id == command.gong_kuang_id);
                        if (gongkuang == null)  //如果找不到command对应和gongkuangid,则把这条command标记为执行失败。
                        {
                            LogMg.AddError("找不到控制命令所对应的工况配置信息");
                            command.execute_result    = 0; //标记为执行失败
                            command.state             = 1; // 就当已经执行过
                            command.execute_comment   = "执行失败,找不到控制命令所对应的工况配置信息";
                            command.complete_datetime = DateTime.Now;
                            db.SubmitChanges();
                            continue;
                        }
                        if (command.read_or_write == 0)   //读读读读读读读读读读读
                        {
                            GuangDaiService.config config = ws.doConfig(wscid, Convert.ToInt32(gongkuang.read_register), (int)command.read_or_write, -1, "");
                            command.state = 1;  //标志为已发送
                            if (config.result == true)
                            {
                                command.execute_result    = 1; //标记为执行成功
                                command.value             = Convert.ToString(config.value);
                                command.execute_comment   = "执行读取操作成功";
                                gongkuang.read_value      = Convert.ToString(config.value);
                                gongkuang.execute_comment = "执行读取操作成功";
                                if (gongkuang.config_type == "05")
                                {
                                    try
                                    {
                                        test   test      = db.test.Single(c => c.testid == gongkuang.testid);
                                        double multiple  = gongkuang.Multiple == null ? 1 : (double)gongkuang.Multiple;
                                        double addNumber = gongkuang.AddNumber == null ? 0 : (double)gongkuang.AddNumber;
                                        test.value = Convert.ToString(config.value * multiple + addNumber);
                                        //test.value = Convert.ToString(config.value * gongkuang.Multiple + gongkuang.AddNumber);
                                    }
                                    catch (Exception ex)
                                    {
                                        LogMg.AddError(ex);
                                        LogMg.AddDebug("找不到工况对应的检测点,gongkuangid=" + gongkuang.id + "   testid=" + gongkuang.testid);
                                    }
                                }
                            }
                            else
                            {
                                command.execute_result    = 0; //标记为执行失败
                                command.execute_comment   = "执行读取操作失败";
                                gongkuang.execute_comment = "执行读取操作失败";
                            }
                        }
                        if (command.read_or_write == 1)      //写写写写写写写写写写写写写写写
                        {
                            GuangDaiService.config config = ws.doConfig(wscid, Convert.ToInt32(gongkuang.write_register), (int)command.read_or_write, Convert.ToInt32(command.value), "");
                            LogMg.AddDebug(String.Format(" ws.doConfig({0},{1}, {2}, {3}, {4})   返回结果是   result={5}   value={6}   message={7}  ", wscid, gongkuang.write_register, command.read_or_write, "-1", "", config.result, config.value, config.message));
                            command.state = 1;  //标志为已发送
                            if (config.result == true)
                            {
                                command.execute_result    = 1; //标记为执行成功
                                command.execute_comment   = "执行写操作成功";
                                gongkuang.write_value     = command.value;
                                gongkuang.execute_comment = "执行写操作成功";
                            }
                            else
                            {
                                command.execute_result    = 0; //标记为执行失败
                                command.execute_comment   = "执行写操作失败";
                                gongkuang.execute_comment = "执行写操作失败";
                            }
                        }
                        gongkuang.execute_datetime = DateTime.Now;
                        command.complete_datetime  = DateTime.Now;
                    }
                    catch (Exception ex)
                    {
                        command.execute_result  = 0; //标记为执行失败
                        command.execute_comment = "执行命令失败,服务程序出现了异常";
                        // MessageQueue.Enqueue_DataInfo(string.Format("接收时间:【{0}】,站点:{1},   执行工况配置失败.程序出现异常,请查看日志.  ", DateTime.Now, station.name));
                        LogMg.AddError(ex);
                    }
                    finally
                    {
                        command.complete_datetime = DateTime.Now;
                    }
                    try
                    {
                        db.SubmitChanges();
                    }
                    catch (Exception ex)
                    {
                        LogMg.AddError(ex.ToString());
                    }
                }
            }
            catch (Exception ex) { LogMg.AddError(ex); }
        }