📄 stockmanage.cs
字号:
namespace PowerEasy.Shop
{
using PowerEasy.Common;
using PowerEasy.Enumerations;
using PowerEasy.IDal.Shop;
using PowerEasy.Model.Shop;
using System;
using System.Collections.Generic;
public sealed class StockManage
{
private static readonly IStockManage dal = DataAccess.CreateStockManage();
private StockManage()
{
}
public static bool Add(StockInfo stockInfo)
{
if (stockInfo.StockId <= 0)
{
stockInfo.StockId = GetMaxId() + 1;
}
DoHtmlEncode(stockInfo);
return dal.Add(stockInfo);
}
public static bool Delete(string stockId)
{
if (!DataValidator.IsValidId(stockId))
{
return false;
}
foreach (string str in stockId.Split(new char[] { ',' }))
{
DeleteAndRevertProductStock(DataConverter.CLng(str));
}
return (dal.Delete(stockId) && StockItem.DeleteByStockIds(stockId));
}
private static void DeleteAndRevertProductStock(int stockId)
{
int num = (GetStockInfoById(stockId).StockType == StockType.InStock) ? -1 : 1;
foreach (StockItemInfo info2 in StockItem.GetListByStockId(stockId))
{
Product.AddStocks(info2.ProductId, num * info2.Amount, info2.Property);
}
}
private static void DoHtmlDecode(StockInfo info)
{
info.Inputer = DataSecurity.HtmlDecode(info.Inputer);
info.Remark = DataSecurity.HtmlDecode(info.Remark);
}
private static void DoHtmlEncode(StockInfo info)
{
info.Inputer = DataSecurity.HtmlEncode(info.Inputer);
info.Remark = DataSecurity.HtmlEncode(info.Remark);
}
public static IList<StockInfo> GetList(int startRowIndexId, int maxNumberRows, int searchType, string keyword)
{
if (searchType == 5)
{
DateTime time;
if (!DateTime.TryParse(keyword, out time))
{
return new List<StockInfo>();
}
keyword = time.ToShortDateString();
}
return dal.GetList(startRowIndexId, maxNumberRows, searchType, DataSecurity.FilterBadChar(keyword));
}
public static int GetMaxId()
{
return dal.GetMaxId();
}
public static StockInfo GetStockInfoById(int id)
{
return dal.GetStockInfoById(id);
}
public static StockInfo GetStockInfoById(int id, bool isDecode)
{
StockInfo stockInfoById = GetStockInfoById(id);
if (isDecode)
{
DoHtmlDecode(stockInfoById);
}
return stockInfoById;
}
public static int GetTotalOfStock(int startRowIndexId, int maxNumberRows, int searchType, string keyword)
{
return dal.GetTotalOfStock();
}
public static bool Update(StockInfo stockInfo)
{
DoHtmlEncode(stockInfo);
return dal.Update(stockInfo);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -