|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Data;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
using System.Web;
|
|
|
using System.Web.Mvc;
|
|
|
using DSWeb.Areas.CommMng.DAL;
|
|
|
using DSWeb.Areas.RptMng.Comm;
|
|
|
|
|
|
using DSWeb.TruckMng.Comm.Cookie;
|
|
|
|
|
|
|
|
|
using Microsoft.Practices.EnterpriseLibrary.Data;
|
|
|
using DSWeb.EntityDA;
|
|
|
|
|
|
using DSWeb.Areas.CommMng.Models;
|
|
|
|
|
|
|
|
|
using HcUtility.Comm;
|
|
|
using HcUtility.Core;
|
|
|
|
|
|
|
|
|
using System.IO;
|
|
|
using System.Data.OleDb;
|
|
|
using DSWeb.MvcShipping.Models.MsChFeeAutoDui;
|
|
|
using DSWeb.MvcShipping.DAL.MsChFeeAutoDuiDAL;
|
|
|
|
|
|
using DSWeb.MvcShipping.DAL.MsChDui;
|
|
|
using DSWeb.MvcShipping.Models.MsChDui;
|
|
|
using DSWeb.MvcShipping.Models.MsChDuiView;
|
|
|
using DSWeb.MvcShipping.DAL.MsSysBillNoSet;
|
|
|
|
|
|
using DSWeb.MvcShipping.DAL.Chfee_AuditDAL;
|
|
|
using DSWeb.Areas.Account.Models.MsOpBill;
|
|
|
using System.Web.Configuration;
|
|
|
using DSWeb.Areas.Account.Models.Chfee_Payapplication;
|
|
|
using DSWeb.Areas.Account.DAL.Chfee_Payapplication;
|
|
|
using DSWeb.Areas.Account.Models.ChfeeDetail;
|
|
|
using DSWeb.MvcShipping.Helper;
|
|
|
using DSWeb.TruckMng.Helper.Repository;
|
|
|
//using DSWeb.MvcShipping.Helper.Repository;
|
|
|
|
|
|
namespace DSWeb.MvcShipping.Controllers
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// 路单查询
|
|
|
/// </summary>
|
|
|
[JsonRequestBehavior]
|
|
|
public class MsChFeeAutoDuiController : Controller
|
|
|
{
|
|
|
|
|
|
public ActionResult Index()
|
|
|
{
|
|
|
return View();
|
|
|
}
|
|
|
|
|
|
public ActionResult Edit()
|
|
|
{
|
|
|
return View();
|
|
|
}
|
|
|
|
|
|
public static string GetRangDAStr(string tb, string userid, string usercode, string orgcode)
|
|
|
{
|
|
|
string str = "";
|
|
|
var strSql = new StringBuilder();
|
|
|
strSql.Append("SELECT ");
|
|
|
strSql.Append(" VISIBLERANGE,OPERATERANGE ");
|
|
|
strSql.Append(" from VW_User_Authority ");
|
|
|
strSql.Append(" where [NAME]='modMsChFeeAutoDui' and USERID='" + userid + "' and ISDELETE=0");
|
|
|
|
|
|
string visiblerange = "4";
|
|
|
string operaterange = "4";
|
|
|
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
DataSet ds = new DataSet();
|
|
|
|
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
|
{
|
|
|
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
visiblerange = Convert.ToString(reader["VISIBLERANGE"]);
|
|
|
operaterange = Convert.ToString(reader["OPERATERANGE"]);
|
|
|
break;
|
|
|
}
|
|
|
reader.Close();
|
|
|
}
|
|
|
if (visiblerange == "4")
|
|
|
{
|
|
|
str = "1=2";
|
|
|
}
|
|
|
else if (visiblerange == "3")
|
|
|
{
|
|
|
if (tb == "index")
|
|
|
{
|
|
|
str = " A.UserCode='" + usercode + "'";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
str = " UPPER(A.OrgCode)='" + orgcode + "'";
|
|
|
}
|
|
|
}
|
|
|
else if (visiblerange == "2")
|
|
|
{
|
|
|
if (tb == "index")
|
|
|
{
|
|
|
var rangeDa = new RangeDA();
|
|
|
var companyid = rangeDa.GetCORPID(userid);
|
|
|
var deptname = rangeDa.GetDEPTNAME(userid);
|
|
|
var userstr = new StringBuilder();
|
|
|
userstr.Append(" select codename from [user] where GID in (select USERID from user_company where COMPANYID='" + companyid + "') and GID in (select userid from user_baseinfo where DEPTNAME='" + deptname + "')");
|
|
|
Database userdb = DatabaseFactory.CreateDatabase();
|
|
|
using (IDataReader reader = userdb.ExecuteReader(CommandType.Text, userstr.ToString()))
|
|
|
{
|
|
|
str = "";
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
if (str == "")
|
|
|
{
|
|
|
str = "(A.usercode='" + Convert.ToString(reader["codename"]) + "'";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
str = str+ " or A.usercode='" + Convert.ToString(reader["codename"]) + "'";
|
|
|
};
|
|
|
}
|
|
|
str =str+ ")";
|
|
|
reader.Close();
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
str = " UPPER(A.OrgCode)='" + orgcode + "'";
|
|
|
}
|
|
|
|
|
|
}
|
|
|
else if (visiblerange == "1")
|
|
|
{
|
|
|
str = " UPPER(A.OrgCode)='" + orgcode + "'";
|
|
|
}
|
|
|
|
|
|
return str;
|
|
|
}
|
|
|
|
|
|
|
|
|
public ContentResult GetDataList(int start, int limit, string sort, string condition)
|
|
|
{
|
|
|
var dataList = MsChFeeAutoDuiDAL.GetDataList(condition, 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 };
|
|
|
}
|
|
|
|
|
|
public ContentResult GetData(string handle,string condition)
|
|
|
{
|
|
|
MsChFeeAutoDuimb head = null;
|
|
|
|
|
|
if (handle == "add")
|
|
|
{
|
|
|
head = new MsChFeeAutoDuimb();
|
|
|
head.GID = System.Guid.NewGuid().ToString();
|
|
|
head.OP = Convert.ToString(Session["SHOWNAME"]);
|
|
|
head.OPDATE = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
|
|
head.FEETYPE = "2";
|
|
|
head.FEEDC = "0";
|
|
|
head.DUITYPE = "1";
|
|
|
head.FEEDUITYPECONDIT = "等于";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
var _t = "";
|
|
|
var list = MsChFeeAutoDuiDAL.GetDataList(condition, _t);
|
|
|
if (list.Count > 0)
|
|
|
head = list[0];
|
|
|
|
|
|
if (head == null)
|
|
|
{
|
|
|
head = new MsChFeeAutoDuimb();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
var json = JsonConvert.Serialize(
|
|
|
new { Success = true, Message = "查询成功", data = head });
|
|
|
return new ContentResult() { Content = json };
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
public ContentResult GetBodyList ( int start, int limit, string sort, string condition )
|
|
|
{
|
|
|
var dataList = MsChFeeAutoDuiDAL.GetBodyList(condition, 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 };
|
|
|
}
|
|
|
|
|
|
public ContentResult GetBodyListStr(string sort, string condition)
|
|
|
{
|
|
|
var dataListStr = MsChFeeAutoDuiDAL.GetBodyListStr(condition, sort);
|
|
|
|
|
|
|
|
|
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", Data = dataListStr });
|
|
|
return new ContentResult() { Content = json };
|
|
|
}
|
|
|
public ContentResult Save ( string opstatus, string data,
|
|
|
string CargoBody, string CargoDelBody )
|
|
|
{
|
|
|
var head = JsonConvert.Deserialize<MsChFeeAutoDuimb>(data);
|
|
|
|
|
|
var CargobodyList = JsonConvert.Deserialize<List<CH_FEE_AutoDuiDetailmb>>(CargoBody);
|
|
|
var CargodelbodyList = JsonConvert.Deserialize<List<CH_FEE_AutoDuiDetailmb>>(CargoDelBody);
|
|
|
|
|
|
if (opstatus == "add")
|
|
|
{
|
|
|
head.DbOperationType = DbOperationType.DbotIns;
|
|
|
head.ModelUIStatus = "I";
|
|
|
//head.Mainstate = "0";
|
|
|
head.GID = PubSysDAL.GetBillNo("N001");
|
|
|
}
|
|
|
else if (opstatus == "edit")
|
|
|
{
|
|
|
head.DbOperationType = DbOperationType.DbotUpd;
|
|
|
head.ModelUIStatus = "E";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
head.DbOperationType = DbOperationType.DbotDel;
|
|
|
}
|
|
|
|
|
|
var _OP = Session["SHOWNAME"].ToString();
|
|
|
|
|
|
head.OP = _OP;
|
|
|
head.OPDATE = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
|
|
|
|
var modb = new ModelObjectRepository();
|
|
|
DBResult result = modb.Save(head,
|
|
|
ModelObjectConvert<CH_FEE_AutoDuiDetailmb>.ToModelObjectList(CargobodyList),
|
|
|
ModelObjectConvert<CH_FEE_AutoDuiDetailmb>.ToModelObjectList(CargodelbodyList)
|
|
|
);
|
|
|
|
|
|
head = MsChFeeAutoDuiDAL.GetData("GID='" + head.GID + "'");
|
|
|
|
|
|
|
|
|
//var _r2 = MsChFeeAutoDuiDAL.ReMake(head);
|
|
|
|
|
|
//刷新父窗口上的父节点
|
|
|
var jsonRespose = new JsonResponse
|
|
|
{
|
|
|
Success = result.Success,
|
|
|
Message = result.Message,
|
|
|
Data = MsChFeeAutoDuiDAL.GetData("GID='" + head.GID + "'")
|
|
|
};
|
|
|
|
|
|
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
|
|
|
}
|
|
|
|
|
|
public ContentResult CFSave(string data,
|
|
|
string CargoBody, string CargoDelBody)
|
|
|
{
|
|
|
var head = JsonConvert.Deserialize<MsChFeeAutoDuimb>(data);
|
|
|
|
|
|
var CargobodyList = MsChFeeAutoDuiDAL.GetBodyList(" D.BSNO='" + head.GID + "' and isnull(D.ISOK,0)=1 ");
|
|
|
|
|
|
|
|
|
head.DbOperationType = DbOperationType.DbotIns;
|
|
|
head.ModelUIStatus = "I";
|
|
|
//head.Mainstate = "0";
|
|
|
head.GID = PubSysDAL.GetBillNo("N001");
|
|
|
var _OP = Session["SHOWNAME"].ToString();
|
|
|
|
|
|
head.OP = _OP;
|
|
|
head.OPDATE = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
|
|
head.STATUS = "对账平衡";
|
|
|
var modb = new ModelObjectDB();
|
|
|
DBResult result = modb.Save(head);
|
|
|
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
using (var conn = db.CreateConnection())
|
|
|
{
|
|
|
conn.Open();
|
|
|
var tran = conn.BeginTransaction();
|
|
|
|
|
|
try
|
|
|
{
|
|
|
CargobodyList.ForEach(i =>
|
|
|
{
|
|
|
if (i.ISOK == "1")
|
|
|
{
|
|
|
var cmd = db.GetSqlStringCommand("update CH_FEE_AutoDuiDetail set BSNO='"+head.GID+"' WHERE GID='"+i.GID+"'");
|
|
|
db.ExecuteNonQuery(cmd, tran);
|
|
|
}
|
|
|
});
|
|
|
|
|
|
|
|
|
tran.Commit();
|
|
|
}
|
|
|
catch (Exception)
|
|
|
{
|
|
|
tran.Rollback();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
head = MsChFeeAutoDuiDAL.GetData("GID='" + head.GID + "'");
|
|
|
|
|
|
|
|
|
//var _r2 = MsChFeeAutoDuiDAL.ReMake(head);
|
|
|
|
|
|
//刷新父窗口上的父节点
|
|
|
var jsonRespose = new JsonResponse
|
|
|
{
|
|
|
Success = result.Success,
|
|
|
Message = result.Message,
|
|
|
Data = MsChFeeAutoDuiDAL.GetData("GID='" + head.GID + "'")
|
|
|
};
|
|
|
|
|
|
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
|
|
|
}
|
|
|
|
|
|
|
|
|
private List<CH_FEE_AutoDuiDetailmb> InsertLocalDetail ( MsChFeeAutoDuimb head, List<CH_FEE_AutoDuiDetailmb> DetailList )
|
|
|
{
|
|
|
//如果有开始和结束日期,查询所有结算对象中包含head.customername的业务
|
|
|
//然后遍历DetailList,如果提单号没有则向DetailList当中添加该业务。
|
|
|
var userid = Session["USERID"].ToString();
|
|
|
var username = Session["SHOWNAME"].ToString();
|
|
|
var companyid = Session["COMPANYID"].ToString();
|
|
|
var feesql = "";
|
|
|
if (head.FSTATUS == "1") {
|
|
|
feesql = " AND ch_fee.FEESTATUS IN (0,8,9) ";
|
|
|
} else if (head.FSTATUS == "2")
|
|
|
{
|
|
|
feesql = " AND ch_fee.FEESTATUS IN (1,2) ";
|
|
|
}
|
|
|
else if (head.FSTATUS == "3")
|
|
|
{
|
|
|
feesql = " AND ch_fee.FEESTATUS IN (0,8,9) AND ch_fee.ORDERAMOUNT=0 ";
|
|
|
}
|
|
|
else if (head.FSTATUS == "4")
|
|
|
{
|
|
|
feesql = " AND ch_fee.ORDERAMOUNT=0 ";
|
|
|
}
|
|
|
|
|
|
var BillList = new List<MsOpBill>();
|
|
|
if (head.STARTDATE != "" && head.ENDDATE != "")
|
|
|
{
|
|
|
if (head.HAVEDEBIT == "0")
|
|
|
{
|
|
|
//BillList = Chfee_AuditDAL.GetBillDataList(" OPLBNAME='海运出口' and ETD between '" + head.STARTDATE + "' and '" + head.ENDDATE + "' and exists(select 1 from ch_fee where customername='" + head.CUSTOMERNAME + "' and bsno=V_op_Bill.BSNO and Amount<>settlement and isnull(ISDEBIT,0)=0) ", userid, username, companyid);
|
|
|
BillList = Chfee_AuditDAL.GetBillDataList(" ETD between '" + head.STARTDATE + "' and '" + head.ENDDATE + "' and exists(select 1 from ch_fee where ch_fee.customername='" + head.CUSTOMERNAME + "' and ch_fee.bsno=V_op_Bill.BSNO and Amount<>settlement and isnull(ISDEBIT,0)=0 "+feesql+") ", userid, username, companyid);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
BillList = Chfee_AuditDAL.GetBillDataList(" ETD between '" + head.STARTDATE + "' and '" + head.ENDDATE + "' and exists(select 1 from ch_fee where ch_fee.customername='" + head.CUSTOMERNAME + "' and ch_fee.bsno=V_op_Bill.BSNO and Amount<>settlement " + feesql + ") ", userid, username, companyid);
|
|
|
}
|
|
|
foreach (var _bill in BillList)
|
|
|
{
|
|
|
var 需要添加 = true;
|
|
|
foreach (var _d in DetailList)
|
|
|
{
|
|
|
if (_bill.MBLNO == _d.MBLNO)
|
|
|
{
|
|
|
需要添加 = false;
|
|
|
continue;
|
|
|
}
|
|
|
}
|
|
|
if (需要添加)
|
|
|
{
|
|
|
var newdetail = new CH_FEE_AutoDuiDetailmb();
|
|
|
newdetail.GID = Guid.NewGuid().ToString();
|
|
|
newdetail.MBLNO = _bill.MBLNO;
|
|
|
newdetail.ISOK = "0";
|
|
|
newdetail.BSNO = "";
|
|
|
newdetail.RMBAMOUNT = "0";
|
|
|
newdetail.USDAMOUNT = "0";
|
|
|
newdetail.L_RMBAMOUNT = "0";
|
|
|
newdetail.L_USDAMOUNT = "0";
|
|
|
newdetail.REMARK2 = "对方账单无此提单号";
|
|
|
DetailList.Add(newdetail);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return DetailList;
|
|
|
}
|
|
|
|
|
|
public ContentResult ReMake (string data )
|
|
|
{
|
|
|
var head = JsonConvert.Deserialize<MsChFeeAutoDuimb>(data);
|
|
|
/* 20170124 改为将“填写需要添加的我方有对方没有的业务放在DAL内,方便倒入excel之后调用”
|
|
|
var DetailList = MsChFeeAutoDuiDAL.GetBodyList("BSNO='"+head.GID+"'");
|
|
|
|
|
|
DetailList = InsertLocalDetail(head, DetailList);
|
|
|
var _DelDetailList = new List<CH_FEE_AutoDuiDetailmb>();
|
|
|
|
|
|
var modb = new ModelObjectRepository();
|
|
|
DBResult result = modb.SaveComm("BSNO",head.GID,
|
|
|
ModelObjectConvert<CH_FEE_AutoDuiDetailmb>.ToModelObjectList(DetailList),
|
|
|
ModelObjectConvert<CH_FEE_AutoDuiDetailmb>.ToModelObjectList(_DelDetailList)
|
|
|
);
|
|
|
*/
|
|
|
var userid = Session["USERID"].ToString();
|
|
|
var username = Session["SHOWNAME"].ToString();
|
|
|
var companyid = Session["COMPANYID"].ToString();
|
|
|
|
|
|
|
|
|
DBResult result = MsChFeeAutoDuiDAL.ReMake(head, userid, username, companyid);
|
|
|
|
|
|
//刷新父窗口上的父节点
|
|
|
var jsonRespose = new JsonResponse
|
|
|
{
|
|
|
Success = result.Success,
|
|
|
Message = result.Message,
|
|
|
Data = MsChFeeAutoDuiDAL.GetData("GID='" + head.GID + "'")
|
|
|
};
|
|
|
|
|
|
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
|
|
|
}
|
|
|
|
|
|
public ContentResult MakeDui ( string type ,string data )
|
|
|
{
|
|
|
var _head = JsonConvert.Deserialize<MsChFeeAutoDuimb>(data);
|
|
|
var head = MsChFeeAutoDuiDAL.GetData("GID='" + _head.GID + "'");
|
|
|
var result = new DBResult();
|
|
|
if (type == "1")
|
|
|
{
|
|
|
var DetailList = MsChFeeAutoDuiDAL.GetBodyJoinList(" D.BSNO='" + head.GID + "' and isnull(D.ISOK,0)=1 ");
|
|
|
//var _DelDetailList = new List<CH_FEE_AutoDuiDetailmb>();
|
|
|
|
|
|
var headData = new ChDui();
|
|
|
headData.DUIDATE = DateTime.Now.ToString("yyyy-MM-dd");
|
|
|
|
|
|
var billnoset = MsSysBillNoSetDAL.GetData("OPLBNAME='客户对账'", Convert.ToString(Session["COMPANYID"]));
|
|
|
if (billnoset.BILLTYPE != "")
|
|
|
headData.DUINO = MsSysBillNoSetDAL.GetBillNo(billnoset, headData.DUIDATE.ToString().Trim(), headData.DUIDATE.ToString().Trim());
|
|
|
else
|
|
|
headData.DUINO = PubSysDAL.GetBillNo("0301");
|
|
|
|
|
|
headData.OP = Convert.ToString(Session["SHOWNAME"]);
|
|
|
headData.CUSTNAME = head.CUSTOMERNAME;
|
|
|
|
|
|
headData.DbOperationType = DbOperationType.DbotIns;
|
|
|
headData.ModelUIStatus = "I";
|
|
|
|
|
|
if (head.FEETYPE == "1") {
|
|
|
//应收
|
|
|
headData.DC = "D";
|
|
|
}
|
|
|
if (head.FEETYPE == "2")
|
|
|
{
|
|
|
//应付
|
|
|
headData.DC = "C";
|
|
|
}
|
|
|
if (head.FEETYPE == "3")
|
|
|
{
|
|
|
//全部
|
|
|
headData.DC = "A";
|
|
|
}
|
|
|
|
|
|
//费用范围 未结费用
|
|
|
headData.ISNOSTL = "B";
|
|
|
|
|
|
var DuiBillList = new List<ChDuiBill>();
|
|
|
var DuiBillDelList = new List<ChDuiBill>();
|
|
|
|
|
|
|
|
|
//对账单内业务明细
|
|
|
foreach (var _D in DetailList) {
|
|
|
if (_D.B_BSNO != "")
|
|
|
{
|
|
|
var DuiBill = new ChDuiBill();
|
|
|
DuiBill.DUINO = "";
|
|
|
DuiBill.BSNO = _D.B_BSNO;
|
|
|
DuiBillList.Add(DuiBill);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
var modb = new ModelObjectRepository();
|
|
|
result = modb.Save(headData);
|
|
|
if (result.Success == true)
|
|
|
{
|
|
|
|
|
|
head.DUINO = headData.DUINO;
|
|
|
head.DbOperationType = DbOperationType.DbotUpd;
|
|
|
head.ModelUIStatus = "E";
|
|
|
|
|
|
result = modb.SaveHead(head
|
|
|
);
|
|
|
|
|
|
//Database db = DatabaseFactory.CreateDatabase();
|
|
|
//using (var conn = db.CreateConnection())
|
|
|
//{
|
|
|
// conn.Open();
|
|
|
// var tran = conn.BeginTransaction();
|
|
|
|
|
|
// try
|
|
|
// {
|
|
|
// var cmd = db.GetSqlStringCommand("insert ch_dui_bill(DUINO,BSNO) SELECT @DUINO,B_BSNO from CH_FEE_AutoDuiDetail D where D.BSNO='" + head.GID + "' AND isnull(D.B_BSNO,'')<>'' and isnull(D.ISOK,0)=1 ");
|
|
|
// db.AddInParameter(cmd, "@DUINO", DbType.String, head.DUINO);
|
|
|
// db.ExecuteNonQuery(cmd, tran);
|
|
|
|
|
|
// tran.Commit();
|
|
|
// }
|
|
|
// catch (Exception)
|
|
|
// {
|
|
|
// tran.Rollback();
|
|
|
|
|
|
|
|
|
|
|
|
// }
|
|
|
//}
|
|
|
|
|
|
//将范围内的费用逐个添加至对账单内。
|
|
|
var _isdebit = "否";
|
|
|
if (head.HAVEDEBIT != "1")
|
|
|
{
|
|
|
_isdebit = "否";//对账单属性 是否包含已对账
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
_isdebit = "是";
|
|
|
}
|
|
|
var _condition = "f.BSNO in (select bsno from v_op_bill b where EXISTS (select 1 from CH_FEE_AutoDuiDetail fd where (b.MBLNO=fd.MBLNO or b.HBLNO=fd.MBLNO) AND ISNULL(fd.MBLNO,'')<>'' AND isnull(fd.ISOK,0)=1 and fd.bsno='"
|
|
|
+ head.GID + "')) and f.customername='" + head.CUSTOMERNAME + "' and f.amount<>f.settlement ";
|
|
|
if (head.FEEDC != "0" && head.FEEDC.Trim()!= "")
|
|
|
{
|
|
|
_condition=_condition+" and f.FEETYPE=" + head.FEEDC;
|
|
|
}
|
|
|
if (head.CURR != "")
|
|
|
{
|
|
|
_condition=_condition+" and f.CURRENCY='" + head.CURR + "'";
|
|
|
}
|
|
|
if (head.FSTATUS == "1" || head.FSTATUS == "3")
|
|
|
{
|
|
|
_condition = _condition + " AND (F.FEESTATUS=0 or F.FEESTATUS=8 or F.FEESTATUS=9)";
|
|
|
}
|
|
|
else if (head.FSTATUS == "2")
|
|
|
{
|
|
|
_condition = _condition + " AND (F.FEESTATUS!=0 and F.FEESTATUS!=8 and F.FEESTATUS!=9) ";
|
|
|
}
|
|
|
if (head.FSTATUS == "3" || head.FSTATUS == "4")
|
|
|
{
|
|
|
_condition = _condition + " AND (f.AMOUNT-isnull(f.SETTLEMENT,0)-isnull(f.ORDERAMOUNT,0)+isnull(f.ORDERSETTLEMENT,0))<>0 ";
|
|
|
}
|
|
|
if (head.SALECORP != "") {
|
|
|
_condition = _condition + " AND F.SALECORP='"+head.SALECORP+"' ";
|
|
|
}
|
|
|
|
|
|
if (head.FEEDUITYPE != "")
|
|
|
{
|
|
|
if (head.FEEDUITYPECONDIT == "不等于")
|
|
|
{
|
|
|
_condition = _condition + " and not EXISTS (select 1 from code_fee c where c.[NAME]=f.FEENAME and c.DUITYPE='" + head.FEEDUITYPE + "') ";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
_condition = _condition + " and EXISTS (select 1 from code_fee c where c.[NAME]=f.FEENAME and c.DUITYPE='" + head.FEEDUITYPE + "') ";
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (_isdebit == "是")
|
|
|
{
|
|
|
//包含已对账的,所以不加条件
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
_condition += " and isnull(f.ISDEBIT,0)=0 ";
|
|
|
}
|
|
|
|
|
|
var _feelist = MsChDuiDAL.GetFeeDetailList(_condition,"否", Convert.ToString(Session["USERID"]));
|
|
|
|
|
|
var feelist = new List<ChDuiDetailView>();
|
|
|
|
|
|
foreach (var _f in _feelist) {
|
|
|
var _df = new ChDuiDetailView();
|
|
|
_df.DUINO = "";
|
|
|
_df.CH_ID = _f.CH_ID;
|
|
|
_df.BSNO = _f.BSNO;
|
|
|
_df.FeeName = _f.FeeName;
|
|
|
_df.CustomerName = _f.CustomerName;
|
|
|
_df.Amount = _f.Amount;
|
|
|
_df.NoTaxAmount = _f.NoTaxAmount;
|
|
|
_df.BalAmount = _f.BalAmount;
|
|
|
_df.Currency = _f.Currency;
|
|
|
_df.ExChangerate = _f.ExChangerate;
|
|
|
feelist.Add(_df);
|
|
|
}
|
|
|
|
|
|
result = MsChDuiDAL.AddDetail(headData.DUINO, feelist, _isdebit);
|
|
|
|
|
|
|
|
|
////Database db = DatabaseFactory.CreateDatabase();
|
|
|
//using (var conn = db.CreateConnection())
|
|
|
//{
|
|
|
// conn.Open();
|
|
|
// var tran = conn.BeginTransaction();
|
|
|
|
|
|
// try
|
|
|
// {
|
|
|
// var cmdinsertbill = db.GetSqlStringCommand("insert into ch_dui_bill(BSNO,DUINO) SELECT distinct BSNO, '" + head.DUINO + "' FROM [ch_dui_detail] where duino = '" + duino + "' "
|
|
|
// + " AND NOT EXISTS (SELECT 1 from ch_dui_bill where DUINO='" + head.DUINO + "' AND BSNO=ch_dui_detail.BSNO )");
|
|
|
|
|
|
// tran.Commit();
|
|
|
// }
|
|
|
// catch (Exception)
|
|
|
// {
|
|
|
// tran.Rollback();
|
|
|
|
|
|
|
|
|
|
|
|
// }
|
|
|
//}
|
|
|
|
|
|
|
|
|
}
|
|
|
}
|
|
|
else {
|
|
|
//result = MsChFeeAutoDuiDAL.DelDui(head);
|
|
|
var userid=Session["USERID"].ToString();
|
|
|
var username=Session["SHOWNAME"].ToString();
|
|
|
var companyid=Session["COMPANYID"].ToString();
|
|
|
var headData = MsChDuiDAL.GetData("ch_dui.DUINO='" + _head.DUINO + "'", userid, username, companyid);
|
|
|
|
|
|
result = MsChDuiDAL.DelBill(_head.DUINO, "1=1");
|
|
|
|
|
|
if (result.Success == true)
|
|
|
{
|
|
|
var modb = new ModelObjectDB();
|
|
|
modb.Delete(headData, "update CH_FEE_AutoDui set DUINO='' where DUINO='" + headData.DUINO + "'");
|
|
|
MsSysBillNoSetDAL.DeleteBsNo(headData.DUINO);
|
|
|
|
|
|
}
|
|
|
|
|
|
//var jsonRespose2 = new JsonResponse { Success = result.Success, Message = result.Message };
|
|
|
//return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose2) };
|
|
|
}
|
|
|
|
|
|
//刷新父窗口上的父节点
|
|
|
var jsonRespose = new JsonResponse
|
|
|
{
|
|
|
Success = result.Success,
|
|
|
Message = result.Message,
|
|
|
Data = MsChFeeAutoDuiDAL.GetData("GID='" + head.GID + "'")
|
|
|
};
|
|
|
|
|
|
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
|
|
|
}
|
|
|
public ContentResult MakeShen(string data)
|
|
|
{
|
|
|
var _head = JsonConvert.Deserialize<MsChFeeAutoDuimb>(data);
|
|
|
var head = MsChFeeAutoDuiDAL.GetData("GID='" + _head.GID + "'");
|
|
|
|
|
|
var headShen = new ChPayapplication();
|
|
|
headShen.GID = Guid.NewGuid().ToString();
|
|
|
headShen.COMPANYID = CookieConfig.GetCookie_CompanyId(Request);
|
|
|
headShen.APPLICANT = CookieConfig.GetCookie_UserId(Request);
|
|
|
headShen.APPLYTIME = DateTime.Now;
|
|
|
headShen.ENTERTIME = DateTime.Now;
|
|
|
headShen.DbOperationType = DbOperationType.DbotIns;
|
|
|
headShen.PAYABLETIME = DateTime.Now.ToString("yyyy-MM-dd");
|
|
|
var billnoset = MsSysBillNoSetDAL.GetData("OPLBNAME='付费申请'", Convert.ToString(Session["COMPANYID"]));
|
|
|
if (billnoset.BILLTYPE != "")
|
|
|
headShen.BILLNO = MsSysBillNoSetDAL.GetBillNo(billnoset, headShen.PAYABLETIME.ToString().Trim(), headShen.APPLYTIME.ToString());
|
|
|
else
|
|
|
headShen.BILLNO = PubSysDAL.GetBillNo("0303");
|
|
|
headShen.CUSTOMERNAME = head.CUSTOMERNAME;
|
|
|
var modb = new ModelObjectDB();
|
|
|
DBResult result = modb.Save(headShen);
|
|
|
var DetailList = MsChFeeAutoDuiDAL.GetBodyList(" D.BSNO='" + head.GID + "' ");
|
|
|
var _condition = "";
|
|
|
var condition = "f.BSNO in (select bsno from v_op_bill b where EXISTS (select 1 from CH_FEE_AutoDuiDetail fd where (isnull(fd.ISOK,0)=1 or (fd.L_RMBAMOUNT<=fd.RMBAMOUNT AND fd.L_USDAMOUNT<=fd.USDAMOUNT)) and (b.MBLNO=fd.MBLNO or b.HBLNO=fd.MBLNO) AND ISNULL(fd.MBLNO,'')<>'' and fd.bsno='"
|
|
|
+ head.GID + "')) and f.customername='" + head.CUSTOMERNAME + "' and f.amount<>f.settlement ";
|
|
|
if (head.FEEDC != "0" && head.FEEDC.Trim() != "")
|
|
|
{
|
|
|
_condition = _condition + " and f.FEETYPE=" + head.FEEDC;
|
|
|
}
|
|
|
|
|
|
|
|
|
if (head.CURR != "")
|
|
|
{
|
|
|
_condition = _condition + " and f.CURRENCY='" + head.CURR + "'";
|
|
|
}
|
|
|
if (head.FSTATUS == "1"|| head.FSTATUS == "3")
|
|
|
{
|
|
|
_condition = _condition + " AND (F.FEESTATUS=0 or F.FEESTATUS=8 or F.FEESTATUS=9)";
|
|
|
}
|
|
|
else if (head.FSTATUS == "2")
|
|
|
{
|
|
|
_condition = _condition + " AND (F.FEESTATUS!=0 and F.FEESTATUS!=8 and F.FEESTATUS!=9) ";
|
|
|
}
|
|
|
if (head.FSTATUS == "3" || head.FSTATUS == "4")
|
|
|
{
|
|
|
_condition = _condition + " AND (f.AMOUNT-isnull(f.SETTLEMENT,0)-isnull(f.ORDERAMOUNT,0)+isnull(f.ORDERSETTLEMENT,0))<>0 ";
|
|
|
}
|
|
|
|
|
|
|
|
|
if (head.SALECORP != "")
|
|
|
{
|
|
|
_condition = _condition + " AND F.SALECORP='" + head.SALECORP + "' ";
|
|
|
}
|
|
|
if (head.FEEDUITYPE != "") {
|
|
|
if (head.FEEDUITYPECONDIT == "不等于")
|
|
|
{
|
|
|
_condition = _condition + " and not EXISTS (select 1 from code_fee c where c.[NAME]=f.FEENAME and c.DUITYPE='"+head.FEEDUITYPE+"') ";
|
|
|
}
|
|
|
else {
|
|
|
_condition = _condition + " and EXISTS (select 1 from code_fee c where c.[NAME]=f.FEENAME and c.DUITYPE='" + head.FEEDUITYPE + "') ";
|
|
|
}
|
|
|
}
|
|
|
condition = condition + _condition;
|
|
|
result = ChpayapplicationDAL.AddBill(headShen.BILLNO, headShen.CUSTOMERNAME,"", condition, null, Convert.ToString(Session["COMPANYID"]), Convert.ToString(Session["USERID"]),false);
|
|
|
var NOkList = DetailList.FindAll(t => !String.IsNullOrEmpty(t.B_BSNO)&& t.ISOK != "1" && ((Convert.ToDecimal(t.L_RMBAMOUNT)>Convert.ToDecimal(t.RMBAMOUNT))||(Convert.ToDecimal(t.L_USDAMOUNT)>Convert.ToDecimal(t.USDAMOUNT))));
|
|
|
if (NOkList != null) {
|
|
|
var feedolist = new List<Areas.Account.Models.ChfeeDetail.ChFeeDetail>();
|
|
|
foreach (var enumValue in NOkList)
|
|
|
{
|
|
|
var econdition = " f.customername='" + head.CUSTOMERNAME + "' and EXISTS (SELECT 1 FROM V_OP_BILL B WHERE B.BSNO=f.BSNO AND (b.MBLNO='" + enumValue.MBLNO+"' or b.HBLNO='"+enumValue.MBLNO+"')) ";
|
|
|
econdition = econdition + _condition;
|
|
|
var feelist = ChpayapplicationDAL.GetFeeDetailList(econdition, Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"]));
|
|
|
decimal blrmbttl = 0; decimal blusdttl = 0;
|
|
|
decimal mrmb = 0;decimal musd = 0;
|
|
|
if (Convert.ToDecimal(enumValue.L_RMBAMOUNT) > Convert.ToDecimal(enumValue.RMBAMOUNT))
|
|
|
{ mrmb = Convert.ToDecimal(enumValue.RMBAMOUNT); } else { mrmb = Convert.ToDecimal(enumValue.L_RMBAMOUNT); };
|
|
|
if (Convert.ToDecimal(enumValue.L_USDAMOUNT) > Convert.ToDecimal(enumValue.USDAMOUNT))
|
|
|
{ musd = Convert.ToDecimal(enumValue.USDAMOUNT); }
|
|
|
else { musd = Convert.ToDecimal(enumValue.L_USDAMOUNT); };
|
|
|
feelist.OrderBy(x => x.BalAmount);
|
|
|
feelist.ForEach(i =>
|
|
|
{
|
|
|
if (i.Currency == "RMB"&&i.BalAmount!=0) {
|
|
|
if ((blrmbttl + i.BalAmount) <= mrmb)
|
|
|
{
|
|
|
i.DoAmount = i.BalAmount;
|
|
|
i.StlAmount = i.BalAmount;
|
|
|
feedolist.Add(i);
|
|
|
blrmbttl = blrmbttl + i.BalAmount;
|
|
|
}
|
|
|
else {
|
|
|
if (blrmbttl<mrmb)
|
|
|
{
|
|
|
i.DoAmount = mrmb - blrmbttl;
|
|
|
i.StlAmount = mrmb - blrmbttl;
|
|
|
feedolist.Add(i);
|
|
|
blrmbttl = mrmb;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
if (i.Currency == "USD" && i.BalAmount != 0)
|
|
|
{
|
|
|
if ((blusdttl + i.BalAmount) <= musd)
|
|
|
{
|
|
|
i.DoAmount = i.BalAmount;
|
|
|
i.StlAmount = i.BalAmount;
|
|
|
feedolist.Add(i);
|
|
|
blusdttl = blusdttl + i.BalAmount;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
if (blusdttl < musd)
|
|
|
{
|
|
|
i.DoAmount = musd - blusdttl;
|
|
|
i.StlAmount = musd - blusdttl;
|
|
|
feedolist.Add(i);
|
|
|
blusdttl = musd;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
});
|
|
|
}
|
|
|
if (feedolist != null) {
|
|
|
|
|
|
result=ChpayapplicationDAL.AddDetail(headShen.BILLNO, feedolist,"", Convert.ToString(Session["COMPANYID"]),head.SALECORP);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (result.Success)
|
|
|
{ ChpayapplicationDAL.p_update_Amount(headShen.BILLNO); }
|
|
|
|
|
|
var jsonRespose = new JsonResponse
|
|
|
{
|
|
|
Success = result.Success,
|
|
|
Message = result.Message,
|
|
|
Data = MsChFeeAutoDuiDAL.GetData("GID='" + head.GID + "'")
|
|
|
};
|
|
|
|
|
|
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
|
|
|
}
|
|
|
|
|
|
[HttpPost]
|
|
|
public ContentResult File()
|
|
|
{
|
|
|
var jsonRespose = new JsonResponse { Success = false, Message = "" };
|
|
|
|
|
|
if (Request.Files.Count != 1)
|
|
|
{
|
|
|
jsonRespose.Success = false;
|
|
|
jsonRespose.Message = "请选择上传的文件";
|
|
|
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
|
|
|
}
|
|
|
|
|
|
var file = Request.Files["file"];
|
|
|
var BSNO = Request.Form["GID"].ToString().Trim();
|
|
|
var CUSTOMERNAME = Request.Form["CUSTOMERNAME"].ToString().Trim();
|
|
|
var FEETYPE = Request.Form["FEETYPE"].ToString().Trim();
|
|
|
|
|
|
|
|
|
|
|
|
if (file == null)
|
|
|
{
|
|
|
jsonRespose.Success = false;
|
|
|
jsonRespose.Message = "上传文件发生未知错误,请重新上传";
|
|
|
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
|
|
|
}
|
|
|
|
|
|
var path = Server.MapPath("../../UploadFiles/CtnTkDetail");
|
|
|
|
|
|
if (!Directory.Exists(path))
|
|
|
{
|
|
|
Directory.CreateDirectory(path);
|
|
|
}
|
|
|
|
|
|
var size = file.ContentLength;
|
|
|
var name = Path.GetFileName(file.FileName);
|
|
|
//var bsno = Request.Form["bsno"];
|
|
|
|
|
|
var usercode = CookieConfig.GetCookie_UserCode(Request);
|
|
|
string filename = path + "\\" + usercode + DateTime.Now.ToString("yyyyMMddHHmmssfff") + name;
|
|
|
|
|
|
if (System.IO.File.Exists(filename))
|
|
|
{
|
|
|
System.IO.File.Delete(filename);
|
|
|
}
|
|
|
file.SaveAs(filename);
|
|
|
|
|
|
if (!System.IO.File.Exists(filename))
|
|
|
{
|
|
|
jsonRespose.Success = false;
|
|
|
jsonRespose.Message = "上传的Excel不包含数据01";
|
|
|
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
|
|
|
}
|
|
|
|
|
|
|
|
|
try
|
|
|
{
|
|
|
string ext = Path.GetExtension(file.FileName).ToLower();
|
|
|
if (ext != ".xls" && ext != ".xlsx")
|
|
|
{
|
|
|
jsonRespose.Success = false;
|
|
|
jsonRespose.Message = "上传的文件不是Excel文件";
|
|
|
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
|
|
|
}
|
|
|
var strMsg = "";
|
|
|
DataTable table = ExcelHelper.ExcelToDatatable(file.InputStream, ext, out strMsg);
|
|
|
if (!string.IsNullOrEmpty(strMsg))
|
|
|
{
|
|
|
jsonRespose.Success = false;
|
|
|
jsonRespose.Message = strMsg;
|
|
|
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
|
|
|
}
|
|
|
|
|
|
if (table.Rows.Count > 0)
|
|
|
{
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
jsonRespose.Success = false;
|
|
|
jsonRespose.Message = "excel无数据!";
|
|
|
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
|
|
|
}
|
|
|
|
|
|
|
|
|
var message = string.Empty;
|
|
|
List<CH_FEE_AutoDuiDetailmb> headList;
|
|
|
|
|
|
//if (customerFieldName == "委托单位")
|
|
|
//{
|
|
|
var InsertCount = 0;
|
|
|
var UpdateCount = 0;
|
|
|
var msg = "";
|
|
|
//ImportExcelData ( HttpRequestBase request, DataTable table, out string msg,out Int32 InsertCount, out Int32 UpdateCount, string AutoDui_GID, string CUSTOMERNAME, out List<CH_FEE_AutoDuiDetailmb> headList )
|
|
|
var userid = Session["USERID"].ToString();
|
|
|
var username = Session["SHOWNAME"].ToString();
|
|
|
var companyid = Session["COMPANYID"].ToString();
|
|
|
|
|
|
var isSucess = MsChFeeAutoDuiDAL.ImportExcelData(Request, table, out msg, out InsertCount, out UpdateCount, BSNO, CUSTOMERNAME, FEETYPE, out headList, userid, username, companyid);
|
|
|
if (!isSucess)
|
|
|
{
|
|
|
jsonRespose.Success = false;
|
|
|
jsonRespose.Message = message;
|
|
|
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
|
|
|
|
|
|
}
|
|
|
|
|
|
var json = JsonConvert.Serialize(new
|
|
|
{
|
|
|
success = true,
|
|
|
Message = "上传成功,共处理" + Convert.ToString(headList.Count) + "条记录,其中新增" + Convert.ToString(InsertCount)
|
|
|
+ "个,更新" + Convert.ToString(UpdateCount) + "个。" + msg,
|
|
|
data = ""
|
|
|
});
|
|
|
return new ContentResult() { Content = json };
|
|
|
}
|
|
|
catch (Exception e)
|
|
|
{
|
|
|
|
|
|
jsonRespose.Success = false;
|
|
|
jsonRespose.Message = "读取Excel文件出错,请确认文件正确性" + e.Message;
|
|
|
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
public ContentResult File2()
|
|
|
{
|
|
|
var jsonRespose = new JsonResponse { Success = false, Message = "" };
|
|
|
|
|
|
if (Request.Files.Count != 1)
|
|
|
{
|
|
|
jsonRespose.Success = false;
|
|
|
jsonRespose.Message = "请选择上传的文件";
|
|
|
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
|
|
|
}
|
|
|
|
|
|
var file = Request.Files["file"];
|
|
|
var BSNO = Request.Form["GID"].ToString().Trim();
|
|
|
var CUSTOMERNAME = Request.Form["CUSTOMERNAME"].ToString().Trim();
|
|
|
var FEETYPE = Request.Form["FEETYPE"].ToString().Trim();
|
|
|
|
|
|
|
|
|
|
|
|
if (file == null)
|
|
|
{
|
|
|
jsonRespose.Success = false;
|
|
|
jsonRespose.Message = "上传文件发生未知错误,请重新上传";
|
|
|
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
|
|
|
}
|
|
|
|
|
|
var path = Server.MapPath("../../UploadFiles/CtnTkDetail");
|
|
|
|
|
|
if (!Directory.Exists(path))
|
|
|
{
|
|
|
Directory.CreateDirectory(path);
|
|
|
}
|
|
|
|
|
|
var size = file.ContentLength;
|
|
|
var name = Path.GetFileName(file.FileName);
|
|
|
//var bsno = Request.Form["bsno"];
|
|
|
|
|
|
var usercode = CookieConfig.GetCookie_UserCode(Request);
|
|
|
string filename = path + "\\" + usercode + DateTime.Now.ToString("yyyyMMddHHmmssfff") + name;
|
|
|
|
|
|
if (System.IO.File.Exists(filename))
|
|
|
{
|
|
|
System.IO.File.Delete(filename);
|
|
|
}
|
|
|
file.SaveAs(filename);
|
|
|
|
|
|
if (!System.IO.File.Exists(filename))
|
|
|
{
|
|
|
jsonRespose.Success = false;
|
|
|
jsonRespose.Message = "上传的Excel不包含数据01";
|
|
|
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
|
|
|
}
|
|
|
var ExcelExt = "";
|
|
|
try
|
|
|
{
|
|
|
ExcelExt = WebConfigurationManager.AppSettings["ExcelExt"].ToString();
|
|
|
}
|
|
|
catch
|
|
|
{
|
|
|
|
|
|
}
|
|
|
if (ExcelExt == "" || ExcelExt == null) ExcelExt = "Excel 8.0;HDR=Yes;IMEX=1";
|
|
|
var errostr = "";
|
|
|
List<string> sheets = ExcelSheetName(filename, ExcelExt, out errostr);
|
|
|
if (sheets.Count == 0)
|
|
|
{
|
|
|
jsonRespose.Success = false;
|
|
|
jsonRespose.Message = "上传的Excel不包含数据02" + errostr;
|
|
|
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
|
|
|
}
|
|
|
|
|
|
try
|
|
|
{
|
|
|
var sheetname = sheets[0];
|
|
|
//var sheetname ="Sheet1";
|
|
|
string excelConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filename +
|
|
|
";Extended Properties=" + ExcelExt;
|
|
|
if (filename.ToLower().IndexOf(".xlsx") > 0)
|
|
|
{
|
|
|
excelConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + filename +
|
|
|
";Extended Properties=\"Excel 12.0 Xml;IMEX=1;HDR=Yes\"";
|
|
|
|
|
|
}
|
|
|
OleDbDataAdapter oada = new OleDbDataAdapter("select * from [" + sheetname + "A1:X]", excelConn);
|
|
|
DataSet ds = new DataSet();
|
|
|
oada.Fill(ds);
|
|
|
|
|
|
if (ds.Tables.Count == 0)
|
|
|
{
|
|
|
jsonRespose.Success = false;
|
|
|
jsonRespose.Message = "上传的Excel不包含数据03";
|
|
|
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
|
|
|
}
|
|
|
|
|
|
var table = ds.Tables[0];
|
|
|
if (table.Rows.Count == 0)
|
|
|
{
|
|
|
jsonRespose.Success = false;
|
|
|
jsonRespose.Message = "上传的Excel不包含数据04";
|
|
|
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
|
|
|
}
|
|
|
|
|
|
|
|
|
var message = string.Empty;
|
|
|
List<CH_FEE_AutoDuiDetailmb> headList;
|
|
|
|
|
|
//if (customerFieldName == "委托单位")
|
|
|
//{
|
|
|
var InsertCount = 0;
|
|
|
var UpdateCount = 0;
|
|
|
var msg = "";
|
|
|
//ImportExcelData ( HttpRequestBase request, DataTable table, out string msg,out Int32 InsertCount, out Int32 UpdateCount, string AutoDui_GID, string CUSTOMERNAME, out List<CH_FEE_AutoDuiDetailmb> headList )
|
|
|
var userid = Session["USERID"].ToString();
|
|
|
var username = Session["SHOWNAME"].ToString();
|
|
|
var companyid = Session["COMPANYID"].ToString();
|
|
|
|
|
|
var isSucess = MsChFeeAutoDuiDAL.ImportExcelData(Request, table, out msg, out InsertCount, out UpdateCount, BSNO, CUSTOMERNAME, FEETYPE, out headList, userid, username, companyid);
|
|
|
if (!isSucess)
|
|
|
{
|
|
|
jsonRespose.Success = false;
|
|
|
jsonRespose.Message = message;
|
|
|
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
|
|
|
|
|
|
}
|
|
|
|
|
|
var json = JsonConvert.Serialize(new
|
|
|
{
|
|
|
success = true,
|
|
|
Message = "上传成功,共处理" + Convert.ToString(headList.Count) + "条记录,其中新增" + Convert.ToString(InsertCount)
|
|
|
+ "个,更新" + Convert.ToString(UpdateCount) + "个。" + msg,
|
|
|
data = ""
|
|
|
});
|
|
|
return new ContentResult() { Content = json };
|
|
|
}
|
|
|
catch (Exception e)
|
|
|
{
|
|
|
|
|
|
jsonRespose.Success = false;
|
|
|
jsonRespose.Message = "读取Excel文件出错,请确认文件正确性" + e.Message;
|
|
|
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
public List<string> ExcelSheetName ( string filepath,string ExcelExt,out string errostr)
|
|
|
{
|
|
|
var al = new List<string>();
|
|
|
|
|
|
try
|
|
|
{
|
|
|
string strConn;
|
|
|
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filepath + ";Extended Properties="+ ExcelExt;
|
|
|
if (filepath.ToLower().IndexOf(".xlsx") > 0)
|
|
|
{
|
|
|
strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + filepath +
|
|
|
";Extended Properties=\"Excel 12.0 Xml;HDR=Yes\"";
|
|
|
|
|
|
}
|
|
|
OleDbConnection conn = new OleDbConnection(strConn);
|
|
|
conn.Open();
|
|
|
System.Data.DataTable sheetNames = conn.GetOleDbSchemaTable
|
|
|
(System.Data.OleDb.OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" });
|
|
|
conn.Close();
|
|
|
|
|
|
foreach (DataRow dr in sheetNames.Rows)
|
|
|
{
|
|
|
al.Add(dr[2].ToString());
|
|
|
}
|
|
|
}
|
|
|
catch (Exception e)
|
|
|
{
|
|
|
errostr = e.Message;
|
|
|
return new List<string>();
|
|
|
}
|
|
|
errostr = "";
|
|
|
return al;
|
|
|
}
|
|
|
|
|
|
|
|
|
public ContentResult Delete ( string data, string USERID )
|
|
|
{
|
|
|
var _head = JsonConvert.Deserialize<MsChFeeAutoDuimb>(data);
|
|
|
|
|
|
var head = MsChFeeAutoDuiDAL.GetData("GID='"+_head.GID+"'");
|
|
|
|
|
|
if (head.DUINO != "")
|
|
|
{
|
|
|
var jsonRespose1 = new JsonResponse { Success = false, Message = "已经生成了对账单,不能删除" };
|
|
|
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose1) };
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
|
|
|
var modb = new ModelObjectDB();
|
|
|
DBResult result = modb.Delete(head, "delete from CH_FEE_AutoDuiDetail where BSNO='" + head.GID + "'");
|
|
|
//var ContractNo = head.ContractNo;
|
|
|
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
|
|
|
|
|
|
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
#region 参照部分
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|