public static ProductDataEntity ToEntity(this Thermo2ProductB data) { var en = new ProductDataEntity(); en.StartTime = data.StartTime.ToString("yyyyMMdd-HHmmss"); en.FinishTime = data.FinishTime.ToString("yyyyMMdd-HHmmss"); en.Status = data.Status.ToString(); en.Error = data.Error; en.CT = decimal.Parse(data.CT.ToString("F1")); en.Barcode = data.Barcode; en.ProductType = data.ProductType; en.Description = data.Description; en.Spcs = string.Join(",", data.SPCItems.Select(f => $"{f.SPC}:{f.Value:F3}")); var sb = new StringBuilder(); sb.Append("Camera1,"); sb.Append(string.Join(",", data.RawData_C1Profile.Select(p => p.Max(v => v.Z)))); sb.Append("Camera2,"); sb.Append(string.Join(",", data.RawData_C2Profile.Select(p => p.Max(v => v.Z)))); sb.Append("Up,"); sb.Append(string.Join(",", data.RawData_UpProfile.Select(p => p.Max(v => v.Z)))); sb.Append("Down,"); sb.Append(string.Join(",", data.RawData_DownProfile.Select(p => p.Max(v => v.Z)))); en.Raws = sb.ToString(); return(en); }
/// <summary> /// 更新一条记录(异步方式) /// </summary> /// <param name="entity">实体模型</param> /// <returns></returns> public virtual async Task <bool> UpdateAsync(ProductDataEntity entity) { Dictionary <string, object> dict = new Dictionary <string, object>(); GetParameters(entity, dict); string strSQL = "Update ProductData SET " + "ProductID = @ProductID," + "TableName = @TableName," + "PropertyValue = @PropertyValue," + "Stocks = @Stocks," + "OrderNum = @OrderNum," + "AlarmNum = @AlarmNum," + "BuyTimes = @BuyTimes," + "Weight = @Weight," + "Volume = @Volume," + "Price = @Price," + "Price_Market = @Price_Market," + "Price_Activity = @Price_Activity," + "Price_Settlement = @Price_Settlement," + "Price_Member = @Price_Member," + "Price_Agent = @Price_Agent," + "Price_Wholesale1 = @Price_Wholesale1," + "Price_Wholesale2 = @Price_Wholesale2," + "Price_Wholesale3 = @Price_Wholesale3," + "Number_Wholesale1 = @Number_Wholesale1," + "Number_Wholesale2 = @Number_Wholesale2," + "Number_Wholesale3 = @Number_Wholesale3," + "IsValid = @IsValid" + " WHERE " + "ID = @ID"; return(await Task.Run(() => _DB.ExeSQLResult(strSQL, dict))); }
public static ProductDataEntity ToEntity(this Thermo1Product data) { var en = new ProductDataEntity(); en.StartTime = data.StartTime.ToString("yyyyMMdd-HHmmss.fff"); en.FinishTime = data.FinishTime.ToString("yyyyMMdd-HHmmss"); en.Status = data.Status.ToString(); en.Error = data.Error; en.CT = decimal.Parse(data.CT.ToString("F1")); en.Barcode = data.Barcode; en.ProductType = data.ProductType; en.Description = data.Description; en.Spcs = string.Join(",", data.SPCItems.Select(f => $"{f.SPC}:{f.Value:F3}")); var sb = new StringBuilder(); sb.Append(string.Join(",", data.RawDataUp.Select(p => $"{p.Z:F3}:{p.Status}"))); sb.Append(","); sb.Append(string.Join(",", data.RawDataDown.Select(p => $"{p.Z:F3}:{p.Status}"))); en.Raws = sb.ToString(); return(en); }
/// <summary> /// 通过数据读取器生成实体类 /// </summary> /// <param name="rdr"></param> /// <returns></returns> private static ProductDataEntity GetEntityFromrdr(NullableDataReader rdr) { ProductDataEntity info = new ProductDataEntity(); info.ID = rdr.GetInt32("ID"); info.ProductID = rdr.GetInt32("ProductID"); info.TableName = rdr.GetString("TableName"); info.PropertyValue = rdr.GetString("PropertyValue"); info.Stocks = rdr.GetInt32("Stocks"); info.OrderNum = rdr.GetInt32("OrderNum"); info.AlarmNum = rdr.GetInt32("AlarmNum"); info.BuyTimes = rdr.GetInt32("BuyTimes"); info.Weight = rdr.GetDouble("Weight"); info.Volume = rdr.GetDouble("Volume"); info.Price = rdr.GetDecimal("Price"); info.Price_Market = rdr.GetDecimal("Price_Market"); info.Price_Activity = rdr.GetDecimal("Price_Activity"); info.Price_Settlement = rdr.GetDecimal("Price_Settlement"); info.Price_Member = rdr.GetDecimal("Price_Member"); info.Price_Agent = rdr.GetDecimal("Price_Agent"); info.Price_Wholesale1 = rdr.GetDecimal("Price_Wholesale1"); info.Price_Wholesale2 = rdr.GetDecimal("Price_Wholesale2"); info.Price_Wholesale3 = rdr.GetDecimal("Price_Wholesale3"); info.Number_Wholesale1 = rdr.GetInt32("Number_Wholesale1"); info.Number_Wholesale2 = rdr.GetInt32("Number_Wholesale2"); info.Number_Wholesale3 = rdr.GetInt32("Number_Wholesale3"); info.IsValid = rdr.GetBoolean("IsValid"); return(info); }
/// <summary> /// 把实体类转换成键/值对集合 /// </summary> /// <param name="entity"></param> /// <param name="dict"></param> private static void GetParameters(ProductDataEntity entity, Dictionary <string, object> dict) { dict.Add("ID", entity.ID); dict.Add("ProductID", entity.ProductID); dict.Add("TableName", entity.TableName); dict.Add("PropertyValue", entity.PropertyValue); dict.Add("Stocks", entity.Stocks); dict.Add("OrderNum", entity.OrderNum); dict.Add("AlarmNum", entity.AlarmNum); dict.Add("BuyTimes", entity.BuyTimes); dict.Add("Weight", entity.Weight); dict.Add("Volume", entity.Volume); dict.Add("Price", entity.Price); dict.Add("Price_Market", entity.Price_Market); dict.Add("Price_Activity", entity.Price_Activity); dict.Add("Price_Settlement", entity.Price_Settlement); dict.Add("Price_Member", entity.Price_Member); dict.Add("Price_Agent", entity.Price_Agent); dict.Add("Price_Wholesale1", entity.Price_Wholesale1); dict.Add("Price_Wholesale2", entity.Price_Wholesale2); dict.Add("Price_Wholesale3", entity.Price_Wholesale3); dict.Add("Number_Wholesale1", entity.Number_Wholesale1); dict.Add("Number_Wholesale2", entity.Number_Wholesale2); dict.Add("Number_Wholesale3", entity.Number_Wholesale3); dict.Add("IsValid", entity.IsValid); }
/// <summary> /// 增加一条记录,返回新的ID号。需要有一个单一主键,并且开启有标识符属性(异步方式) /// </summary> /// <param name="entity">实体模型</param> /// <returns></returns> public virtual async Task <int> InsertAsync(ProductDataEntity entity) { Dictionary <string, object> dict = new Dictionary <string, object>(); GetParameters(entity, dict); string strSQL = "insert into ProductData (" + "ProductID," + "TableName," + "PropertyValue," + "Stocks," + "OrderNum," + "AlarmNum," + "BuyTimes," + "Weight," + "Volume," + "Price," + "Price_Market," + "Price_Activity," + "Price_Settlement," + "Price_Member," + "Price_Agent," + "Price_Wholesale1," + "Price_Wholesale2," + "Price_Wholesale3," + "Number_Wholesale1," + "Number_Wholesale2," + "Number_Wholesale3," + "IsValid) " + "values(" + "@ProductID," + "@TableName," + "@PropertyValue," + "@Stocks," + "@OrderNum," + "@AlarmNum," + "@BuyTimes," + "@Weight," + "@Volume," + "@Price," + "@Price_Market," + "@Price_Activity," + "@Price_Settlement," + "@Price_Member," + "@Price_Agent," + "@Price_Wholesale1," + "@Price_Wholesale2," + "@Price_Wholesale3," + "@Number_Wholesale1," + "@Number_Wholesale2," + "@Number_Wholesale3," + "@IsValid)"; return(await Task.Run(() => _DB.ReturnID(strSQL, dict))); }
/// <summary> /// 获取实体(异步方式) /// </summary> /// <param name="strWhere">参数化查询条件(例如: and Name = @Name )</param> /// <param name="dict">参数的名/值集合</param> /// <returns></returns> public virtual async Task <ProductDataEntity> GetEntityAsync(string strWhere, Dictionary <string, object> dict = null) { ProductDataEntity obj = null; string strSQL = "select top 1 * from ProductData where 1=1 " + strWhere; using (NullableDataReader reader = await Task.Run(() => _DB.GetDataReader(strSQL, dict))) { if (reader.Read()) { obj = GetEntityFromrdr(reader); } } return(obj); }
/// <summary> /// 修改餐點資料 /// </summary> /// <param name="uData"></param> /// <returns></returns> public ActionResult EditProductData(ProductDataEntity uData) { var lstData = new List <ProductDataEntity>() { uData }; var errorMsg = string.Empty; var isSuccess = true; try { DataAccess.ProductDataAccess.UpdateProductData(lstData); } catch (Exception ex) { isSuccess = false; errorMsg = ex.Message.Replace("\n", ""); } return(Json(new { success = isSuccess, errorMsg = errorMsg })); }
/// <summary> /// 新增餐點資料 /// </summary> /// <param name="uData"></param> /// <returns></returns> public ActionResult NewProductData(ProductDataEntity uData) { uData.productID = Guid.NewGuid().ToString(); var lstData = new List <ProductDataEntity>() { uData }; var errorMsg = string.Empty; var isSuccess = true; try { DataAccess.ProductDataAccess.AddProductData(lstData); } catch (Exception ex) { isSuccess = false; errorMsg = ex.Message.Replace("\n", ""); } return(Json(new { success = isSuccess, errorMsg = errorMsg })); }
/// <summary> /// 取得所有餐點資料 /// </summary> /// <param name="shopID"></param> /// <param name="productTypeID"></param> /// <param name="productName"></param> /// <param name="sort"></param> /// <param name="order"></param> /// <returns></returns> public static List <ProductDataEntity> GetProductData(string shopID = null, string productTypeID = null, string productName = null, string sort = null, string order = null) { var strSQL = @" SELECT * FROM LBOM_PRODUCT P JOIN LBOM_PRODUCT_TYPE PT ON P.PRODUCTTYPEID=PT.PRODUCTTYPEID WHERE P.PRODUCTNAME LIKE '%' + ISNULL(@productName,P.PRODUCTNAME) + '%' AND P.PRODUCTTYPEID = ISNULL(@productTypeID,P.PRODUCTTYPEID) AND P.SHOPID=ISNULL(@shopID,P.SHOPID) "; productName = string.IsNullOrEmpty(productName) ? null : productName; productTypeID = string.IsNullOrEmpty(productTypeID) ? null : productTypeID; shopID = string.IsNullOrEmpty(shopID) ? null : shopID; if (!string.IsNullOrEmpty(sort) && !string.IsNullOrEmpty(order)) { strSQL += string.Format("ORDER BY {0} {1} ", sort, order); } SqlParameter[] parms = { new SqlParameter("@productName", (object)productName ?? DBNull.Value), new SqlParameter("@shopID", (object)shopID ?? DBNull.Value), new SqlParameter("@productTypeID", (object)productTypeID ?? DBNull.Value) }; //var lst = ReadData<ProductDataEntity>(strSQL, parms); //----------------------------------------------------------------------------- var lst = new List <ProductDataEntity>(); using (var conn = new SqlConnection(ConnectionString)) using (var cmd = new SqlCommand(strSQL, conn)) { cmd.CommandType = CommandType.Text; cmd.Parameters.AddRange(parms); conn.Open(); using (var pd = cmd.ExecuteReader()) { if (pd.HasRows) { while (pd.Read()) { ProductDataEntity product = new ProductDataEntity() { productID = pd["productID"].ToString(), productName = pd["productName"].ToString(), productTypeID = pd["productTypeID"].ToString(), shopID = pd["shopID"].ToString(), productPrice = Convert.ToInt32(pd["productPrice"]), productTypeName = pd["productTypeName"].ToString() }; lst.Add(product); } //Mapper.CreateMap<IDataReader, LoginUserInfoDataEntity>(); //user = Mapper.Map<IDataReader, IList<LoginUserInfoDataEntity>>(dr).ToList().First(); } } } return(lst); }
/// <summary> /// 增加或更新一条记录(异步方式) /// </summary> /// <param name="entity">实体模型</param> /// <param name="IsSave">是否增加</param> /// <returns></returns> public virtual async Task <bool> AddOrUpdateAsync(ProductDataEntity entity, bool IsSave) { return(IsSave ? await AddAsync(entity) : await UpdateAsync(entity)); }
/// <summary> /// 增加或更新一条记录 /// </summary> /// <param name="entity">实体模型</param> /// <param name="IsSave">是否增加</param> /// <returns></returns> public virtual bool AddOrUpdate(ProductDataEntity entity, bool IsSave) { return(IsSave ? Add(entity) : Update(entity)); }