public bool UploadCellInfo(Clamp clamp, out string msg) { msg = string.Empty; try { //WEB服务地址(非正式地址) //string url = "http://192.168.72.1:8092/mesframework.asmx"; string url = this.WebServiceUrl; //客户端代理服务命名空间,可以设置成需要的值。 string ns = string.Format("ProxyServiceReference"); //获取WSDL WebClient wc = new WebClient(); Stream stream = wc.OpenRead(url + "?WSDL"); ServiceDescription sd = ServiceDescription.Read(stream);//服务的描述信息都可以通过ServiceDescription获取 string classname = sd.Services[0].Name; ServiceDescriptionImporter sdi = new ServiceDescriptionImporter(); sdi.AddServiceDescription(sd, "", ""); CodeNamespace cn = new CodeNamespace(ns); //生成客户端代理类代码 CodeCompileUnit ccu = new CodeCompileUnit(); ccu.Namespaces.Add(cn); sdi.Import(cn, ccu); CSharpCodeProvider csc = new CSharpCodeProvider(); //设定编译参数 CompilerParameters cplist = new CompilerParameters(); cplist.GenerateExecutable = false; cplist.GenerateInMemory = true; cplist.ReferencedAssemblies.Add("System.dll"); cplist.ReferencedAssemblies.Add("System.XML.dll"); cplist.ReferencedAssemblies.Add("System.Web.Services.dll"); cplist.ReferencedAssemblies.Add("System.Data.dll"); //编译代理类 CompilerResults cr = csc.CompileAssemblyFromDom(cplist, ccu); if (cr.Errors.HasErrors == true) { System.Text.StringBuilder sb = new System.Text.StringBuilder(); foreach (System.CodeDom.Compiler.CompilerError ce in cr.Errors) { sb.Append(ce.ToString()); sb.Append(System.Environment.NewLine); } throw new Exception(sb.ToString()); } //生成代理实例 Assembly assembly = cr.CompiledAssembly; Type t = assembly.GetType(ns + "." + classname, true, true); object obj = Activator.CreateInstance(t); //实例化方法 MethodInfo methodInfo = t.GetMethod("AutoLineDataUpload"); Station station = Station.StationList.FirstOrDefault(s => s.Id == clamp.OvenStationId); Floor floor = Floor.FloorList.FirstOrDefault(f => f.Stations.Contains(station)); var batteries = clamp.Batteries; foreach (Battery battery in batteries) { //设置参数 object device = floor.Number; object workstation_sn = floor.Model; object emp_no = this.EmployeeNo; object mo_number = this.ManufactureOrder; object product_sn = "$$$" + battery.Code; // object contaion_sn = clamp.Code; object contaion_sn = string.Empty; object union_list = string.Empty; object error_code = string.Empty; object error_value = string.Empty; object error_qty = "0"; object ec_flg = "OK"; object sn_qty = "1"; object test_item_list = string.Format("烘烤温度:{0}:℃|烘烤真空度:{1}:Pa|烘烤时间:{2}:min|烘烤开始时间:{3}:|烘烤结束时间:{4}:|出烤箱温度:{5}:℃|极片水分:{6}:ppm|夹具扭力:{7}:N|夹具条码:{8}:", clamp.Temperature.ToString("#0.0"), clamp.Vacuum.ToString("#0"), (clamp.BakingStopTime - clamp.BakingStartTime).TotalMinutes.ToString("#0"), clamp.BakingStartTime.ToString("yyyy-MM-dd HH-mm-ss"), clamp.BakingStopTime.ToString("yyyy-MM-dd HH-mm-ss"), clamp.OutOvenTemp.ToString("#0.0"), clamp.WaterContent.ToString("#0.0"), clamp.ClampTorsion.ToString("#0.0"), clamp.Code ); object test_time = DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss"); object[] addParams = new object[] { device, workstation_sn, emp_no, mo_number, product_sn, contaion_sn, union_list, error_code, error_value, error_qty, ec_flg, sn_qty, test_item_list, test_time }; //参数赋值并调用方法 object methodInfoReturn = methodInfo.Invoke(obj, addParams); msg = methodInfoReturn.ToString(); if (msg != "OK") { return(false); } LogHelper.WriteInfo(string.Format("MES上传完成,{0}", battery.Code)); } clamp.IsUploaded = true; return(true); } catch (Exception ex) { msg = ex.Message; } return(false); }
public static void Run() { if (Current.TaskMode == TaskMode.自动任务) { //烤箱只有一个空位时,不要搬运空夹具至烤箱 List <ClampOri> ClampOris = new List <ClampOri> { ClampOri.A, ClampOri.B }; foreach (ClampOri clampOri in ClampOris) { List <Station> stations = Station.StationList.Where(s => s.ClampOri == clampOri && s.IsAlive && s.GetPutType == GetPutType.烤箱 && s.FloorStatus == FloorStatus.无盘).ToList(); Task.TaskList.Where(t => t.FromClampStatus == ClampStatus.空夹具 && t.ToType == GetPutType.烤箱 && t.ClampOri == clampOri).ToList(). ForEach(t => t.IsEnable = stations.Count > 1); } if (Current.Task.Status == TaskStatus.完成) { if (CurrentTask.ToSwitchManuTaskMode) { Current.Task.StartTime = TengDa.Common.DefaultTime; Current.Task.TaskId = -1; Current.Task.FromStationId = -1; Current.Task.ToStationId = -1; Current.Task.FromClampStatus = ClampStatus.未知; Current.TaskMode = TaskMode.手动任务; CurrentTask.ToSwitchManuTaskMode = false; return; } ///任务遍历 foreach (Task task in Task.CanGetPutTaskList.Where(t => t.IsEnable)) { List <Station> fromStations = Station.CanGetPutStationList .Where(s => s.ClampOri == task.ClampOri && s.GetPutType == task.FromType && s.ClampStatus == task.FromClampStatus && s.Status == StationStatus.可取 && task.IsSuitSampleStatus(s)) .OrderBy(s => s.Distance(Current.rgv)) .OrderBy(s => s.Priority) .OrderBy(s => s.GetPutTime) .ToList(); List <Station> toStations = Station.CanGetPutStationList .Where(s => s.ClampOri == task.ClampOri && s.GetPutType == task.ToType && s.ClampStatus == task.ToClampStatus && s.Status == StationStatus.可放 && task.IsSuitSampleStatus(s)) .OrderBy(s => s.Priority) //.OrderBy(s => s.Distance(Current.rgv)) .OrderBy(s => s.GetPutTime) .ToList(); if (fromStations.Count > 0 && toStations.Count > 0) { if (task.FromClampStatus == ClampStatus.满夹具 && task.FromType == GetPutType.烤箱) { fromStations = fromStations.OrderBy(s => s.GetFillClampPriority).ToList(); } if (task.FromClampStatus == ClampStatus.空夹具 && task.FromType == GetPutType.烤箱) { fromStations = fromStations.OrderBy(s => s.GetEmptyClampPriority).ToList(); } if (task.FromClampStatus == ClampStatus.满夹具 && task.ToType == GetPutType.烤箱) { toStations = toStations.OrderBy(s => s.PutFillClampPriority).ToList(); } if (task.FromClampStatus == ClampStatus.空夹具 && task.ToType == GetPutType.烤箱) { toStations = toStations.Where(s => s.CanPutEmptyClamp).OrderBy(s => s.PutEmptyClampPriority).ToList(); } Station fromStation = fromStations.First(); Station toStation = toStations.First(); Current.Task.StartTime = DateTime.Now; Current.Task.TaskId = task.Id; Current.Task.FromStationId = fromStation.Id; Current.Task.ToStationId = toStation.Id; Current.Task.FromClampStatus = fromStation.ClampStatus; Current.Task.PreCycleOrder = task.CycleOrder; Current.Task.Status = TaskStatus.就绪; break; } else { Current.Task.StartTime = TengDa.Common.DefaultTime; Current.Task.TaskId = -1; Current.Task.FromStationId = -1; Current.Task.ToStationId = -1; Current.Task.FromClampStatus = ClampStatus.未知; Current.Task.Status = TaskStatus.完成; } } } else if (Current.Task.FromStationId > 0 && Current.Task.ToStationId > 0 && Current.Task.FromStation != null && Current.Task.ToStation != null) { if (Current.Task.Status == TaskStatus.就绪) { int d3410 = int.Parse(Current.Task.FromStation.RgvValues.Split(',')[0]); int d3411 = int.Parse(Current.Task.FromStation.RgvValues.Split(',')[1]); if (Current.rgv.IsReadyGet) { if (Current.rgv.Move(d3410, d3411, isGet: true)) { Current.Task.Status = TaskStatus.可取; } } } else if (Current.Task.Status == TaskStatus.可取 && Current.Task.FromStation != null) { if (Current.Task.FromStation.DoorStatus != DoorStatus.打开) { Current.Task.FromStation.OpenDoor(); } if (Current.Task.ToStation.DoorStatus != DoorStatus.打开 && Current.Task.ToStation != null && Current.Task.ToStation.GetPutType == GetPutType.烤箱 && Current.rgv.IsGettingOrPutting) { Current.Task.ToStation.OpenDoor(); } if (Current.Task.FromStation.DoorStatus == DoorStatus.打开 && Current.Task.FromStation.ClampStatus != ClampStatus.无夹具) { Current.rgv.StartGetPut(); } if (Current.Task.FromStation.ClampStatus == ClampStatus.无夹具) { Current.rgv.ClampStatus = Current.Task.FromClampStatus; Current.rgv.Location = Current.Task.FromStation.Location; if (Current.Task.FromStation.ClampId > 0) { Current.rgv.ClampId = Current.Task.FromStation.ClampId; Current.Task.FromStation.ClampId = -1; } if (!Current.rgv.IsGettingOrPutting) { Current.Task.Status = TaskStatus.取完; } } } else if (Current.Task.Status == TaskStatus.取完 && Current.Task.ToStation != null) { int d3410 = int.Parse(Current.Task.ToStation.RgvValues.Split(',')[0]); int d3411 = int.Parse(Current.Task.ToStation.RgvValues.Split(',')[1]); if (Current.rgv.IsReadyPut) { if (Current.rgv.Move(d3410, d3411, isGet: false)) { Current.Task.Status = TaskStatus.可放; } } } else if (Current.Task.Status == TaskStatus.可放 && Current.Task.ToStation != null) { if (Current.Task.ToStation.DoorStatus != DoorStatus.打开) { Current.Task.ToStation.OpenDoor(); } if (Current.Task.ToStation.DoorStatus == DoorStatus.打开 && !Current.rgv.IsGettingOrPutting && Current.Task.ToStation.ClampStatus == ClampStatus.无夹具) { Current.rgv.StartGetPut(); } if (Current.Task.ToStation.ClampStatus != ClampStatus.无夹具) { Current.Task.ToStation.ClampStatus = Current.Task.FromClampStatus; Current.Task.ToStation.FromStationId = Current.Task.FromStationId; if (Current.Task.ToStation.ClampId < 1 && Current.Task.ToStation.GetPutType == GetPutType.料机 && Current.Task.FromClampStatus == ClampStatus.空夹具) { string msg = string.Empty; int clampId = Clamp.Add(new Clamp(Current.rgv.ClampId).Code, out msg); if (clampId > 0) { Current.Task.ToStation.ClampId = clampId; } else { LogHelper.WriteError(msg); } } else if (Current.rgv.ClampId > 0) { Current.Task.ToStation.ClampId = Current.rgv.ClampId; } Current.rgv.ClampId = -1; Current.rgv.ClampStatus = ClampStatus.无夹具; Current.rgv.Location = Current.Task.ToStation.Location; } if (Current.rgv.CanCheckGetPutClampIsOk) { Current.rgv.ClampStatus = ClampStatus.无夹具; if (Current.Task.ToStation.ClampStatus == ClampStatus.无夹具) { //放盘无效报警 Current.rgv.PutClampIsNotOkAlarm(); } } if (!Current.rgv.IsGettingOrPutting && Current.Task.ToStation.ClampStatus != ClampStatus.无夹具) { string msg = string.Empty; if (TaskLog.Add(out msg))//记录 { Current.Task.Status = TaskStatus.完成; } else { Error.Alert("保存搬运记录失败:" + msg); } } } } } else if (Current.TaskMode == TaskMode.手动任务) { if (Current.Task.Status == TaskStatus.完成) { Current.Task.StartTime = TengDa.Common.DefaultTime; Current.Task.TaskId = -1; Current.Task.FromStationId = -1; Current.Task.ToStationId = -1; Current.Task.FromClampStatus = ClampStatus.未知; Current.Task.Status = TaskStatus.完成; if (Current.Task.NextFromStationId > 0) { Current.Task.FromStationId = Current.Task.NextFromStationId; Current.Task.NextFromStationId = -1; Current.Task.FromClampStatus = Current.Task.FromStation.ClampStatus; Current.Task.Status = TaskStatus.就绪; } } else if (Current.Task.Status == TaskStatus.就绪 && Current.Task.FromStation != null) { if (Current.Task.FromStation.DoorStatus != DoorStatus.打开) { Tip.Alert(Current.Task.FromStation.Name + "门未打开!"); } if (Current.Task.FromStation.DoorStatus == DoorStatus.打开) { int d3410 = int.Parse(Current.Task.FromStation.RgvValues.Split(',')[0]); int d3411 = int.Parse(Current.Task.FromStation.RgvValues.Split(',')[1]); if (Current.rgv.IsReadyGet) { if (Current.rgv.Move(d3410, d3411, isGet: true)) { if (Current.Task.FromStation.DoorStatus == DoorStatus.打开) { Current.Task.Status = TaskStatus.可取; } } } } } else if (Current.Task.Status == TaskStatus.可取 && Current.Task.FromStation != null) { if (Current.Task.FromStation.DoorStatus == DoorStatus.打开 && Current.Task.FromStation.ClampStatus != ClampStatus.无夹具) { Current.rgv.StartGetPut(); } if (Current.Task.FromStation.ClampStatus == ClampStatus.无夹具) { Current.rgv.ClampStatus = Current.Task.FromClampStatus; Current.rgv.Location = Current.Task.FromStation.Location; if (Current.Task.FromStation.ClampId > 0) { Current.rgv.ClampId = Current.Task.FromStation.ClampId; Current.Task.FromStation.ClampId = -1; } if (!Current.rgv.IsGettingOrPutting) { Current.Task.Status = TaskStatus.取完; } } } else if (Current.Task.Status == TaskStatus.取完) { if (Current.Task.NextToStationId > 0) { Current.Task.ToStationId = Current.Task.NextToStationId; Current.Task.NextToStationId = -1; } if (Current.Task.ToStation != null) { if (Current.Task.ToStation.DoorStatus != DoorStatus.打开) { Tip.Alert(Current.Task.ToStation.Name + "门未打开!"); } if (Current.Task.ToStation.DoorStatus == DoorStatus.打开) { int d3410 = int.Parse(Current.Task.ToStation.RgvValues.Split(',')[0]); int d3411 = int.Parse(Current.Task.ToStation.RgvValues.Split(',')[1]); if (Current.rgv.IsReadyPut) { if (Current.rgv.Move(d3410, d3411, isGet: false)) { if (Current.Task.ToStation.DoorStatus == DoorStatus.打开) { Current.Task.Status = TaskStatus.可放; } } } } } } else if (Current.Task.Status == TaskStatus.可放 && Current.Task.ToStation != null) { if (Current.Task.ToStation.DoorStatus == DoorStatus.打开 && !Current.rgv.IsGettingOrPutting && Current.Task.ToStation.ClampStatus == ClampStatus.无夹具) { Current.rgv.StartGetPut(); } if (Current.Task.ToStation.ClampStatus != ClampStatus.无夹具) { Current.Task.ToStation.ClampStatus = Current.Task.FromClampStatus; Current.Task.ToStation.FromStationId = Current.Task.FromStationId; if (Current.Task.ToStation.ClampId < 1 && Current.Task.ToStation.GetPutType == GetPutType.料机 && Current.Task.FromClampStatus == ClampStatus.空夹具) { string msg = string.Empty; int clampId = Clamp.Add(new Clamp(Current.rgv.ClampId).Code, out msg); if (clampId > 0) { Current.Task.ToStation.ClampId = clampId; } else { LogHelper.WriteError(msg); } } else if (Current.rgv.ClampId > 0) { Current.Task.ToStation.ClampId = Current.rgv.ClampId; } Current.rgv.ClampId = -1; Current.rgv.ClampStatus = ClampStatus.无夹具; Current.rgv.Location = Current.Task.ToStation.Location; } if (Current.rgv.CanCheckGetPutClampIsOk) { Current.rgv.ClampStatus = ClampStatus.无夹具; if (Current.Task.ToStation.ClampStatus == ClampStatus.无夹具) { //放盘无效报警 Current.rgv.PutClampIsNotOkAlarm(); } } if (!Current.rgv.IsGettingOrPutting && Current.Task.ToStation.ClampStatus != ClampStatus.无夹具) { string msg = string.Empty; if (TaskLog.Add(out msg))//记录 { Current.Task.Status = TaskStatus.完成; } else { Error.Alert("保存搬运记录失败:" + msg); } } } } }
public static bool Delete(Clamp delClamp, out string msg) { return(Database.NonQuery(string.Format("DELETE FROM [dbo].[{0}] WHERE [Code] = '{1}'", TableName, delClamp.Code), out msg)); }
public static bool Update(Clamp newClamp, out string msg) { msg = ""; return(true); //return Database.NonQuery(string.Format("UPDATE [dbo].[{0}] SET [EnterTime] = '{1}', [OutTime] = '{2}', [BakingStartTime] = '{3}', [BakingStopTime] = '{4}', [Vacuum] = {5}, [Temperature] = {6}, [IsUploaded] = '{7}', [IsFinished] = '{8}' WHERE [Id] = {9}", TableName, newClamp.EnterTime, newClamp.OutTime, newClamp.BakingStartTime, newClamp.BakingStopTime, newClamp.Vacuum, newClamp.Temperature, newClamp.IsUploaded, newClamp.IsFinished, newClamp.Id), out msg); }
public static int Add(Clamp addClamp, out string msg) { return(Database.Insert(string.Format("INSERT INTO [dbo].[{0}] ([Code], [UserId], [OvenStationId], [Location], [BakingStartTime], [BakingStopTime], [Vacuum], [Temperature], [IsFinished], [QualityStatusId], [ScanTime], [OutOvenTemp], [WaterContent], [ClampTorsion], [IsUploaded]) VALUES ('{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}', '{8}', '{9}', '{10}', '{11}', '{12}', '{13}', '{14}', 'false')", TableName, addClamp.Code, TengDa.WF.Current.user.Id, addClamp.OvenStationId, addClamp.Location, addClamp.BakingStartTime, addClamp.BakingStopTime, addClamp.Vacuum, addClamp.Temperature, addClamp.IsFinished, 1, DateTime.Now, addClamp.OutOvenTemp, addClamp.WaterContent, addClamp.ClampTorsion), out msg)); }