ControllerServiceSetting.prototype._SaveDeviceDri_ = function(Result)
{
	var Class = new JsonTransformXml();
	var ModbusDri = Class.TransformModbusDri();
	var MqttDri = Class.TransformMqttDri();
	var PidDriverDri = Class.TransformPidDriverDri();
	Class = new EipJsonTransformXml();
	var EipDir = Class.ICPDASEIPDri();
	var Result_1={"Input":null}, Result_2={"Input":null}, Result_3={"Input":null}, Result_4={"Input":null};
	Class = new Transmission();
	Class.TransmissionString("SaveModbusDri", ModbusDri, Result_1);
	Class.TransmissionString("SaveMqttDri", MqttDri, Result_2);
	Class.TransmissionString("SavePidDriverDri", PidDriverDri, Result_3);
	Class.TransmissionString("SaveEipDri", EipDir, Result_4);
	var SetInterval = setInterval(function()
	{
		if(Result_1["Input"]==true && Result_2["Input"]==true && Result_3["Input"]==true && Result_4["Input"]==true)
		{
			clearInterval(SetInterval);
			Result["Input"] = true;
		}
	},500);
}

ControllerServiceSetting.prototype._SaveServiceXml_ = function(Result)
{
	var Class = new JsonTransformXml();
	var VariableXml = Class.TransformVariableXml();
	var UAServerDataXml = Class.TransformUAServerDataXml();
	var MqttServiceXml = Class.TransformMqttServiceXml();
	var MethodTableXml = Class.TransformMethodTableXml();
	var ScaleVariableTableXml = Class.TransformScaleVariableTableXml();
	var BitwiseVariableTableXml = Class.TransformBitwiseVariableTableXml();
	var UAServerConfigXml = Class.TransformUAServerConfigXml();
	Class = new ModuleToLocalDataLoggerCommon();
	var DataLogServiceXml = Class.GetDataLogServiceXml();
	var Result_1={"Input":null}, Result_2={"Input":null}, Result_3={"Input":null}, Result_4={"Input":null};
	var Result_5={"Input":null}, Result_6={"Input":null}, Result_7={"Input":null}, Result_8={"Input":null};
	Class = new Transmission();
	Class.TransmissionString("SaveVariableTableXml", VariableXml, Result_1);
	Class.TransmissionString("SaveUAServerDataXml", UAServerDataXml, Result_2);
	Class.TransmissionString("SaveMQTTServiceXml", MqttServiceXml, Result_3);
	Class.TransmissionString("SaveMethodTableXml", MethodTableXml, Result_4);
	Class.TransmissionString("SaveDataLogServiceXml", DataLogServiceXml, Result_5);
	Class.TransmissionString("SaveScaleVariableTableXml", ScaleVariableTableXml, Result_6);
	Class.TransmissionString("SaveBitwiseVariableTableXml", BitwiseVariableTableXml, Result_7);
	Class.TransmissionArray("SaveOpcUaLocalServer", UAServerConfigXml, Result_8);
	var SetInterval = setInterval(function()
	{
		if(Result_1["Input"]==true && Result_2["Input"]==true && Result_3["Input"]==true && Result_4["Input"]==true &&
		   Result_5["Input"]==true && Result_6["Input"]==true && Result_7["Input"]==true && Result_8["Input"]==true)
		{
			clearInterval(SetInterval);
			Result["Input"] = true;
		}
	},500);
}

ControllerServiceSetting.prototype._SaveXml_ = function(that)
{
	var Result_1={"Input":null}, Result_2={"Input":null};
	ControllerServiceSetting.prototype._SaveDeviceDri_(Result_1);
	ControllerServiceSetting.prototype._SaveServiceXml_(Result_2);
	var SetInterval = setInterval(function()
	{
		if(Result_1["Input"]==true && Result_2["Input"]==true)
		{
			clearInterval(SetInterval);
			ControllerServiceSetting.prototype._RunRuntime_(that);
		}
	},500);
}

ControllerServiceSetting.prototype._RunRuntime_ = function(that)
{
	$(that).closest('.Column').find(".Message").eq(1).show();
	var Result_1={"Input":null};  var Result_2={"Input":null};
	var Class = new Transmission();
	Class.TransmissionArray("StartMainSystem", new Array(), Result_1);
	var SetInterval_1 = setInterval(function(){
		if(Result_1["Input"] == true){
			clearInterval(SetInterval_1);
			Class.TransmissionArray("StartBackstageService", new Array(), Result_2);
		}
	},500);
	var SetInterval_2 = setInterval(function(){
		if(Result_2["Input"] == true)
		{
			clearInterval(SetInterval_2);
			ControllerServiceSetting.prototype._SwitchRadioStart_(that);
			$(that).closest(".Row").find(".Message").hide();
		}
	},500);
}

ControllerServiceSetting.prototype._SwitchRadioStop_ = function(that)
{
	var Row=$(that).closest(".Row");
	var Radio=Row.find(":radio");
	Radio.get(1).checked=true;
};

ControllerServiceSetting.prototype._SwitchRadioStart_ = function(that)
{
	var Row=$(that).closest(".Row");
	var Radio=Row.find(":radio");
	Radio.get(0).checked=true;
};
ControllerServiceSetting.prototype._IsUsedStatus_ = function()
{
	var Return=true;
	if($("#Top-Menu-SystemSetting").css("border-bottom-color") != "rgb(57, 93, 139)")
	{
		if($("#Left-List-ControllerServiceSetting").css("border-left-color") != "rgb(57, 93, 139)")
		{
			clearInterval(Global_TimeSetInterval);
			Return=false;
		}
	}
	return Return;
}

ControllerServiceSetting.prototype._GetMainSystemStatus_ = function()
{
	var Row=$("#Main_Center-Content").find(".Form").find(".Row").eq(0);
	var ssocket = io.connect();
	Global_TimeSetInterval = setInterval(function(){
	if(ControllerServiceSetting.prototype._IsUsedStatus_() == false)
	{
		ssocket.emit("SocketClose");
		return 0;
	}
	ssocket.emit('GetMainSystemStatus');
	ssocket.on('GetMainSystemStatus', function (Return) 
	{
		if(Return == true)
		{
			var Radio = Row.eq(0).find(":radio");
			Radio.eq(0).attr("checked", true);
			Radio.get(0).checked=true;
		}
		else if(Return == false)
		{
			var Radio = Row.eq(0).find(":radio");
			Radio.eq(1).attr("checked", true);
			Radio.get(1).checked=true;
		}
		//ssocket.emit("SocketClose");
	});
	}, 1000);
};

ControllerServiceSetting.prototype._StartMainSystem_ = function(that)
{
	$(that).closest(".Row").find(".Message").show();
	var ssocket = io.connect();
	ssocket.emit("SaveFinished");
	ssocket.on("SaveFinished", function (Return)
	{
		ControllerServiceSetting.prototype._SaveXml_(that);
		ssocket.emit("SocketClose");
	});
};

ControllerServiceSetting.prototype._StopMainSystem_ = function(that)
{
	var ssocket = io.connect();
	ssocket.emit('StopMainSystem');
	ssocket.on('StopMainSystem', function (Return) {
		if(Return == true)
		{
			ControllerServiceSetting.prototype._SwitchRadioStop_(that);
		}
		else if(Return == false)
		{
		}
		ssocket.emit("SocketClose");
	});
};

ControllerServiceSetting.prototype._SwitchMainSystem_ = function(that)
{
	var Row=$(that).closest(".Row");
	var Radio=Row.find(":radio");
	if(Radio.get(0).checked == true)
	{
		Radio.get(0).checked=false;
		ControllerServiceSetting.prototype._StartMainSystem_(that);
	}
	else if(Radio.get(1).checked == true)
	{
		Radio.get(1).checked=false;
		ControllerServiceSetting.prototype._StopMainSystem_(that);
	}
};
ControllerServiceSetting.prototype._SwitchWDT_ = function(that)
{
	var Form = $(".Form");
	var Row = Form.eq(0).find(".Row");
	var WDT = Row.eq(0).find(":checkbox").prop("checked");
	if(WDT==true)
	{
		ControllerServiceSetting.prototype._StartWDT_(WDT);
		//ControllerServiceSetting.prototype._GetMainSystemStatus_();
	}
	else
	{
		ControllerServiceSetting.prototype._StopWDT_(WDT);
	}
	/*
	var Row=$(that).closest(".Row");
	var Radio=Row.find(":radio");
	if(Radio.get(0).checked == true)
	{
		Radio.get(0).checked=false;
		ControllerServiceSetting.prototype._StartMainSystem_(that);
	}
	else if(Radio.get(1).checked == true)
	{
		Radio.get(1).checked=false;
		ControllerServiceSetting.prototype._StopMainSystem_(that);
	}
	*/
};
ControllerServiceSetting.prototype._StartWDT_ = function(WDT)
{
	var ssocket = io.connect();
	ssocket.emit('StartWDT');
	ssocket.on('StartWDT', function (Return) {
		ssocket.emit("SocketClose");
	});
}
ControllerServiceSetting.prototype._StopWDT_ = function(WDT)
{
	var ssocket = io.connect();
	ssocket.emit('StopWDT');
	ssocket.on('StopWDT', function (Return) {
		ssocket.emit("SocketClose");
	});
}
ControllerServiceSetting.prototype._GetMqttBrokerStatus_ = function()
{
	var Row=$("#Main_Center-Content").find(".Form").find(".Row").eq(1);
	var ssocket = io.connect();
	ssocket.emit('GetMqttBrokerStatus');
	ssocket.on('GetMqttBrokerStatus', function (Return) {
		if(Return == true)
		{
			Row.eq(0).find(":radio").eq(0).attr("checked", true);
		}
		else if(Return == false)
		{
			Row.eq(0).find(":radio").eq(1).attr("checked", true);
		}
		ssocket.emit("SocketClose");
	});
};

ControllerServiceSetting.prototype._StartMqttBroker_ = function(that)
{
	var ssocket = io.connect();
	ssocket.emit('StartMqttBroker');
	ssocket.on('StartMqttBroker', function (Return) {
		if(Return == true)
		{
			ControllerServiceSetting.prototype._SwitchRadioStart_(that);
		}
		else if(Return == false)
		{
		}
		ssocket.emit("SocketClose");
	});
};

ControllerServiceSetting.prototype._StopMqttBroker_ = function(that)
{
	var ssocket = io.connect();
	ssocket.emit('StopMqttBroker');
	ssocket.on('StopMqttBroker', function (Return) {
		if(Return == true)
		{
			ControllerServiceSetting.prototype._SwitchRadioStop_(that);
		}
		else if(Return == false)
		{
		}
		ssocket.emit("SocketClose");
	});
};

ControllerServiceSetting.prototype._SwitchMqttBroker_ = function(that)
{
	var Row=$(that).closest(".Row");
	var Radio=Row.find(":radio");
	if(Radio.get(0).checked == true)
	{
		Radio.get(0).checked=false;
		ControllerServiceSetting.prototype._StartMqttBroker_(that);
	}
	else if(Radio.get(1).checked == true)
	{
		Radio.get(1).checked=false;
		ControllerServiceSetting.prototype._StopMqttBroker_(that);
	}
};

ControllerServiceSetting.prototype._GetDdnsStatus_ = function()
{
	var Row=$("#Main_Center-Content").find(".Form").find(".Row").eq(2);
	var ssocket = io.connect();
	ssocket.emit('GetDdnsStatus');
	ssocket.on('GetDdnsStatus', function (Return) {
		if(Return == true)
		{
			Row.eq(0).find(":radio").eq(0).attr("checked", true);
		}
		else if(Return == false)
		{
			Row.eq(0).find(":radio").eq(1).attr("checked", true);
		}
		ssocket.emit("SocketClose");
	});
};

ControllerServiceSetting.prototype._StartDdns_ = function(that)
{
	var ssocket = io.connect();
	ssocket.emit('StartDdns');
	ssocket.on('StartDdns', function (Return) {
		if(Return == true)
		{
			ControllerServiceSetting.prototype._SwitchRadioStart_(that);
		}
		else if(Return == false)
		{
		}
		ssocket.emit("SocketClose");
	});
};

ControllerServiceSetting.prototype._StopDdns_ = function(that)
{
	var ssocket = io.connect();
	ssocket.emit('StopDdns');
	ssocket.on('StopDdns', function (Return) {
		if(Return == true)
		{
			ControllerServiceSetting.prototype._SwitchRadioStop_(that);
		}
		else if(Return == false)
		{
		}
		ssocket.emit("SocketClose");
	});
};

ControllerServiceSetting.prototype._SwitchDdns_ = function(that)
{
	var Row=$(that).closest(".Row");
	var Radio=Row.find(":radio");
	if(Radio.get(0).checked == true)
	{
		Radio.get(0).checked=false;
		ControllerServiceSetting.prototype._StartDdns_(that);
	}
	else if(Radio.get(1).checked == true)
	{
		Radio.get(1).checked=false;
		ControllerServiceSetting.prototype._StopDdns_(that);
	}
};
ControllerServiceSetting.prototype._GetMainSystemWDTStatus_ = function()
{
	var Row=$("#Main_Center-Content").find(".Form").find(".Row").eq(0);
	var Form = $(".Form");
	var Row = Form.eq(0).find(".Row");
	
	var ssocket = io.connect();
	ssocket.emit('GetMainSystemWDTStatus');
	ssocket.on('GetMainSystemWDTStatus', function (Return) 
	{
		if(Return == true)
		{
			Row.eq(0).find(":checkbox").prop("checked", Return);
			//var a=1+1;
			//Row.eq(0).find(":radio").eq(0).attr("checked", true);
		}
		else if(Return == false)
		{
			Row.eq(0).find(":checkbox").prop("checked", Return);
			//var a=1+2;
			//Row.eq(0).find(":radio").eq(1).attr("checked", true);
		}
		ssocket.emit("SocketClose");
	});
};

ControllerServiceSetting.prototype._ShowUi_ = function()
{
	ControllerServiceSetting.prototype._GetMainSystemStatus_();
	ControllerServiceSetting.prototype._GetMqttBrokerStatus_();
	ControllerServiceSetting.prototype._GetDdnsStatus_();
};
