You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
DS7/DSWeb/Areas/MvcShipping/Helper/Repository/ModelObjectRepository.cs

271 lines
9.4 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using System;
using System.Web;
using DSWeb.MvcShipping.Comm.Cookie;
using HcUtility.Comm;
using HcUtility.Core;
using System.Collections.Generic;
namespace DSWeb.MvcShipping.Helper.Repository
{
/// wuwei 2011-01-25 CMP-8856 中石化:webpos保存数据报错导致数据保存重复的问题
public class ModelObjectRepository
{
public HttpRequestBase Request { get; set; }
public DBResult Save(ModelObjectBillHead headdata, List<ModelObjectBase> bodylist, List<ModelObjectBase> bodylistDel)
{
return Save(headdata, bodylist, bodylistDel, null, null);
}
public DBResult Save(ModelObjectBillHead headdata, List<ModelObjectBase> bodylist1, List<ModelObjectBase> bodylistDel1
, List<ModelObjectBase> bodylist2, List<ModelObjectBase> bodylistDel2)
{
DBResult result = null;
try
{
result = HandleHeadData(headdata);
if (!result.Success)
return result;
AddBodyToHead(headdata, bodylist1, bodylistDel1);
AddBodyToHead(headdata, bodylist2, bodylistDel2);
result = Save(headdata);
return result;
}
catch (Exception e)
{
if(result==null)
result=new DBResult();
result.Success = false;
result.Message = e.Message;
return result;
}
}
public DBResult Save(ModelObjectBillHead headdata, List<ModelObjectBase> bodylist1, List<ModelObjectBase> bodylistDel1
, List<ModelObjectBase> bodylist2, List<ModelObjectBase> bodylistDel2, List<ModelObjectBase> bodylist3, List<ModelObjectBase> bodylistDel3)
{
DBResult result = null;
try
{
result = HandleHeadData(headdata);
if (!result.Success)
return result;
AddBodyToHead(headdata, bodylist1, bodylistDel1);
AddBodyToHead(headdata, bodylist2, bodylistDel2);
AddBodyToHead(headdata, bodylist3, bodylistDel3);
result = Save(headdata);
return result;
}
catch (Exception e)
{
if (result == null)
result = new DBResult();
result.Success = false;
result.Message = e.Message;
return result;
}
}
//4个子表
public DBResult Save(ModelObjectBillHead headdata,
List<ModelObjectBase> bodylist1, List<ModelObjectBase> bodylistDel1,
List<ModelObjectBase> bodylist2, List<ModelObjectBase> bodylistDel2,
List<ModelObjectBase> bodylist3, List<ModelObjectBase> bodylistDel3,
List<ModelObjectBase> bodylist4, List<ModelObjectBase> bodylistDel4
)
{
DBResult result = null;
try
{
result = HandleHeadData(headdata);
if (!result.Success)
return result;
AddBodyToHead(headdata, bodylist1, bodylistDel1);
AddBodyToHead(headdata, bodylist2, bodylistDel2);
AddBodyToHead(headdata, bodylist3, bodylistDel3);
AddBodyToHead(headdata, bodylist4, bodylistDel4);
result = Save(headdata);
return result;
}
catch (Exception e)
{
if (result == null)
result = new DBResult();
result.Success = false;
result.Message = e.Message;
return result;
}
}
//5
public DBResult Save(ModelObjectBillHead headdata,
List<ModelObjectBase> bodylist1, List<ModelObjectBase> bodylistDel1,
List<ModelObjectBase> bodylist2, List<ModelObjectBase> bodylistDel2,
List<ModelObjectBase> bodylist3, List<ModelObjectBase> bodylistDel3,
List<ModelObjectBase> bodylist4, List<ModelObjectBase> bodylistDel4,
List<ModelObjectBase> bodylist5, List<ModelObjectBase> bodylistDel5
)
{
DBResult result = null;
try
{
result = HandleHeadData(headdata);
if (!result.Success)
return result;
AddBodyToHead(headdata, bodylist1, bodylistDel1);
AddBodyToHead(headdata, bodylist2, bodylistDel2);
AddBodyToHead(headdata, bodylist3, bodylistDel3);
AddBodyToHead(headdata, bodylist4, bodylistDel4);
AddBodyToHead(headdata, bodylist5, bodylistDel5);
result = Save(headdata);
return result;
}
catch (Exception e)
{
if (result == null)
result = new DBResult();
result.Success = false;
result.Message = e.Message;
return result;
}
}
public DBResult Save(ModelObjectBase data)
{
HanderDataCookie(data);
List<ModelObjectBase> list = new List<ModelObjectBase>();
list.Add(data);
return Save(list);
}
public DBResult Save(List<ModelObjectBase> dataList)
{
ModelObjectDBBill dbBill = new ModelObjectDBBill();
foreach (ModelObjectBase mob in dataList)
{
HanderDataCookie(mob);
}
return dbBill.Save(dataList);
}
public DBResult SaveComm(List<ModelObjectBase> dataList)
{
var dbModel = new ModelObjectDB();
foreach (ModelObjectBase mob in dataList)
{
HanderDataCookie(mob);
}
return dbModel.Save(dataList);
}
#region Private Function
private void HanderDataCookie(ModelObjectBase data)
{
if (Request != null)
{
if (data is ModelObjectBillHead)
{
ModelObjectBillHead headdata = (ModelObjectBillHead)data;
// headdata.LoginUserID = CookieConfig.GetCookie_UserId(Request);
headdata.LoginUserCode = CookieConfig.GetCookie_UserCode(Request);
headdata.LoginUserName = CookieConfig.GetCookie_UserName(Request);
}
}
}
private DBResult HandleHeadData(ModelObjectBillHead headdata)
{
var result = new DBResult();
string headBillno = headdata.GetBillNoValue().ToString();
if(String.IsNullOrEmpty(headBillno)||headBillno=="*")
{
result.Success = false;
result.Message = "单据没有相应的单据号,不允许保存";
return result;
}
if (headdata.ModelUIStatus == "0")
{
result.Success = false;
result.Message = "数据为浏览状态不允许保存!";
return result;
}
if(headdata.ModelUIStatus=="I")
{
headdata.DbOperationType = DbOperationType.DbotIns;
}
else if(headdata.ModelUIStatus=="E")
{
headdata.DbOperationType = DbOperationType.DbotUpd;
}
else
{
headdata.DbOperationType = DbOperationType.DbotDel;
}
result.Success = true;
result.Message = "处理主表数据成功";
return result;
}
private void AddBodyToHead(ModelObjectBillHead headdata, List<ModelObjectBase> bodylist, List<ModelObjectBase> bodylistDel)
{
List<ModelObjectBase> bodyListAll = new List<ModelObjectBase>();
//更加billno是否为空置更新或新增标志.
if (bodylist != null)
{
foreach (ModelObjectBillBody modbody in bodylist)
{
string bodyBillNo = modbody.GetBillNoValue().ToString();
if (bodyBillNo == String.Empty || bodyBillNo == "*")
modbody.DbOperationType = DbOperationType.DbotIns;
else
modbody.DbOperationType = DbOperationType.DbotUpd;
}
bodyListAll.AddRange(bodylist);
}
//置删除标志
if (bodylistDel != null)
{
foreach (ModelObjectBillBody modbodydel in bodylistDel)
{
modbodydel.DbOperationType = DbOperationType.DbotDel;
}
bodyListAll.AddRange(bodylistDel);
}
if (bodyListAll.Count > 0)
headdata.BodyList.Add(bodyListAll);
}
#endregion
}
public class ModelHeadConvert<T> where T : ModelObjectBillHead
{
private static ModelObjectBillHead Converter ( T inputObject )
{
return inputObject;
}
public static List<ModelObjectBillHead> ToModelObjectList ( List<T> objList )
{
if (objList == null)
return null;
return objList.ConvertAll<ModelObjectBillHead>(new Converter<T, ModelObjectBillHead>(Converter));
}
}
}