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.

700 lines
28 KiB
C#

using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using DSWeb.MvcShipping.Models.InfoSaleProfitSharePlan;
using DSWeb.MvcShipping.Models.InfoSaleProfitShareSet;
using Microsoft.Practices.EnterpriseLibrary.Data;
using DSWeb.Areas.CommMng.Models;
using HcUtility.Comm;
using DSWeb.TruckMng.Comm.Cookie;
using DSWeb.EntityDA;
namespace DSWeb.MvcShipping.DAL.MsInfoSaleProfitShareSet
{
public class MsInfoSaleProfitShareSetDAL
{
#region 方案
static public List<InfoSaleProfitSharePlan> GetDataList(string strCondition, string companyid, string sort = null)
{
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append("GID,PLANNAME,ISSTOPMONTH,POORDAY,MONTHPOORDAY,COMPANYID,REMARKS,CREATEUSER,CREATETIME");
strSql.Append(" from info_sale_profitShare where COMPANYID='" + companyid + "'");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else {
strSql.Append(" order by CREATETIME DESC");
}
return SetData(strSql);
}
static public InfoSaleProfitSharePlan GetData(string condition, string companyid)
{
InfoSaleProfitSharePlan data = null;
var list = GetDataList(condition,companyid);
if (list.Count > 0)
data = list[0];
if (data == null)
{
data = new InfoSaleProfitSharePlan();
}
return data;
}
private static List<InfoSaleProfitSharePlan> SetData(StringBuilder strSql)
{
var headList = new List<InfoSaleProfitSharePlan>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
InfoSaleProfitSharePlan data = new InfoSaleProfitSharePlan();
#region Set DB data to Object
data.GID = Convert.ToString(reader["GID"]);
data.PLANNAME = Convert.ToString(reader["PLANNAME"]);
data.ISSTOPMONTH = Convert.ToInt16(reader["ISSTOPMONTH"]);
data.POORDAY = Convert.ToInt32(reader["POORDAY"]);
if (reader["MONTHPOORDAY"] != DBNull.Value)
data.MONTHPOORDAY = Convert.ToInt32(reader["MONTHPOORDAY"]);
data.COMPANYID = Convert.ToString(reader["COMPANYID"]);
data.REMARKS = Convert.ToString(reader["REMARKS"]);
data.CREATEUSER = Convert.ToString(reader["CREATEUSER"]);
if (reader["CREATETIME"] != DBNull.Value)
data.CREATETIME = Convert.ToDateTime(reader["CREATETIME"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
public static DBResult DeleteDetail(InfoSaleProfitSharePlan headData)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmd = db.GetSqlStringCommand("delete from info_sale_profitShare where GID='" + headData.GID + "'");
db.ExecuteNonQuery(cmd, tran);
var cmdDelete = db.GetSqlStringCommand("delete from info_sale_profitShareDetail where PLANID='" + headData.GID + "'");
db.ExecuteNonQuery(cmdDelete, tran);
var cmdDeletework = db.GetSqlStringCommand("delete from info_sale_profitShareLx where PLANID='" + headData.GID + "'");
db.ExecuteNonQuery(cmdDeletework, tran);
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "保存出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "保存成功";
return result;
}
#endregion
#region 方案明细
static public List<InfoSaleProfitShareDetail> GetSaleProfitDetailDataList(string strCondition,string sort = null)
{
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append("d.*,s.SALEID,s.SALE,i.POORDAY,i.MONTHPOORDAY,s.PROFITPLAN from info_sale_profitShareDetail d");
strSql.Append(" left join info_sale_profitShareSet s on (s.PLANID=d.PLANID) ");
strSql.Append(" left join info_sale_profitShare i on (i.GID=d.PLANID) ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition);
}
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by d.MONTHNUM,d.PROFITDOWN");
}
return SetSaleProfitDetailData(strSql);
}
private static List<InfoSaleProfitShareDetail> SetSaleProfitDetailData(StringBuilder strSql)
{
var headList = new List<InfoSaleProfitShareDetail>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
InfoSaleProfitShareDetail data = new InfoSaleProfitShareDetail();
#region Set DB data to Object
data.GID = Convert.ToString(reader["GID"]);
data.PLANID = Convert.ToString(reader["PLANID"]);
data.MONTHNUM = Convert.ToInt16(reader["MONTHNUM"]);
data.PROFITDOWN = Convert.ToDecimal(reader["PROFITDOWN"]);
data.PROFITUP = Convert.ToDecimal(reader["PROFITUP"]);
data.SHAREPR = Convert.ToDecimal(reader["SHAREPR"]);
if (reader["BEFORESHAREPR"] != DBNull.Value)
data.BEFORESHAREPR = Convert.ToDecimal(reader["BEFORESHAREPR"]);
data.REMARKS = Convert.ToString(reader["REMARKS"]);
data.SALEID = Convert.ToString(reader["SALEID"]);
data.SALE = Convert.ToString(reader["SALE"]);
data.BSSOURCE = Convert.ToString(reader["BSSOURCE"]);
if (reader["POORDAY"] != DBNull.Value)
data.POORDAY = Convert.ToInt32(reader["POORDAY"]);
if (reader["MONTHPOORDAY"] != DBNull.Value)
data.MONTHPOORDAY = Convert.ToInt32(reader["MONTHPOORDAY"]);
if (reader["PROFITPLAN"] != DBNull.Value)
data.PROFITPLAN = Convert.ToDecimal(reader["PROFITPLAN"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
public static DBResult SaveDetail(List<InfoSaleProfitShareDetail> bodyList, string planid)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmdInsert =
db.GetSqlStringCommand(
@"insert into info_sale_profitShareDetail (GID,PLANID,MONTHNUM,PROFITDOWN,PROFITUP,SHAREPR,BEFORESHAREPR,REMARKS,BSSOURCE)
values (@GID,@PLANID,@MONTHNUM,@PROFITDOWN,@PROFITUP,@SHAREPR,@BEFORESHAREPR,@REMARKS,@BSSOURCE) ");
var cmdUpdate =
db.GetSqlStringCommand(
@"update info_sale_profitShareDetail set MONTHNUM=@MONTHNUM,PROFITDOWN=@PROFITDOWN,PROFITUP=@PROFITUP,SHAREPR=@SHAREPR,BEFORESHAREPR=@BEFORESHAREPR,REMARKS=@REMARKS,BSSOURCE=@BSSOURCE where GID=@GID ");
if (bodyList != null)
{
foreach (var enumValue in bodyList)
{
if (enumValue.PLANID == "*" || enumValue.PLANID == "")
{
cmdInsert.Parameters.Clear();
db.AddInParameter(cmdInsert, "@GID", DbType.String, Guid.NewGuid().ToString());
db.AddInParameter(cmdInsert, "@PLANID", DbType.String, planid);
db.AddInParameter(cmdInsert, "@MONTHNUM", DbType.Int16, enumValue.MONTHNUM);
db.AddInParameter(cmdInsert, "@PROFITDOWN", DbType.Decimal, enumValue.PROFITDOWN);
db.AddInParameter(cmdInsert, "@PROFITUP", DbType.Decimal, enumValue.PROFITUP);
db.AddInParameter(cmdInsert, "@SHAREPR", DbType.Decimal, enumValue.SHAREPR);
db.AddInParameter(cmdInsert, "@BEFORESHAREPR", DbType.Decimal, enumValue.BEFORESHAREPR);
db.AddInParameter(cmdInsert, "@REMARKS", DbType.String, enumValue.REMARKS);
db.AddInParameter(cmdInsert, "@BSSOURCE", DbType.String, enumValue.BSSOURCE);
db.ExecuteNonQuery(cmdInsert, tran);
}
else
{
cmdUpdate.Parameters.Clear();
db.AddInParameter(cmdUpdate, "@GID", DbType.String, enumValue.GID);
db.AddInParameter(cmdUpdate, "@MONTHNUM", DbType.Int16, enumValue.MONTHNUM);
db.AddInParameter(cmdUpdate, "@PROFITDOWN", DbType.Decimal, enumValue.PROFITDOWN);
db.AddInParameter(cmdUpdate, "@PROFITUP", DbType.Decimal, enumValue.PROFITUP);
db.AddInParameter(cmdUpdate, "@SHAREPR", DbType.Decimal, enumValue.SHAREPR);
db.AddInParameter(cmdUpdate, "@BEFORESHAREPR", DbType.Decimal, enumValue.BEFORESHAREPR);
db.AddInParameter(cmdUpdate, "@REMARKS", DbType.String, enumValue.REMARKS);
db.AddInParameter(cmdUpdate, "@BSSOURCE", DbType.String, enumValue.BSSOURCE);
db.ExecuteNonQuery(cmdUpdate, tran);
}
}
}
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "保存出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "保存成功" + result.Message;
return result;
}
#endregion
#region 利息设置
static public List<InfoSaleProfitShareLx> GetSaleProfitLxDataList(string strCondition, string sort = null)
{
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append("GID,PLANID,BDAY,EDAY,DEDUCTIN,REMARKS from info_sale_profitShareLx ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition);
}
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by BDAY");
}
return SetSaleProfitLxData(strSql);
}
private static List<InfoSaleProfitShareLx> SetSaleProfitLxData(StringBuilder strSql)
{
var headList = new List<InfoSaleProfitShareLx>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
InfoSaleProfitShareLx data = new InfoSaleProfitShareLx();
#region Set DB data to Object
data.GID = Convert.ToString(reader["GID"]);
data.PLANID = Convert.ToString(reader["PLANID"]);
data.BDAY = Convert.ToInt16(reader["BDAY"]);
data.EDAY = Convert.ToInt16(reader["EDAY"]);
data.DEDUCTIN = Convert.ToDecimal(reader["DEDUCTIN"]);
data.REMARKS = Convert.ToString(reader["REMARKS"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
public static DBResult SaveLxDetail(List<InfoSaleProfitShareLx> bodyList, string planid)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmdDelete =
db.GetSqlStringCommand(
@"delete from info_sale_profitShareLx where PLANID=@PLANID ");
var cmdInsert =
db.GetSqlStringCommand(
@"insert into info_sale_profitShareLx (GID,PLANID,BDAY,EDAY,DEDUCTIN,REMARKS)
values (@GID,@PLANID,@BDAY,@EDAY,@DEDUCTIN,@REMARKS) ");
if (bodyList != null)
{
cmdDelete.Parameters.Clear();
db.AddInParameter(cmdDelete, "@PLANID", DbType.String, bodyList[0].PLANID);
db.ExecuteNonQuery(cmdDelete, tran);
foreach (var enumValue in bodyList)
{
cmdInsert.Parameters.Clear();
db.AddInParameter(cmdInsert, "@GID", DbType.String, Guid.NewGuid().ToString());
db.AddInParameter(cmdInsert, "@PLANID", DbType.String, planid);
db.AddInParameter(cmdInsert, "@BDAY", DbType.Int16, enumValue.BDAY);
db.AddInParameter(cmdInsert, "@EDAY", DbType.Int16, enumValue.EDAY);
db.AddInParameter(cmdInsert, "@DEDUCTIN", DbType.Decimal, enumValue.DEDUCTIN);
db.AddInParameter(cmdInsert, "@REMARKS", DbType.String, enumValue.REMARKS);
db.ExecuteNonQuery(cmdInsert, tran);
}
}
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "保存出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "保存成功" + result.Message;
return result;
}
#endregion
#region 超期设置
static public List<InfoSaleProfitShareLx> GetSaleProfitCqDataList(string strCondition, string sort = null)
{
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append("d.GID,d.PLANID,d.BDAY,d.EDAY,d.DEDUCTIN,d.REMARKS,s.SALEID,s.SALE from info_sale_profitShareCq d");
strSql.Append(" left join info_sale_profitShareSet s on (s.PLANID=d.PLANID) ");
strSql.Append(" left join info_sale_profitShare i on (i.GID=d.PLANID) ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition);
}
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by d.BDAY");
}
return SetSaleProfitCqData(strSql);
}
private static List<InfoSaleProfitShareLx> SetSaleProfitCqData(StringBuilder strSql)
{
var headList = new List<InfoSaleProfitShareLx>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
InfoSaleProfitShareLx data = new InfoSaleProfitShareLx();
#region Set DB data to Object
data.GID = Convert.ToString(reader["GID"]);
data.PLANID = Convert.ToString(reader["PLANID"]);
data.BDAY = Convert.ToInt16(reader["BDAY"]);
data.EDAY = Convert.ToInt16(reader["EDAY"]);
data.DEDUCTIN = Convert.ToDecimal(reader["DEDUCTIN"]);
data.REMARKS = Convert.ToString(reader["REMARKS"]);
data.SALEID = Convert.ToString(reader["SALEID"]);
data.SALE = Convert.ToString(reader["SALE"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
public static DBResult SaveCqDetail(List<InfoSaleProfitShareCq> bodyList, string planid)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmdDelete =
db.GetSqlStringCommand(
@"delete from info_sale_profitShareCq where PLANID=@PLANID ");
var cmdInsert =
db.GetSqlStringCommand(
@"insert into info_sale_profitShareCq (GID,PLANID,BDAY,EDAY,DEDUCTIN,REMARKS)
values (@GID,@PLANID,@BDAY,@EDAY,@DEDUCTIN,@REMARKS) ");
if (bodyList != null)
{
cmdDelete.Parameters.Clear();
db.AddInParameter(cmdDelete, "@PLANID", DbType.String, bodyList[0].PLANID);
db.ExecuteNonQuery(cmdDelete, tran);
foreach (var enumValue in bodyList)
{
cmdInsert.Parameters.Clear();
db.AddInParameter(cmdInsert, "@GID", DbType.String, Guid.NewGuid().ToString());
db.AddInParameter(cmdInsert, "@PLANID", DbType.String, planid);
db.AddInParameter(cmdInsert, "@BDAY", DbType.Int16, enumValue.BDAY);
db.AddInParameter(cmdInsert, "@EDAY", DbType.Int16, enumValue.EDAY);
db.AddInParameter(cmdInsert, "@DEDUCTIN", DbType.Decimal, enumValue.DEDUCTIN);
db.AddInParameter(cmdInsert, "@REMARKS", DbType.String, enumValue.REMARKS);
db.ExecuteNonQuery(cmdInsert, tran);
}
}
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "保存出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "保存成功" + result.Message;
return result;
}
#endregion
#region InfoSaleProfitShareSet
static public List<InfoSaleProfitShareSet> GetSaleProfitSetDataList(string strCondition, string companyid, string sort = null)
{
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append("GID,PLANID,SALEID,SALE,COMPANYID,CREATEUSER,CREATETIME,REMARKS,(SELECT PLANNAME FROM info_sale_profitShare WHERE GID=info_sale_profitShareSet.PLANID) PLANREF,PROFITPLAN from info_sale_profitShareSet ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition);
}
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by CREATETIME DESC");
}
return SetSaleProfitSetData(strSql);
}
static public InfoSaleProfitShareSet GetSaleProfitSetData(string condition, string companyid)
{
InfoSaleProfitShareSet data = null;
var list = GetSaleProfitSetDataList(condition, companyid);
if (list.Count > 0)
data = list[0];
if (data == null)
{
data = new InfoSaleProfitShareSet();
}
return data;
}
private static List<InfoSaleProfitShareSet> SetSaleProfitSetData(StringBuilder strSql)
{
var headList = new List<InfoSaleProfitShareSet>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
InfoSaleProfitShareSet data = new InfoSaleProfitShareSet();
#region Set DB data to Object
data.GID = Convert.ToString(reader["GID"]);
data.PLANID = Convert.ToString(reader["PLANID"]);
data.PLANREF = Convert.ToString(reader["PLANREF"]);
data.SALE = Convert.ToString(reader["SALE"]);
data.SALEID = Convert.ToString(reader["SALEID"]);
data.COMPANYID = Convert.ToString(reader["COMPANYID"]);
data.REMARKS = Convert.ToString(reader["REMARKS"]);
data.CREATEUSER = Convert.ToString(reader["CREATEUSER"]);
if (reader["CREATETIME"] != DBNull.Value)
data.CREATETIME = Convert.ToDateTime(reader["CREATETIME"]);
if (reader["PROFITPLAN"] != DBNull.Value)
data.PROFITPLAN = Convert.ToDecimal(reader["PROFITPLAN"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
public static DBResult SaveSaleProfitSet(List<InfoSaleProfitShareSet> bodyList, string companyid,string userid)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmdInsert =
db.GetSqlStringCommand(
@"insert into info_sale_profitShareSet (GID,PLANID,SALE,SALEID,COMPANYID,REMARKS,CREATEUSER,CREATETIME,PROFITPLAN)
values (@GID,@PLANID,@SALE,@SALEID,@COMPANYID,@REMARKS,@CREATEUSER,@CREATETIME,@PROFITPLAN) ");
var cmdUpdate =
db.GetSqlStringCommand(
@"update info_sale_profitShareSet set PLANID=@PLANID,SALE=@SALE,SALEID=@SALEID,REMARKS=@REMARKS,PROFITPLAN=@PROFITPLAN where GID=@GID ");
if (bodyList != null)
{
foreach (var enumValue in bodyList)
{
if (enumValue.GID == "*" || enumValue.GID == "")
{
cmdInsert.Parameters.Clear();
db.AddInParameter(cmdInsert, "@GID", DbType.String, Guid.NewGuid().ToString());
db.AddInParameter(cmdInsert, "@PLANID", DbType.String, enumValue.PLANID);
db.AddInParameter(cmdInsert, "@SALE", DbType.String, enumValue.SALE);
db.AddInParameter(cmdInsert, "@SALEID", DbType.String, enumValue.SALEID);
db.AddInParameter(cmdInsert, "@COMPANYID", DbType.String, companyid);
db.AddInParameter(cmdInsert, "@REMARKS", DbType.String, enumValue.REMARKS);
db.AddInParameter(cmdInsert, "@CREATEUSER", DbType.String, userid);
db.AddInParameter(cmdInsert, "@CREATETIME", DbType.String, DateTime.Now.ToString("yyyy-MM-dd"));
db.AddInParameter(cmdInsert, "@PROFITPLAN", DbType.Decimal, enumValue.PROFITPLAN);
db.ExecuteNonQuery(cmdInsert, tran);
}
else {
cmdUpdate.Parameters.Clear();
db.AddInParameter(cmdUpdate, "@GID", DbType.String, enumValue.GID);
db.AddInParameter(cmdUpdate, "@PLANID", DbType.String, enumValue.PLANID);
db.AddInParameter(cmdUpdate, "@SALE", DbType.String, enumValue.SALE);
db.AddInParameter(cmdUpdate, "@SALEID", DbType.String, enumValue.SALEID);
db.AddInParameter(cmdUpdate, "@REMARKS", DbType.String, enumValue.REMARKS);
db.AddInParameter(cmdUpdate, "@PROFITPLAN", DbType.Decimal, enumValue.PROFITPLAN);
db.ExecuteNonQuery(cmdUpdate, tran);
}
}
}
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "保存出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "保存成功" + result.Message;
return result;
}
#endregion
#region 参照部分
#endregion
}
}