|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Data;
|
|
|
using System.Data.OleDb;
|
|
|
using System.IO;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
using System.Web.Mvc;
|
|
|
using DSWeb.MvcShipping.Comm.Cookie;
|
|
|
using DSWeb.MvcShipping.Helper;
|
|
|
using DSWeb.MvcShipping.Helper.Repository;
|
|
|
using DSWeb.MvcShipping.Models.MsOpCtnStatus;
|
|
|
using DSWeb.Areas.MvcShipping.DAL;
|
|
|
using DSWeb.Areas.CommMng.DAL;
|
|
|
using DSWeb.Areas.CommMng.Models;
|
|
|
using DSWeb.Areas.RptMng.Comm;
|
|
|
using HcUtility.Comm;
|
|
|
using HcUtility.Core;
|
|
|
using WebSqlHelper;
|
|
|
using DSWeb.MvcShipping.Models.MsOpCtnRepair;
|
|
|
|
|
|
namespace DSWeb.MvcShipping.Controllers
|
|
|
{
|
|
|
|
|
|
[JsonRequestBehavior]
|
|
|
public class MsOpCtnRepairController : Controller
|
|
|
{
|
|
|
|
|
|
public ActionResult Index ( )
|
|
|
{
|
|
|
return View();
|
|
|
}
|
|
|
|
|
|
public ActionResult Edit ( )
|
|
|
{
|
|
|
return View();
|
|
|
}
|
|
|
|
|
|
|
|
|
public ContentResult GetDataList ( int start, int limit, string sort, string condition )
|
|
|
{
|
|
|
int total = 0;
|
|
|
var dataList = MsOpCtnRepairDAL.GetDataList(condition,start,limit,out total,sort);
|
|
|
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = dataList.ToList().Count, data = dataList.ToList() });
|
|
|
return new ContentResult() { Content = json };
|
|
|
}
|
|
|
|
|
|
public ContentResult GetData (string opstatus, string condition )
|
|
|
{
|
|
|
int total = 0;
|
|
|
var datalist = MsOpCtnRepairDAL.GetDataList(condition, 0, 1, out total);
|
|
|
|
|
|
if (datalist.Count>0)
|
|
|
{
|
|
|
var data = datalist[0];
|
|
|
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", data = data });
|
|
|
return new ContentResult() { Content = json };
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
var json = JsonConvert.Serialize(new { Success = true, Message = "查询失败", data = "" });
|
|
|
return new ContentResult() { Content = json };
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
public ContentResult DeleteData ( string xiuxiangdanhao,string userid)
|
|
|
{
|
|
|
var rst = MsOpCtnRepairDAL.DeleteData(xiuxiangdanhao);
|
|
|
var json = JsonConvert.Serialize(new { Success = rst, Message = rst?"删除成功":"删除失败" });
|
|
|
return new ContentResult() { Content = json };
|
|
|
}
|
|
|
|
|
|
public ContentResult Save ( string opstatus, string maindata, string body )
|
|
|
{
|
|
|
var head = JsonConvert.Deserialize<MsOpCtnRepair>(maindata);
|
|
|
var detailsList = JsonConvert.Deserialize<List<MsOpCtnRepairDetails>>(body);
|
|
|
string RepairID = "";
|
|
|
var rst = MsOpCtnRepairDAL.Save(head,detailsList,out RepairID);
|
|
|
var json = JsonConvert.Serialize(new { Success = rst, Message = rst ? "修改成功" : "修改成功" ,Data = RepairID});
|
|
|
return new ContentResult() { Content = json };
|
|
|
}
|
|
|
|
|
|
public ContentResult GetDetailsList ( int start, int limit, string sort, string condition )
|
|
|
{
|
|
|
int total = 0;
|
|
|
var dataList = MsOpCtnRepairDAL.GetDetailsList(condition, start, limit, out total, sort);
|
|
|
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = dataList.ToList().Count, data = dataList.ToList() });
|
|
|
return new ContentResult() { Content = json };
|
|
|
}
|
|
|
|
|
|
public ContentResult LockAndCreateCost (string RepairID,string IsLock)
|
|
|
{
|
|
|
string userid = Session["USERID"] == null ? "" : Session["USERID"].ToString();
|
|
|
bool hasPower = MsOpCtnRepairDAL.CheckLockAndUnlockPower(1, userid);
|
|
|
if (!hasPower)
|
|
|
{
|
|
|
var json = JsonConvert.Serialize(new { Success = true, Message = "该用户没有操作权限!" });
|
|
|
return new ContentResult() { Content = json };
|
|
|
}
|
|
|
bool rst = MsOpCtnRepairDAL.LockAndCreateCost(RepairID, IsLock, userid);
|
|
|
var json2 = JsonConvert.Serialize(new { Success = rst, Message = rst?"操作成功":"操作失败"});
|
|
|
return new ContentResult() { Content = json2 };
|
|
|
}
|
|
|
|
|
|
public ContentResult ImportExcel ()
|
|
|
{
|
|
|
string userid = Session["USERID"] == null ? "" : Session["USERID"].ToString();
|
|
|
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["LoadExcel"];
|
|
|
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/OpCtnRepairExcel");
|
|
|
|
|
|
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 = "上传的Excel不包含数据02";
|
|
|
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
|
|
|
}
|
|
|
|
|
|
try
|
|
|
{
|
|
|
var sheetname = sheets[0];
|
|
|
string excelConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filename +
|
|
|
";Extended Properties=Excel 8.0;";
|
|
|
if (filename.ToLower().IndexOf(".xlsx") > 0)
|
|
|
{
|
|
|
excelConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + filename +
|
|
|
";Extended Properties=\"Excel 12.0 Xml;HDR=Yes\"";
|
|
|
|
|
|
}
|
|
|
OleDbDataAdapter oada = new OleDbDataAdapter("select * from [" + sheetname + "A1:N]", 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 RepairId = string.Empty;
|
|
|
DBResult result = MsOpCtnRepairDAL.ImportCtnRepairData(table, userid, out RepairId);
|
|
|
if (result.Success == false)
|
|
|
{
|
|
|
jsonRespose.Success = false;
|
|
|
jsonRespose.Message = result.Message;
|
|
|
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
|
|
|
}
|
|
|
var json = JsonConvert.Serialize(new { success = true, Message = result.Message });
|
|
|
return new ContentResult() { Content = json };
|
|
|
}
|
|
|
catch (Exception)
|
|
|
{
|
|
|
|
|
|
jsonRespose.Success = false;
|
|
|
jsonRespose.Message = "读取Excel文件出错,请确认文件正确性";
|
|
|
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;";
|
|
|
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();
|
|
|
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)
|
|
|
{
|
|
|
return new List<string>();
|
|
|
}
|
|
|
|
|
|
return al;
|
|
|
}
|
|
|
|
|
|
public ContentResult UnLock ( string RepairIDs)
|
|
|
{
|
|
|
string msg = "操作成功!";
|
|
|
string userid = Session["USERID"] == null ? "" : Session["USERID"].ToString();
|
|
|
bool rst = MsOpCtnRepairDAL.UnLock(RepairIDs,userid,out msg);
|
|
|
var json = JsonConvert.Serialize(new { Success = rst, Message = msg });
|
|
|
return new ContentResult() { Content = json };
|
|
|
}
|
|
|
|
|
|
public ContentResult Lock ( string RepairIDs )
|
|
|
{
|
|
|
string userid = Session["USERID"] == null ? "" : Session["USERID"].ToString();
|
|
|
|
|
|
bool hasPower = MsOpCtnRepairDAL.CheckLockAndUnlockPower(1,userid);
|
|
|
if (!hasPower)
|
|
|
{
|
|
|
var json = JsonConvert.Serialize(new { Success = true, Message = "该用户没有操作权限!" });
|
|
|
return new ContentResult() { Content = json };
|
|
|
}
|
|
|
|
|
|
string[] repairids = RepairIDs.Split(',');
|
|
|
|
|
|
foreach (var item in repairids)
|
|
|
{
|
|
|
string id = item.Replace("'","");
|
|
|
bool rst = MsOpCtnRepairDAL.LockAndCreateCost(id, "1", userid);
|
|
|
}
|
|
|
|
|
|
var json2 = JsonConvert.Serialize(new { Success = true, Message = "操作完成" });
|
|
|
return new ContentResult() { Content = json2 };
|
|
|
}
|
|
|
|
|
|
public ContentResult ChangeMailStatus ( string RepairIDs )
|
|
|
{
|
|
|
string userid = Session["USERID"] == null ? "" : Session["USERID"].ToString();
|
|
|
bool rst = MsOpCtnRepairDAL.ChangeMailStatus(RepairIDs);
|
|
|
var json = JsonConvert.Serialize(new { Success = rst, Message = rst ? "操作成功" : "操作失败" });
|
|
|
return new ContentResult() { Content = json };
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|