static void Main(string[] args) { var logger = new NetLog(); logger.Error("This is an error, testing with time"); System.Console.ReadLine(); // for debugging }
void HandleData(NetIncomingMessage message) { ushort id = ushort.MaxValue; ByteBuffer byteBuffer = null; try { id = message.ReadUInt16(); ushort len = message.ReadUInt16(); byteBuffer = ByteBufferPool.Alloc(len); message.ReadBytes(byteBuffer.Data, 0, len); var result = dispatcher.Fire(message.SenderConnection, (MessageID)id, byteBuffer, message); if (result != MessageHandleResult.Processing) { ByteBufferPool.Dealloc(ref byteBuffer); } } catch (Exception e) { ByteBufferPool.Dealloc(ref byteBuffer); NetLog.Exception("HandleData throws exception", e); if (id != ushort.MaxValue) { NetLog.Error("Caught exception when processing message " + (MessageID)id); } else { NetLog.Error("Caught exception when processing message"); } } }
void HandleDebugMessage(NetIncomingMessage message) { switch (message.MessageType) { case NetIncomingMessageType.DebugMessage: { NetLog.Debug(message.ReadString()); break; } case NetIncomingMessageType.ErrorMessage: { NetLog.Error(message.ReadString()); break; } case NetIncomingMessageType.WarningMessage: { NetLog.Warn(message.ReadString()); break; } case NetIncomingMessageType.VerboseDebugMessage: { NetLog.Debug(message.ReadString()); break; } } }
public string GetMaterialInfo(string jsMaterialInfo) { NetLog.Write("GetRawMaterialInfo" + " " + jsMaterialInfo); List <FDIGetMaterialInfo> mains = new List <FDIGetMaterialInfo>(); try { mains = SafeConverter.JsonDeserializeObject <List <FDIGetMaterialInfo> >(jsMaterialInfo); foreach (var main in mains) { var check = GetFDIGetMaterialInfos($"ItemCode = '{main.ItemCode}'"); foreach (var c in check) { DelFDIGetMaterialInfo(c.PKNO); } main.PKNO = CBaseData.NewGuid(); AddFDIGetMaterialInfo(main); } } catch (Exception ex) { NetLog.Error("GetRawMaterialInfo error", ex); return("error: " + ex.Message); } return("OK"); }
public void BasicUnsupportedSymbolTest() { netlog_section.Logger.Layout.Value = "[#date] severity + #message"; var message = "An Error occurred"; var logger = new NetLog(netlog_section); var ouput = logger.Error(message); }
public void BasicMissingOpenBracketTest() { netlog_section.Logger.Layout.Value = "#date] #severity - #message"; var message = "An Error occurred"; var logger = new NetLog(netlog_section); var ouput = logger.Error(message); }
private void WriteLog(ExceptionContext context) { if (context == null) { return; } NetLog.Error("", context.Exception); }
public void ComplexFileLoggerTest() { netlog_section.Logger.Layout.Value = "[#date][[#severity - #message] - [#assembly]]"; var message = "An Error occurred"; var assembly = "NetLog.Test"; var severity = "ERROR"; var expected = "[" + DateTime.Now.ToString("MM/dd/yyyy") + "][[" + severity + " - " + message + "] - [" + assembly + "]]"; var logger = new NetLog(netlog_section); var output = logger.Error(message); Assert.AreEqual(expected, output); }
public string GetRawMaterial(string jsMaterialMain, string jsMaterialDetail) { NetLog.Write("GetRawMaterial" + " " + jsMaterialMain); NetLog.Write("GetRawMaterial" + " " + jsMaterialDetail); List <FDIGetRawMaterial> mains = new List <FDIGetRawMaterial>(); List <FDIGetRawMaterialDetail> detials = new List <FDIGetRawMaterialDetail>(); try { mains = SafeConverter.JsonDeserializeObject <List <FDIGetRawMaterial> >(jsMaterialMain); detials = SafeConverter.JsonDeserializeObject <List <FDIGetRawMaterialDetail> >(jsMaterialDetail); foreach (var main in mains) { var check = GetFDIGetRawMaterials($"DocEntry = '{main.DocEntry}'"); foreach (var c in check) { DelFDIGetRawMaterial(c.PKNO); } main.PKNO = CBaseData.NewGuid(); AddFDIGetRawMaterial(main); } foreach (var detail in detials) { var check = GetFDIGetRawMaterialDetails($"DocEntry = '{detail.DocEntry}' and LineId = '{detail.LineId}'"); foreach (var c in check) { DelFDIGetRawMaterialDetail(c.PKNO); } detail.PKNO = CBaseData.NewGuid(); AddFDIGetRawMaterialDetail(detail); } } catch (Exception ex) { NetLog.Error("GetRawMaterial error", ex); return("error: " + ex.Message); } return("OK"); }
private Page ShowCurrentPage(string assName, string fullName) { try { Assembly assembly = null; if (dicAssemblies.ContainsKey(assName)) { assembly = dicAssemblies[assName]; } else { assembly = Assembly.Load(assName); } Page obj = null; try { obj = assembly.GetType(fullName).InvokeMember("GetInstance", BindingFlags.Static | BindingFlags.Public | BindingFlags.InvokeMethod, null, null, null) as Page; } catch { obj = null; } if (obj == null) { obj = (Page)assembly.CreateInstance(fullName, true); // 创建类的实例,返回为 object 类型 } return(obj); } catch (Exception ex) { NetLog.Error("MainForm.ShowCurrentPage", ex); return(null); } }
/// <summary> /// 自动计算标签值 /// 采用动态代码执行方式,编译一次,采用参数传入的方式执行 /// </summary> private void ThreadAutoCalculation() { Type dynamicCode = null; //获取编译后代码,调用该类用 List <FmsTagCalculation> TagCalculations = null; //计算规则 Dictionary <string, Dictionary <string, string> > FuncAndParamTagPKNO = new Dictionary <string, Dictionary <string, string> >(); //函数和对应参数的Tag的PKNO while (!CBaseData.AppClosing) { #region 暂停 if (bPause) { System.Threading.Thread.Sleep(200); continue; } #endregion try { int index; if (bRefreshAutoCal) //刷新计算规则 { WcfClient <IFMSService> wsThis = new WcfClient <IFMSService>(); TagCalculations = wsThis.UseService(s => s.GetFmsTagCalculations("USE_FLAG = 1")); bRefreshAutoCal = false; if ((TagCalculations == null) || (!TagCalculations.Any())) { Thread.Sleep(500); continue; } string className = "C" + Guid.NewGuid().ToString("N"); #region 形成执行的代码 string execCode = "using System; \r\n" + "using System.Text; \r\n" + "using System.Collections.Generic; \r\n" + "using BFM.Common.Base; \r\n\r\n"; execCode += "public class " + className + "\r\n" + "{ \r\n"; string basicFuc = "AutoCalculation"; index = 1; FuncAndParamTagPKNO.Clear(); foreach (FmsTagCalculation calculation in TagCalculations) { FmsAssetTagSetting tagResult = GetTagSettingById(calculation.RESULT_TAG_PKNO); //结果 string exp = calculation.CALCULATION_EXPRESSION; //表达式 string funcname = basicFuc + index.ToString(); //函数名称 Dictionary <string, string> paramTas = new Dictionary <string, string>(); //参数对应的标签的PKNO, param List <string> funcParam = new List <string>(); //带类型的参数 string code = ""; string resultType = "string"; //将标签替换成参数名 foreach (var line in exp.Split(new string[] { "\r\n" }, StringSplitOptions.None)) { string ret = line; #region 替换标签值,将标签替换成参数名 string[] expTags = line.Split('{'); for (int i = 0; i < expTags.Length; i++) { string str = expTags[i]; int length = str.IndexOf('}'); if (length < 0) //没有找到 } { continue; } string tagPKNO = str.Substring(0, length); //{ } 内为PKNO string param = "{" + tagPKNO + "}"; if (paramTas.ContainsKey(tagPKNO)) //已经添加了该参数 { param = paramTas[tagPKNO]; } else { FmsAssetTagSetting tag = GetTagSettingById(tagPKNO); if (tag == null) { continue; } param = "param" + paramTas.Count; paramTas.Add(tagPKNO, param); string paramType = "string"; //所有参数传入都是string型 //string paramType = // ((calculation.CALCULATION_TYPE == 2) || // (tag.VALUE_TYPE > 0 && tag.VALUE_TYPE < 20)) // ? "double" // : "string"; funcParam.Add(paramType + " " + param); } ret = ret.Replace("{" + tagPKNO + "}", param); } #endregion if (string.IsNullOrEmpty(code)) { code = " " + ret; } else { code += Environment.NewLine + " " + ret; } } //确定返回结果类型,将code语句转换成C#的语句 if (calculation.CALCULATION_TYPE == 1) //逻辑运算 { //(结果为1,0):({标签1}==1)&&({标签2}==1)&&({标签3}==0||{标签4}==0)&&({标签5}==1) code = code.Replace("AND", "&&").Replace("and", "&&").Replace("OR", "||").Replace("or", "||"); resultType = "bool"; } else if (calculation.CALCULATION_TYPE == 2) //数值运算 { //{标签1}+3+{标签2}+4 resultType = "double"; } else if (calculation.CALCULATION_TYPE == 3) //字符运算 { //{标签1}+"123" } else if (calculation.CALCULATION_TYPE == 12) //条件数值运算 { //{标签1}==3:{标签2}+1;{标签1}==4:{标签2}+2;{标签1}==5:{标签2}+3 resultType = "double"; List <string> exps = code.Split(';').ToList(); string temp = ""; foreach (var exp1 in exps) { if (exp1.Split(':').Length < 2) { continue; } temp += " if (" + exp1.Split(':')[0] + ") { return (" + exp1.Split(':')[1] + "); } \r\n"; } temp += " return 0; \r\n"; code = temp; } else if (calculation.CALCULATION_TYPE == 13) //条件字符运算 { //{标签1}==3:{标签1}+"123";{标签1}==4:{标签1}+"123" List <string> exps = code.Split(';').ToList(); string temp = ""; foreach (var exp1 in exps) { if (exp1.Split(':').Length < 2) { continue; } temp += " if (" + exp1.Split(':')[0] + ") { return (" + exp1.Split(':')[1] + ").ToString(); } \r\n"; } temp += " return \"\"; \r\n"; code = temp; } else if (calculation.CALCULATION_TYPE == 100) //C#脚本 { //支持C#语法,最后返回值(Double/String) resultType = "string"; } else //不支持的类型 { code = $" return \"计算类型[{calculation.CALCULATION_TYPE}],不支持的类型。\"; \r\n"; } execCode += DynamicCode.BuildExecFunc(funcname, resultType, code, funcParam); //增加一个函数 index++; FuncAndParamTagPKNO.Add(funcname, paramTas); //添加 } execCode += "}\r\n"; #endregion #region 编译代码 CodeDomProvider compiler = new CSharpCodeProvider(); CompilerParameters cp = new CompilerParameters() { GenerateExecutable = false, GenerateInMemory = true, }; cp.ReferencedAssemblies.Add("BFM.Common.Base.dll"); CompilerResults cr = compiler.CompileAssemblyFromSource(cp, execCode); if (cr.Errors.HasErrors) { NetLog.Error("DeviceMonitor.ThreadAutoCalculation Invaild Code: :" + execCode); } dynamicCode = cr.CompiledAssembly.GetType(className); //获取 #endregion } if ((TagCalculations == null) || (!TagCalculations.Any()) || (dynamicCode == null) || (FuncAndParamTagPKNO.Count <= 0)) { Thread.Sleep(500); continue; } #region 获取值 index = 0; foreach (FmsTagCalculation calculation in TagCalculations) { FmsAssetTagSetting tagResult = GetTagSettingById(calculation.RESULT_TAG_PKNO); //结果 if (tagResult == null) { continue; } if (FuncAndParamTagPKNO.Count < index) { break; } string funcName = FuncAndParamTagPKNO.Keys.ToList()[index]; var tagParms = FuncAndParamTagPKNO.Values.ToList()[index]; List <object> paramValues = new List <object>(); //参数值 foreach (var tagpkno in tagParms) //参数 { object value = null; FmsAssetTagSetting tagParam = GetTagSettingById(tagpkno.Key); if (tagParam != null) { value = SafeConverter.SafeToStr(tagParam.CUR_VALUE); //if ((calculation.CALCULATION_TYPE == 2) || (tagParam.VALUE_TYPE > 0 && tagParam.VALUE_TYPE < 20)) //{ // value = SafeConverter.SafeToDouble(tagParam.CUR_VALUE); //} //else //{ // value = SafeConverter.SafeToStr(tagParam.CUR_VALUE); //} } else { value = ""; } paramValues.Add(value); } object obj = dynamicCode.InvokeMember(funcName, BindingFlags.Public | BindingFlags.Static | BindingFlags.InvokeMethod, System.Type.DefaultBinder, null, paramValues.ToArray()); string newValue = ""; //新的计算结果 #region 更新结果 if (calculation.CALCULATION_TYPE == 1) //逻辑运算 { newValue = SafeConverter.SafeToBool(obj) ? "1" : "0"; } else { newValue = SafeConverter.SafeToStr(obj); } SaveData(tagResult.PKNO, newValue); //保存更新值 #endregion index++; } #endregion } catch (Exception e) { NetLog.Error("DeviceMonitor.ThreadAutoCalculation error:", e); } Thread.Sleep(100); } }
//程序启动 protected override void OnStartup(StartupEventArgs e) { #region 检测进程是否存在 string sName = Assembly.GetExecutingAssembly().FullName; bool runone = true; System.Threading.Mutex run = new System.Threading.Mutex(true, sName, out runone); if (!runone) { MessageBox.Show("系统已经在运行中,请查看任务管理器并退出系统【BFM.WPF.MainUI.exe】.", "系统启动", MessageBoxButton.OK, MessageBoxImage.Error); System.Environment.Exit(0); return; } run.ReleaseMutex(); //必须需要 #endregion NewMainForm mainForm; #if !DEBUG NetLog.Write("============系统启动========="); mainForm = new NewMainForm(); #endif System.Threading.ThreadPool.SetMaxThreads(2000, 800); #region 获取用户 try { WcfClient <ISDMService> _SDMService = new WcfClient <ISDMService>(); List <SysUser> mSysUsers = _SDMService.UseService(s => s.GetSysUsers("USE_FLAG = 1")).ToList(); } catch (Exception ex) { MessageBox.Show("数据库访问失败,请核实系统配置是否正确。\r\n错误为:" + ex.Message, "系统启动", MessageBoxButton.OK, MessageBoxImage.Error); System.Environment.Exit(0); return; } #endregion try { #region 自动升级程序 //1.检验版本并提示升级 //VersionManage.UpdateAppVersion(true); //检验版本 //2.开启后台检查版本 //VersionManage.AutoUpdateVersion(); //自动升级版本 #endregion #if DEBUG NetLog.Write("系统为DEBUG,请使用Release..."); mainForm = new NewMainForm(); #endif mainForm.ShowDialog(); } catch (Exception ex) { NetLog.Error("系统错误,", ex); WPFMessageBox.ShowError( $"系统错误,请核实。" + Environment.NewLine + $"错误为:" + ex.Message, "系统错误"); } }
/// <summary> /// 后台自动升级程序 /// <param name="bFisrtCheck">是否首次检测</param> /// </summary> public static void UpdateAppVersion(bool bFisrtCheck) { try { if (File.Exists(UpgradeBatFile)) { File.Delete(UpgradeBatFile); } //删除升级文件 string updateCmd = ""; int iUpdateIndex = 0; //升级文件的序号 bool bForceUpdate = false; //强制升级 foreach (SysAppInfo appInfo in AllModels) { string error; List <string> value = VersionProcess.GetDBVersionNO(appInfo.MODEL_CODE, out error); //获取服务器的新版本 if (!string.IsNullOrEmpty(error)) //错误 { if (bFisrtCheck) //第一次检验失败 { WPFMessageBox.ShowError(error + "请检查连接!", "系统启动失败"); App.AppExit(5); //系统退出 } continue; } int dbVersion = -1; string newAppPKNO = ""; if (value.Count >= 2) { newAppPKNO = value[0]; dbVersion = SafeConverter.SafeToInt(value[1]); } if (dbVersion < appInfo.MODEL_INNER_VERSION) //服务器版本 < 当前版本 => 上传 { string filename = Environment.CurrentDirectory + "\\" + (String.IsNullOrEmpty(appInfo.APP_RELATIVE_PATH) ? "" : appInfo.APP_RELATIVE_PATH + "\\") + appInfo.APP_NAME; if (!File.Exists(filename)) { continue; } #region 版本 SysAppInfo newApp = new SysAppInfo() { PKNO = CBaseData.NewGuid(), MODEL_CODE = appInfo.MODEL_CODE, MODEL_NAME = appInfo.MODEL_NAME, MODEL_INNER_VERSION = appInfo.MODEL_INNER_VERSION, MODEL_VERSION = appInfo.MODEL_VERSION, APP_NAME = appInfo.APP_NAME, APP_RELATIVE_PATH = appInfo.APP_RELATIVE_PATH, VERSION_INTROD = appInfo.VERSION_INTROD, MODEL_CONTENT = FileHelper.FileToBytes(filename), //上传文档 CREATED_BY = CBaseData.LoginName, CREATION_DATE = DateTime.Now, VERSION_TYPE = appInfo.VERSION_TYPE, REMARK = appInfo.REMARK, }; bool ret = VersionProcess.UploadApp(newApp); //上传到数据库 if (ret) { EventLogger.Log($"上传最新版本 {newApp.MODEL_VERSION} 的程序【{newApp.MODEL_NAME}】到服务器。"); } #endregion } else if (dbVersion > appInfo.MODEL_INNER_VERSION) //服务器版本 > 当前版本 => 升级 { #region 载最新版本 SysAppInfo newApp = VersionProcess.GetNewApp(newAppPKNO); //下载 #endregion if (string.IsNullOrEmpty(newApp?.PKNO)) //下载失败 { continue; } bool updateResult = false; //强制升级 #region 保存到本地,并升级 string newfilename = Environment.CurrentDirectory + "\\Temp\\" + (String.IsNullOrEmpty(newApp.APP_RELATIVE_PATH) ? "" : newApp.APP_RELATIVE_PATH + "\\") + newApp.APP_NAME; string directory = Path.GetDirectoryName(newfilename); if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } FileHelper.BytesToFile(newApp.MODEL_CONTENT, newfilename); string oldfilename = Environment.CurrentDirectory + "\\" + (String.IsNullOrEmpty(newApp.APP_RELATIVE_PATH) ? "" : newApp.APP_RELATIVE_PATH + "\\") + newApp.APP_NAME; string filename = (String.IsNullOrEmpty(newApp.APP_RELATIVE_PATH) ? "" : newApp.APP_RELATIVE_PATH + "\\") + newApp.APP_NAME; try { File.Copy(newfilename, oldfilename); updateResult = true; //升级成功 EventLogger.Log($"【{appInfo.MODEL_NAME}】 {appInfo.MODEL_VERSION} 完成自动升级。"); } catch (Exception) //升级失败 { iUpdateIndex++; //索引号 #region 形成升级Bat updateCmd += $"echo {iUpdateIndex}. 正在升级 【{appInfo.MODEL_NAME}】 到 {appInfo.MODEL_VERSION} ..." + Environment.NewLine; //显示提示信息 updateCmd += "ping 127.0.0.1 -n 2 > nul " + Environment.NewLine; //暂停2s updateCmd += "if not exist Temp\\" + filename + " (" + Environment.NewLine; //检验是否已经下载了文件 updateCmd += $" echo 【{appInfo.MODEL_NAME}】 {appInfo.MODEL_VERSION} ... 尚未下载,升级失败!" + Environment.NewLine; // updateCmd += $")" + Environment.NewLine; // updateCmd += "copy /y " + "Temp\\" + filename + " " + filename + Environment.NewLine; //复制 => 升级文件 updateCmd += "if %ERRORLEVEL% == 0 (" + Environment.NewLine; //复制成功 updateCmd += $" echo 【{appInfo.MODEL_NAME}】 {appInfo.MODEL_VERSION} 升级成功。" + Environment.NewLine; // updateCmd += $" echo %DATE% %TIME% 完成【{appInfo.MODEL_NAME}】 {appInfo.MODEL_VERSION} 的升级 >>log\\AutoUpdate.txt" + Environment.NewLine; // updateCmd += ") else (" + Environment.NewLine; //复制失败 updateCmd += " copy /y " + "Temp\\" + filename + " " + filename + Environment.NewLine; //二次复制 => 升级文件 updateCmd += " if %ERRORLEVEL% == 0 (" + Environment.NewLine; //复制成功 updateCmd += $" echo 【{appInfo.MODEL_NAME}】 {appInfo.MODEL_VERSION} 升级成功。" + Environment.NewLine; // updateCmd += $" echo %DATE% %TIME% 完成【{appInfo.MODEL_NAME}】 {appInfo.MODEL_VERSION} 的升级 >>log\\AutoUpdate.txt" + Environment.NewLine; // updateCmd += " ) else (" + Environment.NewLine; updateCmd += $" echo 【{appInfo.MODEL_NAME}】 {appInfo.MODEL_VERSION} 升级失败,请退出系统后,运行【{UpgradeBatFile}】。" + Environment.NewLine; // updateCmd += $" echo %DATE% %TIME% 【{appInfo.MODEL_NAME}】 {appInfo.MODEL_VERSION} 升级失败,错误代码为 %ERRORLEVEL% >>log\\AutoUpdate.txt" + Environment.NewLine; // updateCmd += " pause" + Environment.NewLine; updateCmd += " exit" + Environment.NewLine; updateCmd += " )" + Environment.NewLine; updateCmd += ")" + Environment.NewLine; #endregion updateResult = false; } #endregion if ((!updateResult) && (!bForceUpdate)) //升级失败,检验是否强制升级 { if (bFisrtCheck) { bForceUpdate = true; //强制升级 } else //不是第一次检测,则需要检测是否强制升级 { int updateType = VersionProcess.CheckUpdateVersion(appInfo.MODEL_CODE, appInfo.MODEL_INNER_VERSION.Value); //获取版本升级信息,是否强制升级 #region 强制升级 if (updateType == 2) //强制升级 { bForceUpdate = true; //强制升级 } #endregion } } } } //end foreach if (!string.IsNullOrEmpty(updateCmd)) //有升级 { if (!Directory.Exists("log")) { Directory.CreateDirectory("log"); } updateCmd = "@echo off " + Environment.NewLine + " color fc " + Environment.NewLine + " title ******** 客户端自动升级程序 ******* " + Environment.NewLine + " echo *****************客户端自动升级程序(共" + iUpdateIndex + "个) ************* " + Environment.NewLine + updateCmd; updateCmd += "echo 系统升级成功!" + (bFisrtCheck ? "请重新打开程序。": "") + Environment.NewLine; //升级成功 updateCmd += "del /f /q " + UpgradeBatFile + Environment.NewLine; //删除本身 FileHelper.SaveStrToFile(updateCmd, UpgradeBatFile, true); //保存升级文件 } if (bForceUpdate) //强制升级 { Application.Current.Dispatcher.Invoke(new Action(() => { WPFMessageBox.ShowWarring( $"检测到系统有强制升级的新版本,系统自动升级失败,需要强制升级。" + Environment.NewLine + "***!系统将退出!***", "自动升级程序"); })); App.AppExit(5); } } catch (Exception ex) { NetLog.Error("自动升级程序失败,", ex); Console.WriteLine("自动升级程序失败,错误为:" + ex.Message); } }
public void ComplexMissingOpenBracketTest() { netlog_section.Logger.Layout.Value = "[[[#date]][[#severity - #message]] - [[#assembly] - #file [#method]]]]"; var message = "An Error occurred"; var logger = new NetLog(netlog_section); var ouput = logger.Error(message); }
public void ComplexFileLoggerTest3() { netlog_section.Logger.Layout.Value = "[#date][[#severity - #message] - [#assembly - #file [#method]]]"; var message = "An Error occurred"; var assembly = "NetLog.Test"; var file = @"c:\Repositories\netlog\NetLog.Test\NetLogTests.cs"; var severity = "ERROR"; var method = "Void ComplexFileLoggerTest3()"; var expected = "[" + DateTime.Now.ToString("MM/dd/yyyy") + "][[" + severity + " - " + message + "] - [" + assembly + " - " + file + " [" + method + "]]]"; var logger = new NetLog(netlog_section); var output = logger.Error(message); Assert.AreEqual(expected, output); }
public string GetWorkOrder(string jsWOMain, string jsWODetail) { NetLog.Write("GetWorkOrder" + " " + jsWOMain); NetLog.Write("GetWorkOrder" + " " + jsWODetail); List <FDIGetWOrder> mains = new List <FDIGetWOrder>(); List <FDIGetWOrderDetail> detials = new List <FDIGetWOrderDetail>(); //String jsWOMain = "[{\r\n" + // "\"DocEntry\": \"5\",\r\n" + // "\"ItemCode\": \"P00000001\",\r\n" + // "\"Status\": \"L\",\r\n" + // "\"Type\": \"S\",\r\n" + // "\"PlannedQty\": \"100.000000\",\r\n" + // " \"Comments\": \"\",\"RlsDate\": \"2019-03-26\",\r\n" + // " \"Warehouse\": \"W001\",\r\n" + // "\"Project\": \"\",\r\n" + // "\"OcrCode\": \"\",\r\n" + // "\"OcrCode2\": \"\",\r\n" + // " \"OcrCode3\": \"\",\"OcrCode4\": \"\",\r\n" + // "\"OcrCode5\": \"\",\r\n" + // "\"OriginNum\": \"-1\",\r\n" + // "\"Cardcode\": \"\",\r\n" + // "\"UserSign\": \"9\",\r\n" + // "\"StartDate\": \"2019-03-26\",\"DueDate\": \"2019-03-26\",\r\n" + // "\"DocTime\": \"142602\",\r\n" + // "\"Udf1\": \"\",\r\n" + // "\"Udf2\": \"\",\r\n" + // "\"Udf3\": \"\",\r\n" + // "\"Udf4\": \"\",\r\n" + // " \"Udf5\": \"\"\r\n" + // "}\r\n" + // "]"; //String jsWODetail = "[{\r\n" + // "\"DocEntry\": \"5\",\r\n" + // "\"LineNum\": \"0\",\r\n" + // " \"ItemCode\": \"M00000001\",\r\n" + // " \"ItemName\": \"16寸轮毂毛坯\",\r\n" + // " \"BaseQty\": \"1.000000\",\r\n" + // " \"PlannedQty\": \"100.000000\",\r\n" + // " \"WareHouse\": \"W001\",\r\n" + // " \"Project\": \"\",\r\n" + // " \"OcrCode\": \"\",\r\n" + // " \"OcrCode2\": \"\",\r\n" + // " \"OcrCode3\": \"\",\r\n" + // " \"OcrCode4\": \"\",\r\n" + // " \"OcrCode5\": \"\",\r\n" + // " \"Udf1\": \"\",\r\n" + // " \"Udf2\": \"\",\r\n" + // " \"Udf3\": \"\",\r\n" + // " \"Udf4\": \"\",\r\n" + // " \"Udf5\": \"\"\r\n" + // " }\r\n" + // "]"; try { mains = SafeConverter.JsonDeserializeObject <List <FDIGetWOrder> >(jsWOMain); detials = SafeConverter.JsonDeserializeObject <List <FDIGetWOrderDetail> >(jsWODetail); foreach (var main in mains) { var check = GetFDIGetWOrders($"DocEntry = '{main.DocEntry}'"); foreach (var c in check) { DelFDIGetWOrder(c.PKNO); } main.PKNO = CBaseData.NewGuid(); AddFDIGetWOrder(main); } foreach (var detail in detials) { var check = GetFDIGetWOrderDetails($"DocEntry = '{detail.DocEntry}'and LineNum = '{detail.LineNum}'"); foreach (var c in check) { DelFDIGetWOrderDetail(c.PKNO); } detail.PKNO = CBaseData.NewGuid(); AddFDIGetWOrderDetail(detail); } } catch (Exception ex) { NetLog.Error("GetRawMaterial error", ex); return("error: " + ex.Message); } return("OK"); }