using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Data.SqlClient; using System.Configuration; namespace AGV_WPF.Services { public class CasunWebService { public CasunWebService() { if (CasunService == null) { CasunService = new OrderWebservice.WebService(); header = new OrderWebservice.MyHeader(); header.UserName = "casun"; header.PassWord = "casunagv"; CasunService.MyHeaderValue = header; CasunService.GetOrderListCompleted += new OrderWebservice.GetOrderListCompletedEventHandler(CasunService_GetOrderListCompleted); try { WriteLog("Connect CasunService"); ClearAgv(); ClearOrder(); ClearRoute(); SetDatabase(); SetTrafficFlag(0, false); } catch (System.Exception ex) { Console.WriteLine("Message:{0}\r\nStackTrace:{1}", ex.Message, ex.StackTrace); } } } //public static OrderWebservice.COrder[] orderList = null; //static OrderWebservice.WebService CasunService; //static OrderWebservice.MyHeader header; public bool SetSystemStatus(bool status) { bool result = false; try { result = CasunService.SetSystemStatus(status); } catch (System.Exception ex) { Console.WriteLine("Message:{0}\r\nStackTrace:{1}",ex.Message,ex.StackTrace); } return result; } public void SetSystemStatusAsync(bool status) { try { CasunService.SetSystemStatusAsync(status); } catch (System.Exception ex) { Console.WriteLine("Message:{0}\r\nStackTrace:{1}", ex.Message, ex.StackTrace); } } public bool WriteAgvLog(ushort agvNum ,string directory) { bool result = false; try { Action action = new Action(delegate() { result = CasunService.WriteAgvLog(agvNum, directory); }); action.BeginInvoke(null, null); } catch (System.Exception ex) { Console.WriteLine("Message:{0}\r\nStackTrace:{1}", ex.Message, ex.StackTrace); } return result; } public bool UpdateAgv(OrderWebservice.CAgvData agv) { bool result = false; try { Action action = new Action(delegate() { result = CasunService.UpdateAgv(agv); }); action.BeginInvoke(null, null); } catch (System.Exception ex) { Console.WriteLine("Message:{0}\r\nStackTrace:{1}", ex.Message, ex.StackTrace); } return result; } public void UpdateAgvAsync(OrderWebservice.CAgvData agv) { try { CasunService.UpdateAgvAsync(agv); } catch (System.Exception ex) { Console.WriteLine("Message:{0}\r\nStackTrace:{1}", ex.Message, ex.StackTrace); } } public bool RemoveAgv(OrderWebservice.CAgvData agv) { bool result = false; try { result = CasunService.RemoveAgv(agv); } catch (System.Exception ex) { Console.WriteLine("Message:{0}\r\nStackTrace:{1}", ex.Message, ex.StackTrace); } return result; } public void RemoveAgvAsync(OrderWebservice.CAgvData agv) { try { CasunService.RemoveAgvAsync(agv); } catch (System.Exception ex) { Console.WriteLine("Message:{0}\r\nStackTrace:{1}", ex.Message, ex.StackTrace); } } public bool ClearAgv() { bool result = false; try { result = CasunService.ClearAgv(); } catch (System.Exception ex) { Console.WriteLine("Message:{0}\r\nStackTrace:{1}", ex.Message, ex.StackTrace); } return result; } public void ClearAgvAsync() { try { CasunService.ClearAgvAsync(); } catch (System.Exception ex) { Console.WriteLine("Message:{0}\r\nStackTrace:{1}", ex.Message, ex.StackTrace); } } public bool AddRoute(ushort route) { bool result = false; try { Action action = new Action(delegate() { result = CasunService.AddRoute(route); }); action.BeginInvoke(null, null); } catch (System.Exception ex) { Console.WriteLine("Message:{0}\r\nStackTrace:{1}", ex.Message, ex.StackTrace); } return result; } public void AddRouteAsync(ushort route) { try { CasunService.AddRouteAsync(route); } catch (System.Exception ex) { Console.WriteLine("Message:{0}\r\nStackTrace:{1}", ex.Message, ex.StackTrace); } } public bool ClearRoute() { bool result = false; try { result = CasunService.ClearRoute(); } catch (System.Exception ex) { Console.WriteLine("Message:{0}\r\nStackTrace:{1}", ex.Message, ex.StackTrace); } return result; } public void ClearRouteAsync() { try { CasunService.ClearRouteAsync(); } catch (System.Exception ex) { Console.WriteLine("Message:{0}\r\nStackTrace:{1}", ex.Message, ex.StackTrace); } } public OrderWebservice.COrder[] GetOrderList() { OrderWebservice.COrder[] orderList = null; try { orderList = CasunService.GetOrderList(); } catch (System.Exception ex) { Console.WriteLine("Message:{0}\r\nStackTrace:{1}", ex.Message, ex.StackTrace); } return orderList; } public void GetOrderListAsync() { try { CasunService.GetOrderListAsync(); } catch (System.Exception ex) { Console.WriteLine("Message:{0}\r\nStackTrace:{1}", ex.Message, ex.StackTrace); } } void CasunService_GetOrderListCompleted(object sender, OrderWebservice.GetOrderListCompletedEventArgs e) { try { orderList = e.Result; } catch (System.Exception ex) { Console.WriteLine("Message:{0}\r\nStackTrace:{1}", ex.Message, ex.StackTrace); orderList = null; } } public bool RemoveOrder(OrderWebservice.COrder order) { bool result = false; try { result = CasunService.RemoveOrder(order); } catch (System.Exception ex) { Console.WriteLine("Message:{0}\r\nStackTrace:{1}", ex.Message, ex.StackTrace); } return result; } public void RemoveOrderAsync(OrderWebservice.COrder order) { CasunService.RemoveOrderAsync(order); } public bool ClearOrder() { bool result = false; try { result = CasunService.ClearOrder(); } catch (System.Exception ex) { Console.WriteLine("Message:{0}\r\nStackTrace:{1}", ex.Message, ex.StackTrace); } return result; } public void ClearOrderAsync() { try { CasunService.ClearOrderAsync(); } catch (System.Exception ex) { Console.WriteLine("Message:{0}\r\nStackTrace:{1}", ex.Message, ex.StackTrace); } } public bool WriteLog(string msg) { bool result = false; try { result = CasunService.WriteLog(msg); } catch (System.Exception ex) { Console.WriteLine("Message:{0}\r\nStackTrace:{1}", ex.Message, ex.StackTrace); } return result; } public void WriteLogAsync(string msg) { try { CasunService.WriteLogAsync(msg); } catch (System.Exception ex) { Console.WriteLine("Message:{0}\r\nStackTrace:{1}", ex.Message, ex.StackTrace); } } public void SetDatabase() { try { string str = ""; using (SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["ConnString"])) { con.Open(); str = con.Database; con.Close(); CasunService.SetDatabase(str); } } catch (System.Exception ex) { Console.WriteLine("Message:{0}\r\nStackTrace:{1}", ex.Message, ex.StackTrace); } } public long GetTrafficFlag() { long result = 0; try { return CasunService.GetTrafficFlag(); } catch (System.Exception ex) { Console.WriteLine("Message:{0}\r\nStackTrace:{1}", ex.Message, ex.StackTrace); } return result; } public bool SetTrafficFlag(ushort agvNum, bool stopFlag) { bool result = false; try { return CasunService.SetTrafficFlag(agvNum, stopFlag); } catch (System.Exception ex) { Console.WriteLine("Message:{0}\r\nStackTrace:{1}", ex.Message, ex.StackTrace); } return result; } } }