ZhiYeJianKang_PeiXun/Song.ServiceImpls/Contents/ProductCom.cs

297 lines
12 KiB
C#
Raw Normal View History

2025-02-20 15:41:53 +08:00
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.Common;
using WeiSha.Common;
using Song.Entities;
using WeiSha.Data;
using Song.ServiceInterfaces;
using System.Resources;
using System.Reflection;
namespace Song.ServiceImpls
{
public partial class ContentsCom : IContents
{
public int ProductAdd(Product entity)
{
//<2F><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
entity.Pd_CrtTime = DateTime.Now;
Song.Entities.Columns nc = Business.Do<IColumns>().Single((int)entity.Col_Id);
if (nc != null) entity.Col_Name = nc.Col_Name;
//<2F><><EFBFBD>Ӷ<EFBFBD><D3B6>󣬲<EFBFBD><F3A3ACB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
object obj = Gateway.Default.Max<Product>(Product._.Pd_Tax, Product._.Col_Id == entity.Col_Id);
entity.Pd_Tax = obj is int ? (int)obj + 1 : 0;
//<2F><><EFBFBD>ڻ<EFBFBD><DABB><EFBFBD>
Song.Entities.Organization org = Business.Do<IOrganization>().OrganCurrent();
if (org != null)
{
entity.Org_ID = org.Org_ID;
entity.Org_Name = org.Org_Name;
}
return Gateway.Default.Save<Product>(entity);
}
public void ProductSave(Product entity)
{
Song.Entities.Columns nc = Business.Do<IColumns>().Single((int)entity.Col_Id);
if (nc != null) entity.Col_Name = nc.Col_Name;
using (DbTrans tran = Gateway.Default.BeginTrans())
{
try
{
tran.Save<Product>(entity);
//<2F><><EFBFBD><EFBFBD><EFBFBD>IJ<EFBFBD>Ʒ<EFBFBD><C6B7>Ϣʱ<CFA2><CAB1>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD><EFBFBD>IJ<EFBFBD>Ʒ<EFBFBD><C6B7><EFBFBD>ԵIJ<D4B5>Ʒ<EFBFBD><C6B7><EFBFBD><EFBFBD>
tran.Update<ProductMessage>(new Field[] { ProductMessage._.Pd_Name }, new object[] { entity.Pd_Name }, ProductMessage._.Pd_Id == entity.Pd_Id);
tran.Commit();
}
catch (Exception ex)
{
tran.Rollback();
throw ex;
}
finally
{
tran.Close();
}
}
}
public bool ProductUp(int orgid, int id)
{
//<2F><>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>
Product current = Gateway.Default.From<Product>().Where(Product._.Pd_Id == id).ToFirst<Product>();
int tax = (int)current.Pd_Tax;
//<2F><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>󣬼<EFBFBD><F3A3ACBC>ֳ<EFBFBD><D6B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֳ<EFBFBD><D6B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֱ<EFBFBD>ӷ<EFBFBD><D3B7><EFBFBD>false;
Product prev = Gateway.Default.From<Product>()
.Where(Product._.Pd_Tax < tax && Product._.Col_Id == current.Col_Id && Product._.Org_ID == orgid)
.OrderBy(Product._.Pd_Tax.Desc).ToFirst<Product>();
if (prev == null) return false;
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
current.Pd_Tax = prev.Pd_Tax;
prev.Pd_Tax = tax;
using (DbTrans tran = Gateway.Default.BeginTrans())
{
try
{
tran.Save<Product>(current);
tran.Save<Product>(prev);
tran.Commit();
return true;
}
catch
{
tran.Rollback();
throw;
}
finally
{
tran.Close();
}
}
}
public bool ProductDown(int orgid, int id)
{
//<2F><>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>
Product current = Gateway.Default.From<Product>().Where(Product._.Pd_Id == id).ToFirst<Product>();
int tax = (int)current.Pd_Tax;
//<2F><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>󣬼<EFBFBD><F3A3ACBC>ܵܶ<DCB5><DCB6>󣻵ܵܲ<DCB5><DCB2><EFBFBD><EFBFBD><EFBFBD>ֱ<EFBFBD>ӷ<EFBFBD><D3B7><EFBFBD>false;
Product next = Gateway.Default.From<Product>()
.Where(Product._.Pd_Tax > tax && Product._.Col_Id == current.Col_Id && Product._.Org_ID == orgid)
.OrderBy(Product._.Pd_Tax.Asc).ToFirst<Product>();
if (next == null) return false;
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
current.Pd_Tax = next.Pd_Tax;
next.Pd_Tax = tax;
using (DbTrans tran = Gateway.Default.BeginTrans())
{
try
{
tran.Save<Product>(current);
tran.Save<Product>(next);
tran.Commit();
return true;
}
catch
{
tran.Rollback();
throw;
}
finally
{
tran.Close();
}
}
}
public int ProductNumber(int id, int addNum)
{
object obj = Gateway.Default.Max<Product>(Product._.Pd_Number, Product._.Pd_Id == id);
int i = obj is int ? (int)obj : 0;
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӣ<EFBFBD><D3A3><EFBFBD>ֱ<EFBFBD>ӷ<EFBFBD><D3B7>ص<EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (addNum < 1) return i;
//<2F><><EFBFBD>Ӽ<EFBFBD><D3BC><EFBFBD>
i += addNum;
Gateway.Default.Update<Product>(new Field[] { Product._.Pd_Number }, new object[] { i }, Product._.Pd_Id == id);
return i;
}
public void ProductDelete(int identify)
{
Song.Entities.Product entity = this.ProductSingle(identify);
using (DbTrans tran = Gateway.Default.BeginTrans())
{
try
{
_ProductDelete(entity,tran);
tran.Commit();
}
catch (Exception ex)
{
tran.Rollback();
throw ex;
}
finally
{
tran.Close();
}
}
}
/// <summary>
/// <20><><EFBFBD><EFBFBD>ɾ<EFBFBD><C9BE>
/// </summary>
/// <param name="orgid"><3E><><EFBFBD><EFBFBD>id</param>
/// <param name="colid"><3E><>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD>id</param>
public void ProductDeleteAll(int orgid, int colid)
{
WhereClip wc = new WhereClip();
if (orgid > 0) wc.And(Product._.Org_ID == orgid);
if (colid > 0) wc.And(Product._.Col_Id == colid);
Song.Entities.Product[] entities = Gateway.Default.From<Product>().Where(wc).ToArray<Product>();
DbTrans tran = Gateway.Default.BeginTrans();
foreach (Song.Entities.Product entity in entities)
{
_ProductDelete(entity, tran);
}
}
/// <summary>
/// ɾ<><C9BE>
/// </summary>
/// <param name="entity">ҵ<><D2B5>ʵ<EFBFBD><CAB5></param>
private void _ProductDelete(Product entity, DbTrans tran)
{
//ɾ<><C9BE><EFBFBD><EFBFBD>Ʒ<EFBFBD><C6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
tran.Delete<ProductMessage>(ProductMessage._.Pd_Id == entity.Pd_Id);
// ɾ<><C9BE><EFBFBD><EFBFBD>ƷͼƬ
//Song.Entities.ProductPicture[] pps = this.PictureAll(entity.Pd_Id, null);
//foreach (ProductPicture p in pps)
//{
// this._PictureDelete(p);
//}
//ɾ<><C9BE><EFBFBD><EFBFBD>Ʒ<EFBFBD><C6B7><EFBFBD><EFBFBD>Ϣ
string resPath = WeiSha.Common.Upload.Get["Product"].Physics;
WeiSha.WebControl.FileUpload.Delete("Product", entity.Pd_Logo);
//ɾ<><C9BE><EFBFBD><EFBFBD>ά<EFBFBD><CEAC><EFBFBD>ļ<EFBFBD>
if (System.IO.File.Exists(resPath + entity.Pd_QrCode))
{
System.IO.File.Delete(resPath + entity.Pd_QrCode);
}
tran.Delete<Product>(Product._.Pd_Id == entity.Pd_Id);
}
public void ProductIsDelete(int identify)
{
Gateway.Default.Update<Product>(new Field[] { Product._.Pd_IsDel }, new object[] { true }, Product._.Pd_Id == identify);
}
public void ProductRecover(int identify)
{
Gateway.Default.Update<Product>(new Field[] { Product._.Pd_IsDel }, new object[] { false }, Product._.Pd_Id == identify);
}
public Product ProductSingle(int identify)
{
return Gateway.Default.From<Product>().Where(Product._.Pd_Id == identify).ToFirst<Product>();
}
public Product ProductSingle(string uid)
{
return Gateway.Default.From<Product>().Where(Product._.Pd_Uid == uid).ToFirst<Product>();
}
public Product[] ProductPager(int orgid, int? colid, int size, int index, out int countSum)
{
WhereClip wc = Product._.Pd_IsDel == false;
if (orgid > 0) wc.And(Product._.Org_ID == orgid);
if (colid != null && colid > 0) wc.And(Product._.Col_Id == colid);
countSum = Gateway.Default.Count<Product>(wc);
return Gateway.Default.From<Product>().Where(wc).OrderBy(Product._.Pd_Tax.Asc).ToArray<Product>(size, (index - 1) * size);
}
public Product[] ProductPager(int orgid, int? colid, string searTxt, bool? isDel, int size, int index, out int countSum)
{
WhereClip wc = new WhereClip();
if (orgid > 0) wc.And(Product._.Org_ID == orgid);
if (colid != null && colid > 0) wc.And(Product._.Col_Id == colid);
if (isDel != null) wc.And(Product._.Pd_IsDel == (bool)isDel);
if (searTxt != null && searTxt.Trim() != "")
wc.And(Product._.Pd_Name.Like("%" + searTxt + "%"));
countSum = Gateway.Default.Count<Product>(wc);
return Gateway.Default.From<Product>().Where(wc).OrderBy(Product._.Pd_Tax.Asc).ToArray<Product>(size, (index - 1) * size);
}
public Product[] ProductPager(int orgid, int? colid, string searTxt, bool? isDel, bool? isUse, bool? isNew, bool? isRec, string type, int size, int index, out int countSum)
{
WhereClip wc = new WhereClip();
if (orgid > 0) wc.And(Product._.Org_ID == orgid);
if (colid != null && colid > 0) wc.And(Product._.Col_Id == colid);
if (isDel != null) wc.And(Product._.Pd_IsDel == (bool)isDel);
if (isUse != null) wc.And(Product._.Pd_IsUse == (bool)isUse);
if (isNew != null && isNew != false) wc.And(Product._.Pd_IsNew == (bool)isNew);
if (isRec != null && isRec != false) wc.And(Product._.Pd_IsRec == (bool)isRec);
if (searTxt != null && searTxt.Trim() != "")
wc.And(Product._.Pd_Name.Like("%" + searTxt + "%"));
countSum = Gateway.Default.Count<Product>(wc);
type = type.ToLower();
if (type == "new")
{
return Gateway.Default.From<Product>().Where(wc).OrderBy(Product._.Pd_IsNew.Asc && Product._.Pd_Tax.Asc).ToArray<Product>(size, (index - 1) * size);
}
if (type == "hot")
{
return Gateway.Default.From<Product>().Where(wc).OrderBy(Product._.Pd_Number.Desc && Product._.Pd_Tax.Asc).ToArray<Product>(size, (index - 1) * size);
}
if (type == "rec")
{
return Gateway.Default.From<Product>().Where(wc).OrderBy(Product._.Pd_IsRec.Desc && Product._.Pd_Tax.Asc).ToArray<Product>(size, (index - 1) * size);
}
return Gateway.Default.From<Product>().Where(wc).OrderBy(Product._.Pd_Tax.Asc).ToArray<Product>(size, (index - 1) * size);
}
public Product[] ProductCount(int orgid, int? colid, int count, bool? isDel, bool? isUse, string type)
{
WhereClip wc = new WhereClip();
if (orgid > 0) wc.And(Product._.Org_ID == orgid);
if (colid != null && colid > 0) wc.And(Product._.Col_Id == colid);
if (isDel != null) wc.And(Product._.Pd_IsDel == isDel);
if (isUse != null) wc.And(Product._.Pd_IsUse == isUse);
type = type.ToLower();
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ
OrderByClip order = Product._.Pd_Tax.Asc;
if (type == "new")
{
order = Product._.Pd_IsNew.Asc;
wc.And(Product._.Pd_IsNew == true);
}
if (type == "hot") order = Product._.Pd_Number.Desc;
if (type == "rec") order = Product._.Pd_IsRec.Asc;
if (type == "flux") order = Product._.Pd_Number.Desc;
//ȡ<><C8A1>Ʒ<EFBFBD><C6B7><EFBFBD><EFBFBD>
return Gateway.Default.From<Product>().Where(wc).OrderBy(order && Product._.Pd_PushTime.Desc && Product._.Pd_Tax.Asc).ToArray<Product>(count);
}
}
}