public DbResult <bool> Auditin(long userId, long stockOutId) { var flag = _client.Ado.UseTran(() => { //添加库存 如果有则修改 如果没有新增 添加库存明细 var stockOutDetailList = _client.Queryable <Wms_stockoutdetail>().Where(c => c.StockOutId == stockOutId).ToList(); var inventory = new Wms_inventory(); stockOutDetailList.ForEach(c => { var exist = _client.Queryable <Wms_inventory>().Where(i => i.MaterialId == c.MaterialId && i.StoragerackId == c.StoragerackId).First(); CheckNull.ArgumentIsNullException(exist, PubConst.StockOut1); if (exist.Qty < c.ActOutQty) { CheckNull.ArgumentIsNullException(PubConst.StockOut2); } //update exist.Qty = exist.Qty - c.ActOutQty; exist.ModifiedBy = userId; exist.ModifiedDate = DateTimeExt.DateTime; _client.Updateable(exist); }); //修改明细状态 2 _client.Updateable(new Wms_stockoutdetail { Status = StockInStatus.egis.ToByte(), AuditinId = userId, AuditinTime = DateTimeExt.DateTime, ModifiedBy = userId, ModifiedDate = DateTimeExt.DateTime }).UpdateColumns(c => new { c.Status, c.AuditinId, c.AuditinTime, c.ModifiedBy, c.ModifiedDate }).Where(c => c.StockOutId == stockOutId && c.IsDel == 1).ExecuteCommand(); //修改主表中的状态改为进行中 2 _client.Updateable(new Wms_stockout { StockOutId = stockOutId, StockOutStatus = StockInStatus.egis.ToByte(), ModifiedBy = userId, ModifiedDate = DateTimeExt.DateTime }).UpdateColumns(c => new { c.StockOutStatus, c.ModifiedBy, c.ModifiedDate }).ExecuteCommand(); }); return(flag); }
public static T HttpGet <T>(string url, Dictionary <string, string> postData = null, Dictionary <string, string> headers = null) { CheckNull.ArgumentIsNullException(url, nameof(url)); var handler = new HttpClientHandler() { AutomaticDecompression = DecompressionMethods.None }; using (var http = new HttpClient(handler)) { if (headers != null) { foreach (var header in headers) { http.DefaultRequestHeaders.Add(header.Key, header.Value); } } if (postData != null) { url = url + "?" + BuildParam(postData); } HttpResponseMessage response = http.GetAsync(url).Result; return(response.Content.ReadAsStreamAsync().Result.ToObject <T>()); } }
public static bool Delete(string directory, bool isDeleteRoot = true) { CheckNull.ArgumentIsNullException(directory, nameof(directory)); var flag = false; var dirPathInfo = new DirectoryInfo(directory); if (dirPathInfo.Exists) { //删除目录下所有文件 foreach (var fileInfo in dirPathInfo.GetFiles()) { fileInfo.Delete(); } //递归删除所有子目录 foreach (var subDirectory in dirPathInfo.GetDirectories()) { Delete(subDirectory.FullName); } //删除目录 if (isDeleteRoot) { dirPathInfo.Attributes = FileAttributes.Normal; dirPathInfo.Delete(); } flag = true; } return(flag); }
public static void Delete(string filePath) { CheckNull.ArgumentIsNullException(filePath, nameof(filePath)); if (File.Exists(filePath)) { File.Delete(filePath); } }
public static string ToSha1(this string str) { CheckNull.ArgumentIsNullException(str, nameof(str)); SHA1 shaM = new SHA1Managed(); var result = shaM.ComputeHash(str.ToBytes()); return(result.ToHexString()); }
public static string ToMd52(this string str) { CheckNull.ArgumentIsNullException(str, nameof(str)); var md5Hasher = new MD5CryptoServiceProvider(); var data = md5Hasher.ComputeHash(Encoding.UTF8.GetBytes(str)); return(data.ToHexString()); }
public static string GetMimeType(string extension) { CheckNull.ArgumentIsNullException(extension, nameof(extension)); if (!extension.StartsWith(".")) { extension = "." + extension; } return(_mappings.Value.TryGetValue(extension, out string mime) ? mime : "application/octet-stream"); }
public static IServiceCollection AddOption <T>(this IServiceCollection services, string key, IConfiguration configuration) where T : class, new() { //if (key.IsEmpty()) //{ // throw new ArgumentNullException(nameof(key)); //} CheckNull.ArgumentIsNullException(key, nameof(key)); return(services.AddOptions().Configure <T>(configuration?.GetSection(key))); }
public static string ToSha512(this string str) { CheckNull.ArgumentIsNullException(str, nameof(str)); using (var shaM = SHA512.Create()) { //SHA512 shaM = new SHA512Managed(); var result = shaM.ComputeHash(str.ToBytes()); return(result.ToHexString()); } }
/// <summary> /// Gets the <see cref="bool"/> value with the specified key from the cache asynchronously or returns /// <c>null</c> if the key was not found. /// </summary> /// <param name="cache">The distributed cache.</param> /// <param name="key">The cache item key.</param> /// <returns>The <see cref="bool"/> value or <c>null</c> if the key was not found.</returns> /// <exception cref="ArgumentNullException"><paramref name="cache"/> or <paramref name="key"/> is <c>null</c>.</exception> public static async Task <bool?> GetBooleanAsync(this IDistributedCache cache, string key) { CheckNull.ArgumentIsNullException(cache, nameof(cache)); CheckNull.ArgumentIsNullException(cache, nameof(key)); var bytes = await cache.GetAsync(key).ConfigureAwait(false); if (bytes == null) { return(null); } return(bytes.GetBinaryReader().ReadBoolean()); }
public bool Auditin(long userId, long InventorymoveId) { var flag = _client.Ado.UseTran(() => { var invmovedetailList = _client.Queryable <Wms_invmovedetail>().Where(c => c.InventorymoveId == InventorymoveId).ToList(); var invmove = _client.Queryable <Wms_inventorymove>().Where(c => c.InventorymoveId == InventorymoveId).First(); invmovedetailList.ForEach(c => { var exist = _client.Queryable <Wms_inventory>().Where(i => i.MaterialId == c.MaterialId && i.InventoryBoxId == invmove.SourceInventoryBoxId).First(); CheckNull.ArgumentIsNullException(exist, PubConst.StockOut1); if (exist.Qty < c.ActQty) { CheckNull.ArgumentIsNullException(PubConst.StockOut2); } //update exist.Qty = exist.Qty - (int)c.ActQty; exist.ModifiedBy = userId; exist.ModifiedDate = DateTimeExt.DateTime; _client.Updateable(exist).ExecuteCommand(); exist = _client.Queryable <Wms_inventory>().Where(i => i.MaterialId == c.MaterialId && i.InventoryBoxId == invmove.AimInventoryBoxId).First(); if (exist == null) { _client.Insertable(new Wms_inventory { InventoryBoxId = invmove.AimInventoryBoxId, CreateBy = userId, InventoryId = PubId.SnowflakeId, MaterialId = c.MaterialId, Qty = (int)c.ActQty, }).ExecuteCommand(); } else { exist.Qty += (int)c.ActQty; exist.ModifiedBy = userId; exist.ModifiedDate = DateTimeExt.DateTime; _client.Updateable(exist).ExecuteCommand(); } }); //修改明细状态 2 _client.Updateable(new Wms_invmovedetail { Status = StockInStatus.task_confirm.ToByte(), AuditinId = userId, AuditinTime = DateTimeExt.DateTime, ModifiedBy = userId, ModifiedDate = DateTimeExt.DateTime }).UpdateColumns(c => new { c.Status, c.AuditinId, c.AuditinTime, c.ModifiedBy, c.ModifiedDate }).Where(c => c.InventorymoveId == InventorymoveId && c.IsDel == 1).ExecuteCommand(); //修改主表中的状态改为进行中 2 _client.Updateable(new Wms_inventorymove { InventorymoveId = InventorymoveId, Status = StockInStatus.task_confirm.ToByte(), ModifiedBy = userId, ModifiedDate = DateTimeExt.DateTime }).UpdateColumns(c => new { c.Status, c.ModifiedBy, c.ModifiedDate }).ExecuteCommand(); }).IsSuccess; return(flag); }
public static string ToMd5(this string str) { CheckNull.ArgumentIsNullException(str, nameof(str)); using (var md5Hash = MD5.Create()) { var data = md5Hash.ComputeHash(Encoding.UTF8.GetBytes(str)); //for (var i = 0; i < data.Length; i++) //{ // sBuilder.Append(data[i].ToString("x2")); //} return(data.ToHexString()); } }
/// <summary> ///根据生成的dll注册服务 /// </summary> /// <param name="service">IServiceCollection</param> /// <param name="assemblyName">程序集的名称</param> /// <param name="injection">生命周期</param> public static void RegisterAssembly(IServiceCollection services, string assemblyName, ServiceLifetime injection = ServiceLifetime.Scoped) { CheckNull.ArgumentIsNullException(services, nameof(services)); CheckNull.ArgumentIsNullException(assemblyName, nameof(assemblyName)); var assembly = AssemblyLoadContext.Default.LoadFromAssemblyName(new AssemblyName(assemblyName)); if (assembly.IsNullT()) { throw new DllNotFoundException($"\"{assemblyName}\".dll不存在"); } var types = assembly.GetTypes().Where(x => (typeof(IDependency).IsAssignableFrom(x)) && !x.IsInterface).ToList(); //&& !o.Name.Contains("Base") foreach (var type in types) { var faces = type.GetInterfaces().Where(o => o.Name != "IDependency" && !o.Name.Contains("Base")).ToArray(); if (faces.Any()) { var interfaceType = faces.LastOrDefault();//.FirstOrDefault(); switch (injection) { case ServiceLifetime.Scoped: services.AddScoped(interfaceType, type); if (faces.Count() > 2) //存在多个注册 { services.AddScoped(faces[faces.Count() - 2], type); } break; case ServiceLifetime.Singleton: services.AddSingleton(interfaceType, type); if (faces.Count() > 2) //存在多个注册 { services.AddScoped(faces[faces.Count() - 2], type); } break; case ServiceLifetime.Transient: services.AddTransient(interfaceType, type); if (faces.Count() > 2) //存在多个注册 { services.AddScoped(faces[faces.Count() - 2], type); } break; } } } }
/// <summary> /// /// </summary> /// <param name="obj"></param> /// <returns></returns> public static string ToJsonL(this object obj) { var config = GlobalCore.GetRequiredService <JsonConfig>(); CheckNull.ArgumentIsNullException(config, "请添加app.UseGlobalCore();services.AddJson();"); switch (config.JsonType) { case JsonType.MessagePack: return(obj.MpToJson()); case JsonType.ProtobufNet: throw new Exception("未实现"); case JsonType.SimdJsonSharp: throw new Exception("未实现"); case JsonType.SpanJson: throw new Exception("未实现"); case JsonType.SwifterJson: if (config.SwifterJsonConfig.DateTimeFormat.IsEmpty()) { return(obj.SwifterToJson()); } else { return(obj.SwifterToJson(config.SwifterJsonConfig.DateTimeFormat, config.SwifterJsonConfig.JsonFormatterOptions)); } case JsonType.Utf8Json: return(obj.Utf8JsonToJson()); case JsonType.Jil: return(obj.JilToJson()); case JsonType.ServiceStackText: throw new Exception("未实现"); case JsonType.Newtonsoft: return(obj.ToJson(config.Newtonsoft.DateTimeFormat)); default: return(obj.JilToJson()); } }
public static string GetExtension(string mimeType, bool throwErrorIfNotFound) { CheckNull.ArgumentIsNullException(mimeType, nameof(mimeType)); if (mimeType.StartsWith(".")) { throw new ArgumentException("Requested mime type is not valid: " + mimeType); } if (_mappings.Value.TryGetValue(mimeType, out string extension)) { return(extension); } if (throwErrorIfNotFound) { throw new ArgumentException("Requested mime type is not registered: " + mimeType); } else { return(string.Empty); } }
public static IDictionary <string, string> GetKeyValuesFromPath(string path, EncodingType type = EncodingType.UTF8) { try { CheckNull.ArgumentIsNullException(path, nameof(path)); using (StreamReader streamReader = new StreamReader(path, BytesExt.GetEncoding(type))) { _data.Clear(); _reader = new JsonTextReader(streamReader) { DateParseHandling = 0 }; JObject jObject = JObject.Load(_reader); new JsonDict().VisitJObject(jObject); return(_data); } } catch (Exception) { throw new FormatException("json格式不正确"); } }
public static string HttpPost(string url, Dictionary <string, string> postData = null, Dictionary <string, string> headers = null) { CheckNull.ArgumentIsNullException(url, nameof(url)); var handler = new HttpClientHandler() { AutomaticDecompression = DecompressionMethods.None }; using (var http = new HttpClient(handler)) { if (headers != null) { foreach (var header in headers) { http.DefaultRequestHeaders.Add(header.Key, header.Value); } } using (HttpContent httpContent = new StringContent(BuildParam(postData), Encoding.UTF8)) { HttpResponseMessage response = http.PostAsync(url, httpContent).Result; return(response.Content.ReadAsStringAsync().Result); } } }