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/MsOpPlanController.cs

373 lines
16 KiB
C#

2 years ago
using System;
using System.Linq;
using System.Web.Mvc;
using DSWeb.MvcShipping.DAL.MsOpPlanDAL;
using DSWeb.MvcShipping.Models.MsOpPlan;
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.Models;
using DSWeb.Attributes;
using DSWeb.MvcShipping.Models.MsSysBillNoSet;
using DSWeb.MvcShipping.DAL.MsSysBillNoSet;
using System.IO;
using System.Data;
using System.Data.OleDb;
using DSWeb.MvcShipping.DAL.MsInfoClient;
using DSWeb.MvcShipping.DAL.MsSysParamSet;
using System.Web.Configuration;
using DSWeb.SoftMng.DAL.SoftSysTable;
using DSWeb.Areas.SysMng.DAL.SysUser;
using DSWeb.MvcShipping.DAL.MsCodeOpTemplate;
using DSWeb.MvcShipping.DAL.ChMonthCloseDAL;
using DSWeb.MvcShipping.DAL.MsChFeeDAL;
using DSWeb.Areas.MvcShipping.Helper;
namespace DSWeb.MvcShipping.Controllers
{
[JsonRequestBehavior]
public class MsOpPlanController : Controller
{
public ActionResult Index()
{
return View();
}
public ContentResult GetDataList(int start, int limit, string sort, string condition)
{
var issale = MsBaseInfoDAL.GetUserModuleEnable("modOpPlanSale", Convert.ToString(Session["USERID"]));
var dataList = MsOpPlanDAL.GetDataList(start, limit, condition, Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"]), issale, sort);
int count = MsOpPlanDAL.getTotalCount(condition, CookieConfig.GetCookie_UserId(Request), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"]), issale);
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = count, data = dataList.ToList() });
return new ContentResult() { Content = json };
}
public ContentResult GetDataListStr(string sort, string condition)
{
var issale = MsBaseInfoDAL.GetUserModuleEnable("modOpPlanSale", Convert.ToString(Session["USERID"]));
var dataListStr = MsOpPlanDAL.GetDataListStr(condition, Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"]), issale, sort);
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", data = dataListStr });
return new ContentResult() { Content = json };
}
public ContentResult GetData(string handle, string condition)
{
MsOpPlan head = null;
if (handle == "edit")
{
head = MsOpPlanDAL.GetData(condition);
}
if (head == null)
{
head = new MsOpPlan();
//head.BSTYPE = "2";
}
var json = JsonConvert.Serialize(
new { Success = true, Message = "查询成功", data = head });
return new ContentResult() { Content = json };
}
public ContentResult Save(string opstatus, string data, string data2)
{
if (Convert.ToString(Session["COMPANYID"]).ToString().Trim() == "" || Convert.ToString(Session["USERID"]).ToString().Trim() == "" || Convert.ToString(Session["CODENAME"]).ToString().Trim() == "" || Convert.ToString(Session["SHOWNAME"]).ToString().Trim() == "" || Convert.ToString(Session["DEPTNAME"]).ToString().Trim() == "")
{
var jsonRespose2 = new JsonResponse { Success = false, Message = "登录超时,请退出系统重新登录!" };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose2) };
}
//
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
var dataall = data.Replace("}", ",") + data2.Replace("{", "");
var headData = JsonConvert.Deserialize<MsOpPlan>(dataall);
var isPost = true;
var errorstr = "";
var iscreatecustno = false;
//分公司代码
if (headData.CORPID == "" || headData.CORPID == null)
{
headData.CORPID = Convert.ToString(Session["COMPANYID"]);
}
//分公司代码
if (headData.BSNO == "" || headData.BSNO == null)
{
headData.BSNO = "topother" + Guid.NewGuid().ToString().Replace("-","");
}
string rq = T_ALL_DA.GetStrSQL("rq", "select getdate() as rq");
//
if (opstatus == "add")
{
headData.DbOperationType = DbOperationType.DbotIns;
}
else if (opstatus == "edit")
{
headData.DbOperationType = DbOperationType.DbotUpd;
headData.ModelUIStatus = "E";
//
}
else
{
headData.DbOperationType = DbOperationType.DbotDel;
}
if (isPost)
{
var modb = new ModelObjectDB();
DBResult result = modb.Save(headData);
var BSNO = headData.BSNO;
if (result.Success == true)
{
//--result = MsOpOtherDAL.SaveDetail(headData, bodyList, Convert.ToString(Session["USERID"]));
}
else
{
MsSysBillNoSetDAL.DeleteBsNo(headData.CUSTNO);
}
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
Data = MsOpPlanDAL.GetData("BSNO='" + BSNO + "'")
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
else {
if (iscreatecustno == true)
MsSysBillNoSetDAL.DeleteBsNo(headData.CUSTNO);
var jsonRespose = new JsonResponse { Success = false, Message =errorstr };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
}
public ContentResult DeleteList(string data)
{
if (Convert.ToString(Session["COMPANYID"]).ToString().Trim() == "" || Convert.ToString(Session["USERID"]).ToString().Trim() == "" || Convert.ToString(Session["CODENAME"]).ToString().Trim() == "" || Convert.ToString(Session["SHOWNAME"]).ToString().Trim() == "" || Convert.ToString(Session["DEPTNAME"]).ToString().Trim() == "")
{
var jsonRespose2 = new JsonResponse { Success = false, Message = "登录超时,请退出系统重新登录!" };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose2) };
}
//
DBResult result = new DBResult();
var headList = JsonConvert.Deserialize<List<MsOpPlan>>(data);
if (headList != null)
{
foreach (var enumValue in headList)
{
var modb = new ModelObjectDB();
result = modb.Delete(enumValue);
}
}
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult SaveToOther(string body)
{
var bodylist = JsonConvert.Deserialize<List<MsOpPlan>>(body);
var result = MsOpPlanDAL.SaveToOther(bodylist,Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"]));
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult ChangeStatus(string data,string bsstatus,string accdate)
{
DBResult result = new DBResult();
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
var bodylist = JsonConvert.Deserialize<List<MsOpPlan>>(data);
if (bodylist != null) {
foreach (var headdata in bodylist) {
if (bsstatus == "延期")
{
var blUpSQL = " update op_plan set BSSTATUS='" + bsstatus + "',ACCDATE='"+accdate+"',OLDACCDATE='"+headdata.ACCDATE+ "',MODIFIEDUSER='"+ Convert.ToString(Session["SHOWNAME"]) + "',MODIFIEDTIME='"+DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss")+"' where BSNO='" + headdata.BSNO + "' ";
bool bl = T_ALL_DA.GetExecuteSqlCommand(blUpSQL);
}
else
{
var blUpSQL = " update op_plan set BSSTATUS='" + bsstatus + "',MODIFIEDUSER='" + Convert.ToString(Session["SHOWNAME"]) + "',MODIFIEDTIME='" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss") + "' where BSNO='" + headdata.BSNO + "' ";
bool bl = T_ALL_DA.GetExecuteSqlCommand(blUpSQL);
}
}
}
var jsonRespose = new JsonResponse { Success =true, Message ="更新完成!" };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult Modify(string BSNO, string AMOUNT, string REMARK,string OTREMARK)
{
DBResult result = new DBResult();
if (string.IsNullOrEmpty(AMOUNT)) AMOUNT = "0";
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
var blUpSQL = " update op_plan set AMOUNT='" + AMOUNT + "',REMARK='" + REMARK + "',OTREMARK='" + OTREMARK + "',MODIFIEDUSER='" + Convert.ToString(Session["SHOWNAME"]) + "',MODIFIEDTIME='" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss") + "' where BSNO='" + BSNO + "' ";
bool bl = T_ALL_DA.GetExecuteSqlCommand(blUpSQL);
var jsonRespose = new JsonResponse { Success = true, Message = "更新完成!" };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult ToSale(string body)
{
DBResult result = new DBResult();
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
var bodylist = JsonConvert.Deserialize<List<MsOpPlan>>(body);
if (bodylist != null)
{
foreach (var headdata in bodylist)
{
var blUpSQL = " update op_plan set TOSALE=1,MODIFIEDUSER='" + Convert.ToString(Session["SHOWNAME"]) + "',MODIFIEDTIME='" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss") + "' where BSNO='" + headdata.BSNO + "' ";
bool bl = T_ALL_DA.GetExecuteSqlCommand(blUpSQL);
var mailbody = headdata.INPUTBY + " 转交收费计划编号:" + headdata.CUSTNO + Environment.NewLine
+ "客户名称:" + headdata.CUSTOMERNAME + " 备注:" + headdata.REMARK+" 请处理!";
DingTalkHelper.SendMessage(headdata.SALE, mailbody);
}
}
var jsonRespose = new JsonResponse { Success = true, Message = "更新完成!" };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
[HttpPost]
public ContentResult ImpExcel()
{
if (Convert.ToString(Session["COMPANYID"]).ToString().Trim() == "" || Convert.ToString(Session["USERID"]).ToString().Trim() == "" || Convert.ToString(Session["CODENAME"]).ToString().Trim() == "" || Convert.ToString(Session["SHOWNAME"]).ToString().Trim() == "" || Convert.ToString(Session["DEPTNAME"]).ToString().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["DsLoadExcel"];
if (file == null)
{
jsonRespose.Success = false;
jsonRespose.Message = "上传文件发生未知错误,请重新上传";
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
if (Convert.ToString(Session["COMPANYID"]).ToString().Trim() == "" || Convert.ToString(Session["USERID"]).ToString().Trim() == "" || Convert.ToString(Session["CODENAME"]).ToString().Trim() == "" || Convert.ToString(Session["SHOWNAME"]).ToString().Trim() == "" || Convert.ToString(Session["DEPTNAME"]).ToString().Trim() == "")
{
var jsonRespose2 = new JsonResponse { Success = false, Message = "登录超时,请退出系统重新登录!" };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose2) };
}
string ext = Path.GetExtension(file.FileName).ToLower();
if (ext == ".asp" || ext == ".aspx")
{
jsonRespose.Success = false;
jsonRespose.Message = "不允许上传ASP或ASPX文件";
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
var path = Server.MapPath("../../UploadFiles/ImpBsExcel");
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) };
}
try
{
if (ext != ".xls" && ext != ".xlsx")
{
jsonRespose.Success = false;
jsonRespose.Message = "上传的文件不是Excel文件";
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
var strMsg = "";
System.Data.DataTable table = ExcelHelper.ReadStreamToDataTable(file.InputStream, 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 result = new DBResult();
//if (customerFieldName == "委托单位")
//{
var userid = Session["USERID"].ToString();
var username = Session["SHOWNAME"].ToString();
var companyid = Session["COMPANYID"].ToString();
result = MsOpPlanDAL.ImpOpPlan(table, userid, username, companyid);
var json = JsonConvert.Serialize(new
{
success = result.Success,
Message = result.Message
});
return new ContentResult() { Content = json };
}
catch (Exception e)
{
jsonRespose.Success = false;
jsonRespose.Message = "读取Excel文件出错请确认文件正确性" + e.Message;
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
}
}
}