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/Controllers/MsCwVouchersController.cs

631 lines
35 KiB
C#

This file contains invisible Unicode characters!

This file contains invisible Unicode characters that may be processed differently from what appears below. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to reveal hidden characters.

using System;
using System.Data;
using System.Linq;
using System.Web.Mvc;
using DSWeb.MvcShipping.DAL.MsCwVouchersDAL;
using DSWeb.MvcShipping.Models.MsCwVouchers;
using DSWeb.MvcShipping.Helper;
using DSWeb.MvcShipping.Comm.Cookie;
using HcUtility.Comm;
using HcUtility.Core;
using System.Collections.Generic;
using DSWeb.MvcShipping.DAL.MsBaseInfoDAL;
using DSWeb.EntityDA;
using DSWeb.Areas.CommMng.DAL;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data.SqlClient;
using DSWeb.SoftMng.Filter;
namespace DSWeb.MvcShipping.Controllers
{
[JsonRequestBehavior]
public class MsCwVouchersController : Controller
{
public ActionResult Index()
{
return View();
}
public ActionResult Edit()
{
return View();
}
#region 查询
[SqlKeyWordsFilter(Type = "Action")]//sql 防注入过滤器
public ContentResult GetDetailList(string condition)
{
var dataList = MsCwVouchersDAL.GetDetailList(condition, Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"]));
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = dataList.Count, data = dataList.ToList() });
return new ContentResult() { Content = json };
}
[SqlKeyWordsFilter(Type = "Action")]//sql 防注入过滤器
public ContentResult GetData(string handle, string condition)
{
MsCwVouchers head = null;
head = MsCwVouchersDAL.GetData(condition, Convert.ToString(Session["COMPANYID"]));
var json = JsonConvert.Serialize(
new { Success = true, Message = "查询成功", data = head });
return new ContentResult() { Content = json };
}
[SqlKeyWordsFilter(Type = "Action")]//sql 防注入过滤器
public ContentResult GetDataCwVVList(int start, int limit, string sort, string condition)
{
var dataList = MsCwVouchersDAL.GetDataCwVVList(condition, Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"]), sort);
var list = dataList.Skip(start).Take(limit);
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = dataList.Count, data = list.ToList() });
return new ContentResult() { Content = json };
}
#endregion
#region 合计列
[SqlKeyWordsFilter(Type = "Action")]//sql 防注入过滤器
public ContentResult GetDataListHJ(int start, int limit, string sort, string condition)
{
var dataList = MsCwVouchersDAL.GetDataListHJ(condition, Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"]), sort);
var list = dataList.Skip(start).Take(limit);
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = dataList.Count, data = list.ToList() });
return new ContentResult() { Content = json };
}
#endregion
#region 明细表保存
public ContentResult SaveEdit(string opstatus, string data, string body, string DelBody)//, string data_v
{
if (Convert.ToString(Session["COMPANYID"]).Trim() == "" || Convert.ToString(Session["USERID"]).Trim() == "" || Convert.ToString(Session["CODENAME"]).Trim() == "" || Convert.ToString(Session["SHOWNAME"]).Trim() == "" || Convert.ToString(Session["DEPTNAME"]).Trim() == "")
{
var jsonRespose2 = new JsonResponse { Success = false, Message = "登录超时,请退出系统重新登录!" };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose2) };
}
//
string strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(Convert.ToString(Session["USERID"]).Trim());
string strCwACCDATE = BasicDataRefDAL.GetCwACCDATE(Convert.ToString(Session["USERID"]).Trim());
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
//var headData_v = JsonConvert.Deserialize<MsCwVouchers>(data_v);
var headData = JsonConvert.Deserialize<MsCwVouchers>(data);
var bodyList = JsonConvert.Deserialize<List<MsCwVouitems>>(body);
var DelBodyList = JsonConvert.Deserialize<List<MsCwVouitems>>(DelBody);
string ORDNO = "";
string oldVOUALLNO = "";
var isPost = true;
var errorstr = "";
#region 默认值
//headData.VOUNO = "";//月初清零
//headData.VKNO = "";//凭证字
//headData.VOUDATE = "";//凭证日期
//headData.ATTACHS = "";//附件(单据)数
ORDNO = headData.ORDNO.ToString().Trim();
headData.ACCYEAR = DateTime.Parse(headData.VOUDATE.ToString()).Year.ToString();//年
headData.ACCMONTH = DateTime.Parse(headData.VOUDATE.ToString()).Month.ToString();//月
if (headData.ACCMONTH.ToString().Length == 1)
{
headData.ACCMONTH = "0" + headData.ACCMONTH.ToString();//月
}
headData.PREPARED = Convert.ToString(Session["SHOWNAME"]).Trim();//制单人
//
string strVOUNO = headData.VOUNO.ToString();
for (int i = 0; i < (4 - headData.VOUNO.ToString().Length); i++)
{
strVOUNO = "0" + strVOUNO;
}
headData.VOUNO = strVOUNO;//年+月+自动生成编号=凭证号
//headData.VOUALLNO = headData.VKNO + headData.ACCYEAR + headData.ACCMONTH + strVOUNO;//年+月+自动生成编号=凭证号
headData.VOUALLNO = headData.ACCYEAR + headData.ACCMONTH + strVOUNO;//年+月+自动生成编号=凭证号
#endregion
//
if (opstatus == "add")
{
#region 默认值
string lsVOUALLNO = "select (ISNULL((select top 1 VOUNO from cw_vouchers WITH(NOLOCK) where ACCYEAR='" + headData.ACCYEAR.ToString() + "' and ACCMONTH='" + headData.ACCMONTH.ToString() + "' order by VOUALLNO desc),0)+1) as VOUNO";
string lsVOUNO = T_ALL_DA.GetStrSQL("VOUNO", lsVOUALLNO);
if (lsVOUNO.Trim() != "")
{
if (lsVOUNO.Trim() != headData.VOUNO.ToString())
{
headData.VOUNO = lsVOUNO.Trim();
strVOUNO = lsVOUNO.Trim();
for (int i = 0; i < (4 - headData.VOUNO.ToString().Length); i++)
{
strVOUNO = "0" + strVOUNO;
}
headData.VOUNO = strVOUNO;//年+月+自动生成编号=凭证号
//headData.VOUALLNO = headData.VKNO + headData.ACCYEAR + headData.ACCMONTH + strVOUNO;//年+月+自动生成编号=凭证号
headData.VOUALLNO = headData.ACCYEAR + headData.ACCMONTH + strVOUNO;//年+月+自动生成编号=凭证号
}
}
//
ORDNO = "VOU" + Guid.NewGuid().ToString().Trim().Replace("-", "");
headData.ORDNO = ORDNO;//唯一编码 newid()
headData.AMTDR = 0;//本位币借方
headData.AMTCR = 0;//本位币贷方
headData.FCY = "RMB";//是否含有外币科目
headData.QTY = "";//是否含有数量科目
headData.VOUPROP = "";//凭证属性
headData.CHECKED = "";//审核人
headData.ENTERED = "";//记账人
headData.ERRMSG = "";//错误信息
headData.ISDELETE = false;//是否废除
headData.DELETEUSER = "";//废除操作人
//headData.DELETETIME = null;//废除时间
headData.ISEXPORT = false;//是否导出凭证
#endregion
//
headData.DbOperationType = DbOperationType.DbotIns;
}
else if (opstatus == "edit")
{
oldVOUALLNO = T_ALL_DA.GetStrSQL("VOUALLNO", "select top 1 VOUALLNO from cw_vouchers WITH(NOLOCK) where ORDNO='" + headData.ORDNO.ToString().Trim() + "'");
headData.DbOperationType = DbOperationType.DbotUpd;
headData.ModelUIStatus = "E";
}
else
{
headData.DbOperationType = DbOperationType.DbotDel;
}
//
if (isPost)
{
var modb = new ModelObjectDB();
DBResult result = modb.Save(headData);
if (result.Success == true)
{
//删除列表中的多余数据
if (DelBodyList != null)
{
foreach (var enumValue in DelBodyList)
{
DBResult result1 = MsCwVouchersDAL.DeleteDetail(enumValue);
}
}
//添加、修改数据
if (bodyList != null)
{
int n = 1;
Decimal AMTDR_HJ = 0;
Decimal AMTCR_HJ = 0;
foreach (var enumValue in bodyList)
{
#region 默认值
MsCwVouitems headRow = new MsCwVouitems();
headRow.ORDNO = headData.ORDNO;//关联cw_vouchers = "";//varchar = "";//(36)
headRow.ITEMNO = n;//行号 = "";//int = "";//
headRow.EXPLAN = enumValue.EXPLAN;//摘要,规则生成 = "";//varchar = "";//(60)
//
#region 分解 会计科目 字符串
headRow.CUSTOMERNAME = "";//委托单位//Varchar20
headRow.SALE = "";//揽货人//varchar10
headRow.BLNO = "";//业务编号//varchar30
headRow.ITEMGID = "";//项目名称//varchar
headRow.DEPTGID = "";//项目名称//varchar
headRow.ISDEPTACC = false;//核算部门,按规则设置生成//bit
headRow.ISEMPLACC = false;//核算人员,按规则设置生成//bit
headRow.ISCORPACC = false;//核算客户,按规则设置生成//bit
headRow.ISITEMACC = false;//核算项目,按规则设置生成//bit
headRow.DEPTID = "";//部门(系统)//varchar(18)
headRow.EMPLID = "";//人员(系统)//varchar(18)
headRow.CORPID = "";//客户(系统)//varchar(18)
headRow.ITEMID = "";//项目编号//Varchar(50)
//
headRow.ACCID = enumValue.ACCID;//科目代码 = "";//varchar = "";//(16)
headRow.ACCALL = enumValue.ACCALL.ToString().Trim();//会计科目字符串//varchar
string[] ayList = headRow.ACCALL.ToString().Trim().Split(new string[] { "▁" }, StringSplitOptions.RemoveEmptyEntries);
headRow.ACCNAME = ayList[0].ToString();//科目名称 varchar(60)
string strITEM = headRow.ACCNAME.ToString();//科目名称 varchar(60)
string sSQL2 = "select top 1 * from cw_accitems WITH(NOLOCK) where ACCID='" + headRow.ACCID.ToString() + "'";
DataSet ds = T_ALL_DA.GetAllSQL(sSQL2);
if (ds != null)
{
if (ds.Tables[0].Rows.Count > 0)
{
headRow.ACCID = ds.Tables[0].Rows[0]["ACCID"].ToString();//科目代码//varchar(16)
headRow.ACCNAME = ds.Tables[0].Rows[0]["ACCNAME"].ToString();//科目名称 varchar(60)
strITEM = headRow.ACCNAME.ToString();//科目名称 varchar(60)
if (ds.Tables[0].Rows[0]["ISCORPACC"].ToString()=="True") {
strITEM += "▁CustNAME";//核算客户,按规则设置生成
}
if (ds.Tables[0].Rows[0]["ISDEPTACC"].ToString()=="True") {
strITEM += "▁DeptName";//核算部门,按规则设置生成
}
if (ds.Tables[0].Rows[0]["ISEMPLACC"].ToString()=="True") {
strITEM += "▁SALE";//核算人员,按规则设置生成
}
if (ds.Tables[0].Rows[0]["ISITEMACC"].ToString()=="True") {
strITEM += "▁ITEMNAME";//核算项目,按规则设置生成
}
}
}
string[] ayItem = strITEM.Trim().Split(new string[] { "▁" }, StringSplitOptions.RemoveEmptyEntries);
for (var i = 1; i < ayList.Count(); i++)
{
if (ayItem[i].ToString() == "CustNAME")//委托单位
{
headRow.ISCORPACC = true;//核算客户,按规则设置生成//bit
headRow.CUSTOMERNAME = ayList[i].ToString();//委托单位//Varchar20
if (enumValue.AMTDR == 0)//借
{
sSQL2 = "select top 1 FARCODE from info_client WITH(NOLOCK) where SHORTNAME='" + ayList[i].ToString() + "'";
}
else//贷
{
sSQL2 = "select top 1 FAPCODE as FARCODE from info_client WITH(NOLOCK) where SHORTNAME='" + ayList[i].ToString() + "'";
}
headRow.CORPID = T_ALL_DA.GetStrSQL("FARCODE", sSQL2);//客户(系统)//varchar(18)
}
else if (ayItem[i].ToString() == "DeptName")
{
headRow.ISDEPTACC = true;//核算部门,按规则设置生成//bit
sSQL2 = "select top 1 FINANCESOFTCODE from sys_dept WITH(NOLOCK) where DEPTNAME='" + ayList[i].ToString() + "'";
headRow.DEPTID = T_ALL_DA.GetStrSQL("FINANCESOFTCODE", sSQL2);
sSQL2 = "select top 1 GID from sys_dept where DEPTNAME='" + ayList[i].ToString() + "'";
headRow.DEPTGID = T_ALL_DA.GetStrSQL("GID", sSQL2);
}
else if (ayItem[i].ToString() == "SALE")
{
headRow.ISEMPLACC = true;//核算人员,按规则设置生成//bit
headRow.SALE = ayList[i].ToString();//揽货人//varchar10
sSQL2 = "select top 1 FINANCESOFTCODE from user_baseinfo,[user] WITH(NOLOCK) where [user].GID=user_baseinfo.USERID and [user].SHOWNAME='" + ayList[i].ToString() + "'";
headRow.EMPLID = T_ALL_DA.GetStrSQL("FINANCESOFTCODE", sSQL2);//人员(系统)//varchar(18)
}
else if (ayItem[i].ToString() == "ITEMNAME")
{
headRow.ISITEMACC = true;//核算项目,按规则设置生成//bit
sSQL2 = "select top 1 FINANCESOFTCODE from cw_item WITH(NOLOCK) where [STARTGID]='" + strCwSTARTGID + "' and ITEMNAME='" + ayList[i].ToString() + "'";
headRow.ITEMID = T_ALL_DA.GetStrSQL("FINANCESOFTCODE", sSQL2);//项目编号//Varchar(50)
sSQL2 = "select top 1 GID from cw_item WITH(NOLOCK) where [STARTGID]='" + strCwSTARTGID + "' and ITEMNAME='" + ayList[i].ToString() + "'";
headRow.ITEMGID = T_ALL_DA.GetStrSQL("GID", sSQL2);//项目名称//varchar
}
}
#endregion
//
headRow.AMTDR = enumValue.AMTDR;//本位币借方金额(互斥) = "";//Numeric = "";//(18,2)
headRow.AMTCR = enumValue.AMTCR;//本位币贷方金额(互斥) = "";//Numeric = "";//(18,2)
if (enumValue.AMTCR == 0)
{
headRow.DC = "D";//借贷方向 = "";//varchar = "";//(2)
}
else
{
headRow.DC = "C";//借贷方向 = "";//varchar = "";//(2)
}
headRow.FCYNO = "RMB";//外币编号usd = "";//varchar = "";//(8)
headRow.ISFCY = false;//是否外币 = "";//Bit = "";//
headRow.FCYEXRATE = 1;//汇率 = "";//Numeric = "";//(18,2)
if (enumValue.FCYNO.ToString().Trim() != "RMB" && enumValue.FCYNO.ToString().Trim() != "")
{
headData.FCY = enumValue.FCYNO.ToString().Trim();//是否含有外币科目
headRow.FCYNO = enumValue.FCYNO.ToString().Trim();//外币编号usd = "";//varchar = "";//(8)
headRow.ISFCY = true;//是否外币 = "";//Bit = "";//
headRow.FCYEXRATE = enumValue.FCYEXRATE;//汇率 = "";//Numeric = "";//(18,2)
if (enumValue.AMTCR == 0)
{
headRow.FCYDR = enumValue.FCYAMT;//外币借方金额 = "";//Numeric = "";//(18,2)
headRow.FCYCR = 0;//外币贷方金额 = "";//Numeric = "";//(18,2)
headRow.AMTDR = Decimal.Parse((enumValue.FCYAMT * enumValue.FCYEXRATE).ToString("#.##"));//本位币借方金额(互斥)//Numeric(18,2)
}
else
{
headRow.FCYDR = 0;//外币借方金额 = "";//Numeric = "";//(18,2)
headRow.FCYCR = enumValue.FCYAMT;//外币贷方金额 = "";//Numeric = "";//(18,2)
headRow.AMTCR = Decimal.Parse((enumValue.FCYAMT * enumValue.FCYEXRATE).ToString("#.##"));//本位币借方金额(互斥)//Numeric(18,2)
}
AMTDR_HJ += enumValue.AMTDR;
AMTCR_HJ += enumValue.AMTCR;
}
else
{
AMTDR_HJ += enumValue.AMTDR;
AMTCR_HJ += enumValue.AMTCR;
}
//
headRow.MODIFIEDUSER = Convert.ToString(Session["USERID"]);//最后一次更新操作人 = "";//Varchar(36) = "";//Y
headRow.MODIFIEDTIME = DateTime.Now;//最后一次更新操作时间 = "";//Datetime = "";//Y
#endregion
//
if (enumValue.GID.ToString().Trim() == "*")//"add"
{
#region 默认值
string GID = Guid.NewGuid().ToString();
headRow.GID = GID;//唯一编码 newid() varchar (36)
headRow.ORDNO = headData.ORDNO;//关联cw_vouchers = "";//varchar = "";//(36)
headRow.PACCID = "";//父级科目代码 = "";//varchar = "";//(16)
headRow.PROPERTY = 0;//科目属性 = "";//int = "";//
headRow.GRADE = 0;//科目级别 = "";//int = "";//
headRow.QTYUNIT = "";//数量包装单位 = "";//varchar = "";//(10)
headRow.QTYDR = 0;//借方数量 = "";//Numeric = "";//(18,2)
headRow.QTYCR = 0;//贷方数量 = "";//Numeric = "";//(18,2)
headRow.PITEMID = 0;//父级项目编号 = "";//int = "";// 
headRow.FIELD1 = "";//预留字段1 = "";//varchar = "";//(10)
headRow.FIELD2 = "";//预留字段2 = "";//varchar = "";//(10)
headRow.FIELD3 = "";//预留字段3 = "";//varchar = "";//(20)
headRow.FIELD4 = "";//预留字段4 = "";//varchar = "";//(20)
headRow.FIELD5 = "";//预留字段5 = "";//varchar = "";//(20)
headRow.FIELD6 = "";//预留字段6 = "";//varchar = "";//(20)
headRow.FIELD7 = "";//预留字段7 = "";//varchar = "";//(60)
headRow.FIELD8 = "";//预留字段8 = "";//varchar = "";//(60)
headRow.FIELD9 = "";//预留字段9 = "";//varchar = "";//(60)
headRow.FIELD10 = "";//预留字段10 = "";//varchar = "";//(60)
headRow.ISSYS = true;//是否手动录入 = "";//Bit = "";//
headRow.FSETTLCODE = "";//结算方式 = "";//varchar = "";//(20)
headRow.FSETTLENO = "";//财务辅助编号 = "";//varchar = "";//(20)
#endregion
headRow.DbOperationType = DbOperationType.DbotIns;
}
else//"edit"
{
headRow.GID = enumValue.GID.ToString().Trim();//唯一编码
headRow.DbOperationType = DbOperationType.DbotUpd;
headRow.ModelUIStatus = "E";
}
//
modb = new ModelObjectDB();
result = modb.Save(headRow);
if (result.Message.ToString().IndexOf("插入重复键") > -1)
{
errorstr += "重复数据不再重复插入!";
//var jsonRespose = new JsonResponse { Success = false, Message = "重复,不允许保存!" };
//return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
n++;
}
//
string sSQL = "update cw_vouchers set AMTDR=" + AMTDR_HJ + ",AMTCR=" + AMTCR_HJ + " where ORDNO='" + headData.ORDNO.ToString().Trim() + "'";
if (headData.FCY.ToString().Trim() != "RMB")
{
sSQL = "update cw_vouchers set AMTDR=" + AMTDR_HJ + ",AMTCR=" + AMTCR_HJ + ",FCY='" + headData.FCY + "' where ORDNO='" + headData.ORDNO.ToString().Trim() + "'";
}
bool bl = T_ALL_DA.GetExecuteSqlCommand(sSQL);
//
if (oldVOUALLNO.Trim() != "")
{
//更新进口贸易业务表的凭证相关字段
sSQL = "UPDATE ch_fee SET VOUCHERNO='" + headData.VOUALLNO.ToString() + "' where VOUCHERNO in ('" + oldVOUALLNO + "')";
bl = T_ALL_DA.GetExecuteSqlCommand(sSQL);
sSQL = "UPDATE ch_fee_settlement SET VOUNO='" + headData.VOUALLNO.ToString() + "' where VOUNO in ('" + oldVOUALLNO + "')";
bl = T_ALL_DA.GetExecuteSqlCommand(sSQL);
}
//
}
}
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
Data = MsCwVouchersDAL.GetData("ORDNO='" + ORDNO + "'", Convert.ToString(Session["COMPANYID"]))
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
else
{
var jsonRespose = new JsonResponse { Success = false, Message = errorstr + "重复,不允许保存!" };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
}
#endregion
#region 删除
public ContentResult Delete(string gids)
{
if (Convert.ToString(Session["COMPANYID"]).Trim() == "" || Convert.ToString(Session["USERID"]).Trim() == "" || Convert.ToString(Session["CODENAME"]).Trim() == "" || Convert.ToString(Session["SHOWNAME"]).Trim() == "" || Convert.ToString(Session["DEPTNAME"]).Trim() == "")
{
var jsonRespose2 = new JsonResponse { Success = false, Message = "登录超时,请退出系统重新登录!" };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose2) };
}
//
DBResult result = MsCwVouchersDAL.Delete(gids, Convert.ToString(Session["USERID"]));
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult DeleteDetail(string data)
{
var head = JsonConvert.Deserialize<MsCwVouitems>(data);
var modb = new ModelObjectDB();
DBResult result = modb.Delete(head);
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
#endregion
#region 根据币别,获取汇率值
public ContentResult GetFCYEXRATE(string FCY, string LINKGID)
{
var strList = MsCwVouchersDAL.GetFCYEXRATE(FCY, LINKGID, Convert.ToString(Session["COMPANYID"]), Convert.ToString(Session["USERID"]));
if (strList.Trim() == "-1")
{
var json = JsonConvert.Serialize(new { Success = false, Message = "请先设置对应的币别信息!", data = "" });
return new ContentResult() { Content = json };
}
else
{
var json = JsonConvert.Serialize(new { Success = true, Message = "操作成功!", data = strList });
return new ContentResult() { Content = json };
}
}
#endregion
#region 是否已经维护财务代码
public ContentResult GetISFINANCESOFTCODE(string TYPE, string VALUE)
{
var strList = MsCwVouchersDAL.GetISFINANCESOFTCODE(TYPE, VALUE, Convert.ToString(Session["COMPANYID"]), Convert.ToString(Session["USERID"]));
if (strList.Trim() == "-1")
{
var json = JsonConvert.Serialize(new { Success = false, Message = "请先设置对应的财务代码!", data = "" });
return new ContentResult() { Content = json };
}
else
{
var json = JsonConvert.Serialize(new { Success = true, Message = "操作成功!", data = strList });
return new ContentResult() { Content = json };
}
}
#endregion
#region 设置导出凭证号
[SqlKeyWordsFilter(Type = "Action")]//sql 防注入过滤器
public ContentResult IsSetVouNo(string data, string beginvou, string ACCDATEbgn, string ACCDATEend, string condition,string type)
{
var headData = JsonConvert.Deserialize<List<MsCwVouchersVouitems>>(data);
if (type == "0") {
var dataList = MsCwVouchersDAL.GetDataListHJ(condition, Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"]));
headData = dataList;
}
string strvouno = "";
string sql = "";
if (ACCDATEbgn != null) {
if (ACCDATEbgn != "") {
sql = sql + " and SUBSTRING(convert(char(10),VOUDATE,120),1,7) >='" + ACCDATEbgn + "'";
}
}
if (ACCDATEend != null) {
if (ACCDATEend != "") {
sql = sql + " and SUBSTRING(convert(char(10),VOUDATE,120),1,7) <='" + ACCDATEend+ "'";
}
}
try
{
Int32 vouno = Convert.ToInt32(beginvou);
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
if (headData != null)
{
foreach (var enmuvalue in headData)
{
vouno = vouno + 1;
if (!string.IsNullOrEmpty(enmuvalue.EXPVOUNO)) strvouno = strvouno + "," + enmuvalue.EXPVOUNO;
}
var BLCOUNT = T_ALL_DA.GetStrSQL("BLCOUNT", "select count(*) BLCOUNT from cw_vouchers WHERE EXPVOUNO>='"+ beginvou + "' and EXPVOUNO<='" + vouno.ToString() + "' " + sql);
if (BLCOUNT == "0")
{
strvouno = "";
}
}
if (strvouno!= "")
{
var jsonRespose = new JsonResponse { Success = false, Message = "发票号:" + strvouno+" 系统中已存在,确实要重复生成吗?",Data=strvouno };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
else
{
vouno = Convert.ToInt32(beginvou);
if (headData != null)
{
Database db = DatabaseFactory.CreateDatabase();
StringBuilder insSb = new StringBuilder();
SqlCommand cmd = new SqlCommand();
cmd.CommandTimeout = 120000;
int cnt = 0;
foreach (var enmuvalue in headData)
{
insSb.Append("UPDATE cw_vouchers SET EXPVOUNO='" + vouno.ToString() + "' where ORDNO='" + enmuvalue.ORDNO + "' ");
if (cnt == 100)
{
cmd.CommandText = insSb.ToString();
db.ExecuteNonQuery(cmd);
insSb.Clear();
//insSb.Append("insert into ch_dui (duino,custname,duidate,op,duiname,duitype) values ");
cnt = 0;
}
cnt++;
vouno = vouno + 1;
}
if (insSb.ToString() != "") {
cmd.CommandText = insSb.ToString();
db.ExecuteNonQuery(cmd);
}
}
var jsonRespose = new JsonResponse { Success = true, Message = "" };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
}
catch (Exception)
{
var jsonRespose = new JsonResponse { Success = false, Message = "生成过程发生错误!" ,Data=""};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
}
[SqlKeyWordsFilter(Type = "Action")]//sql 防注入过滤器
public ContentResult SetVouNo(string data, string beginvou, string condition, string type)
{
var headData = JsonConvert.Deserialize<List<MsCwVouchersVouitems>>(data);
if (type == "0")
{
var dataList = MsCwVouchersDAL.GetDataListHJ(condition, Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"]));
headData = dataList;
}
try
{
Int32 vouno = Convert.ToInt32(beginvou);
Database db = DatabaseFactory.CreateDatabase();
StringBuilder insSb = new StringBuilder();
SqlCommand cmd = new SqlCommand();
cmd.CommandTimeout = 120000;
int cnt = 0;
foreach (var enmuvalue in headData)
{
insSb.Append("UPDATE cw_vouchers SET EXPVOUNO='" + vouno.ToString() + "' where ORDNO='" + enmuvalue.ORDNO + "' ");
if (cnt == 100)
{
cmd.CommandText = insSb.ToString();
db.ExecuteNonQuery(cmd);
insSb.Clear();
//insSb.Append("insert into ch_dui (duino,custname,duidate,op,duiname,duitype) values ");
cnt = 0;
}
cnt = cnt + 1;
vouno = vouno + 1;
}
if (insSb.ToString() != "")
{
cmd.CommandText = insSb.ToString();
db.ExecuteNonQuery(cmd);
}
var jsonRespose = new JsonResponse { Success =true, Message ="" };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
catch (Exception)
{
var jsonRespose = new JsonResponse { Success =false, Message ="生成过程发生错误!" };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
}
#endregion
#region 是否导出数据
public ContentResult getIsExport(string condition, string gids)
{
DBResult result = MsCwVouchersDAL.getIsExport(condition, gids, Convert.ToString(Session["USERID"]));
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
#endregion
}
}