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.

371 lines
19 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.Data;
using System.Linq;
using System.Web.Mvc;
using DSWeb.MvcShipping.DAL.MsCtBankStatementDAL;
using DSWeb.MvcShipping.Models.MsCtBankStatement;
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.Data.OleDb;
using System.IO;
using System.Text;
using System.Web.UI.MobileControls;
namespace DSWeb.MvcShipping.Controllers
{
[JsonRequestBehavior]
public class MsCtBankStatementController : Controller
{
public ActionResult Index()
{
return View();
}
public ActionResult Edit()
{
return View();
}
#region 查询
public ContentResult GetDataList(int start, int limit, string sort, string condition)
{
var dataList = MsCtBankStatementDAL.GetDataList(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 };
}
public ContentResult GetData(string handle, string condition)
{
MsCtBankStatement head = null;
head = MsCtBankStatementDAL.GetData(condition, Convert.ToString(Session["COMPANYID"]), Convert.ToString(Session["USERID"]));
var json = JsonConvert.Serialize(
new { Success = true, Message = "查询成功", data = head });
return new ContentResult() { Content = json };
}
public ContentResult GetDetailList(string condition)
{
var dataList = MsCtBankStatementDAL.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 };
}
#endregion
#region 明细表保存
public ContentResult SaveEdit(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 strCtACCDATE = BasicDataRefDAL.GetCtACCDATE(Convert.ToString(Session["USERID"]));
string strCtSTARTGID = BasicDataRefDAL.GetCtSTARTGID(Convert.ToString(Session["USERID"]));
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
var bodyList = JsonConvert.Deserialize<List<MsCtBankStatement>>(body.Replace("T00:00:00", ""));
//var DelBodyList = JsonConvert.Deserialize<List<MsCtBankStatement>>(DelBody.Replace("T00:00:00", ""));
var isPost = true;
var errorstr = "";
string sYear = "";
string sMonth = "";
string sDay = "";
//
if (isPost)
{
//删除列表中的多余数据
//if (DelBodyList != null)
//{
// foreach (var enumValue in DelBodyList)
// {
// MsCtBankStatementDAL.DeleteDetail(enumValue, Convert.ToString(Session["COMPANYID"]), Convert.ToString(Session["USERID"]));
// }
//}
//添加、修改数据
DBResult result = new DBResult();
if (bodyList != null)
{
foreach (var enumValue in bodyList)
{
MsCtBankStatement headRow = new MsCtBankStatement();
#region 默认值
headRow.ISINITIAL = enumValue.ISINITIAL;//是否期初
headRow.ACCGID = enumValue.ACCGID == null ? "" : enumValue.ACCGID.ToString().Trim();//科目GID
headRow.FCYNO = enumValue.FCYNO == null ? "" : enumValue.FCYNO.ToString().Trim();//外币编号usd
DateTime _VOUDATE = enumValue.VOUDATE;
sYear = _VOUDATE.Year.ToString();
sMonth = _VOUDATE.Month.ToString();
sDay = _VOUDATE.Day.ToString();
if (sMonth.Length == 1)
{
sMonth = "0" + sMonth;
}
if (sDay.Length == 1)
{
sDay = "0" + sDay;
}
headRow.VOUDATE = DateTime.Parse(sYear + "-" + sMonth + "-" + sDay + " 23:59:00.000");//结算日期
int iITEMNO = int.Parse(T_ALL_DA.GetStrSQL("iITEMNO", "select isnull((select top 1 isnull(ITEMNO,0) as iITEMNO from ct_bank_statement where STARTGID='" + strCtSTARTGID + "' and convert(varchar,VOUDATE,23)='" + (sYear + "-" + sMonth + "-" + sDay) + "' order by VOUDATE desc,convert(decimal(10),ITEMNO) desc),0) as iITEMNO"));
headRow.ITEMNO = iITEMNO+1;//当日序号
headRow.ACCDATE = enumValue.ACCDATE == null ? "" : enumValue.ACCDATE.ToString().Trim();//会计期间
if (headRow.ISINITIAL)
{
headRow.ACCDATE = sYear + "-" + sMonth;//会计期间
}
headRow.SETTLETYPE = enumValue.SETTLETYPE;//结算方式
headRow.BILLNO = enumValue.BILLNO == null ? "" : enumValue.BILLNO.ToString().Trim();//结算号
headRow.DC = enumValue.DC == null ? "" : enumValue.DC.ToString().Trim();//余额方向
headRow.DR = enumValue.DR;//原币借方金额(互斥)
headRow.CR = enumValue.CR;//原币贷方金额(互斥)
headRow.FCYEXRATE = enumValue.FCYEXRATE;//汇率
headRow.BLC = 0;//原币余额
headRow.EXPLAN = enumValue.EXPLAN == null ? "" : enumValue.EXPLAN.ToString().Trim();//摘要,规则生成
headRow.ENTERED = enumValue.ENTERED == null ? "" : enumValue.ENTERED.ToString().Trim();//经手人
headRow.ISIMPORT = false;//是否导入的数据
headRow.CHECKINGGID = "";//对账GID
headRow.STARTGID = strCtSTARTGID;//账套启用GID
headRow.CORPID = Convert.ToString(Session["COMPANYID"]);//分公司GID
headRow.CREATEUSER = Convert.ToString(Session["USERID"]);//制单人GID
headRow.CREATETIME = DateTime.Now;//创建时间
headRow.MODIFIEDUSER = Convert.ToString(Session["USERID"]);//最后一次更改操作人GID
headRow.MODIFIEDTIME = DateTime.Now;//最后一次更改操作时间
#endregion
if (enumValue.GID.ToString().Trim() == "*")//"add"
{
headRow.GID = Guid.NewGuid().ToString();
headRow.DbOperationType = DbOperationType.DbotIns;
}
else//"edit"
{
headRow.GID = enumValue.GID.ToString().Trim();//唯一编码
headRow.DbOperationType = DbOperationType.DbotUpd;
headRow.ModelUIStatus = "E";
}
var modb = new ModelObjectDB();
result = modb.Save(headRow);
if (result.Message.ToString().IndexOf("插入重复键") > -1)
{
errorstr += "重复数据不再重复插入!";
}
if (result.Success)
{
//更新期初余额
if (headRow.ISINITIAL == true)
{
MsCtBankStatementDAL.onINITIAL(headRow, Convert.ToString(Session["COMPANYID"]), Convert.ToString(Session["USERID"]));
}
else
{
//插入更新余额
MsCtBankStatementDAL.onBLC(headRow, Convert.ToString(Session["COMPANYID"]), Convert.ToString(Session["USERID"]));
}
}
}
}
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
Data = MsCtBankStatementDAL.GetData("convert(varchar,VOUDATE,23)='" + (sYear + "-" + sMonth + "-" + sDay) + "'", Convert.ToString(Session["COMPANYID"]), Convert.ToString(Session["USERID"]))
};
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 = MsCtBankStatementDAL.Delete(gids, Convert.ToString(Session["COMPANYID"]), Convert.ToString(Session["USERID"]));
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
#endregion
#region 导入Excel银行流水单
[HttpPost]
public ContentResult onImportExcelData(string strACCGID, string strFCYNO, string strfile)
{
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) };
}
//
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"];
if (file == null)
{
jsonRespose.Success = false;
jsonRespose.Message = "上传文件发生未知错误,请重新上传";
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
var path = Server.MapPath("../../UploadFiles/Bs");
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
var size = file.ContentLength;
var name = Path.GetFileName(file.FileName);
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) };
}
List<string> sheets = ExcelSheetName(filename);
if (sheets.Count == 0)
{
jsonRespose.Success = false;
jsonRespose.Message = filename + " 上传的Excel不包含数据02";
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
//开始取模板值
string strCtSTARTGID = BasicDataRefDAL.GetCtSTARTGID(Convert.ToString(Session["USERID"]));
T_ALL_DA T_ALL_DA = new T_ALL_DA();
string sSQL = "select top 1 * from ct_bank_deploy where STARTGID='" + strCtSTARTGID + "' and ACCGID='" + strACCGID + "' and FCYNO='" + strFCYNO + "'";
DataSet dsCtBankDeploy = T_ALL_DA.GetAllSQL(sSQL);
if (dsCtBankDeploy != null)
{
if (dsCtBankDeploy.Tables[0].Rows.Count > 0)
{
try
{
var sheetname = sheets[0];
string excelConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filename + ";Extended Properties='Excel 8.0;HDR=No;IMEX=1;'";
sSQL = "select * from [" + sheetname + dsCtBankDeploy.Tables[0].Rows[0]["STARTROW"].ToString() + "]";
OleDbDataAdapter oada = new OleDbDataAdapter(sSQL, 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 || table.Rows.Count == 1)
{
jsonRespose.Success = false;
jsonRespose.Message = "上传的Excel不包含数据04";
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
var InsertCount = 0;
var UpdateCount = 0;
var UnKnowenTruckNo = "";
var iheadList = 0;
var isSucess = MsCtBankStatementDAL.ImportExcelData(strACCGID, strFCYNO, dsCtBankDeploy, table, out InsertCount, out UpdateCount, out UnKnowenTruckNo, out iheadList, Convert.ToString(Session["USERID"]), Convert.ToString(Session["COMPANYID"]));
//
if (System.IO.File.Exists(filename))
{
System.IO.File.Delete(filename);
}
//
if (!isSucess)
{
jsonRespose.Success = false;
jsonRespose.Message = "";
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
var json = JsonConvert.Serialize(new
{
success = true,
Message = "上传成功,共处理" + Convert.ToString(iheadList) + "条流水,其中新增" + Convert.ToString(InsertCount) + "条,跳过" + Convert.ToString(UpdateCount) + "条。" + UnKnowenTruckNo,
data = ""
});
return new ContentResult() { Content = json };
}
catch (Exception)
{
jsonRespose.Success = false;
jsonRespose.Message = "读取Excel文件出错请确认文件正确性";
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
}
else
{
jsonRespose.Success = false;
jsonRespose.Message = "请先设置当前银行的导入模板!";
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
}
else
{
jsonRespose.Success = false;
jsonRespose.Message = "请先设置当前银行的导入模板!";
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
}
public List<string> ExcelSheetName(string filepath)
{
var al = new List<string>();
try
{
string strConn;
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filepath + ";Extended Properties=Excel 8.0;";
OleDbConnection conn = new OleDbConnection(strConn);
conn.Open();
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().Replace("#",".").Replace("'",""));
}
}
catch (Exception)
{
return new List<string>();
}
return al;
}
#endregion
}
}