//订单删除 公共方法 by panhuaguo 2016-08-30 含国内业务 public static string deleteorder(string ordercode) { string json = "{success:false}"; //删除订单随附文件 System.Uri Uri = new Uri("ftp://" + ConfigurationManager.AppSettings["FTPServer"] + ":" + ConfigurationManager.AppSettings["FTPPortNO"]); string UserName = ConfigurationManager.AppSettings["FTPUserName"]; string Password = ConfigurationManager.AppSettings["FTPPassword"]; FtpHelper ftp = new FtpHelper(Uri, UserName, Password); string sql = "select * from list_attachment where ordercode='" + ordercode + "'"; DataTable dt = DBMgr.GetDataTable(sql); foreach (DataRow dr in dt.Rows) { ftp.DeleteFile(dr["FILENAME"] + ""); } sql = "delete from list_attachment where ordercode='" + ordercode + "'"; DBMgr.ExecuteNonQuery(sql); //删除list_times信息 sql = "delete from list_times where code='" + ordercode + "'"; DBMgr.ExecuteNonQuery(sql); //删除集装箱信息 sql = "delete from list_predeclcontainer where ordercode='" + ordercode + "'"; DBMgr.ExecuteNonQuery(sql); //删除订单信息 sql = "delete from list_order where code='" + ordercode + "'"; DBMgr.ExecuteNonQuery(sql); json = "{success:true}"; return(json); }
//订单新增或者更新时对随附文件表的操作 非国内业务都会用到 封装by panhuaguo 2016-08-03 //originalfileids 这个字符串存储的是订单修改时原始随附文件id用逗号分隔 public static void Update_Attachment(string ordercode, string filedata, string originalfileids, JObject json_user) { if (!string.IsNullOrEmpty(filedata)) { System.Uri Uri = new Uri("ftp://" + ConfigurationManager.AppSettings["FTPServer"] + ":" + ConfigurationManager.AppSettings["FTPPortNO"]); string UserName = ConfigurationManager.AppSettings["FTPUserName"]; string Password = ConfigurationManager.AppSettings["FTPPassword"]; FtpHelper ftp = new FtpHelper(Uri, UserName, Password); JArray jarry = JsonConvert.DeserializeObject <JArray>(filedata); string sql = ""; foreach (JObject json in jarry) { if (string.IsNullOrEmpty(json.Value <string>("ID"))) { string filename = "/" + json.Value <string>("FILETYPE") + "/" + ordercode + "/" + json.Value <string>("ORIGINALNAME"); string sizes = json.Value <string>("SIZES"); string filetypename = json.Value <string>("FILETYPENAME"); string extname = json.Value <string>("ORIGINALNAME").ToString().Substring(json.Value <string>("ORIGINALNAME").ToString().LastIndexOf('.') + 1); sql = @"insert into LIST_ATTACHMENT (id,filename,originalname,filetype,uploadtime,uploaduserid,customercode,ordercode, sizes,filetypename,filesuffix,IETYPE) values(List_Attachment_Id.Nextval,'{0}','{1}','{2}',sysdate,{3},'{4}','{5}','{6}','{7}','{8}','{9}')"; sql = string.Format(sql, filename, json.Value <string>("ORIGINALNAME"), json.Value <string>("FILETYPE"), json_user.Value <string>("ID"), json_user.Value <string>("CUSTOMERCODE"), ordercode, sizes, filetypename, extname, json.Value <string>("IETYPE")); DBMgr.ExecuteNonQuery(sql); } else//如果ID已经存在 说明是已经存在的记录,不需要做任何处理 { originalfileids = originalfileids.Replace(json.Value <string>("ID") + ",", ""); } } //从数据库和文档库删除在前端移除的随附文件记录 string[] idarray = originalfileids.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); foreach (string id in idarray) { sql = @"select * from LIST_ATTACHMENT where ID='" + id + "'"; DataTable dt = DBMgr.GetDataTable(sql); if (dt.Rows.Count > 0) { ftp.DeleteFile(dt.Rows[0]["FILENAME"] + ""); } sql = @"delete from LIST_ATTACHMENT where ID='" + id + "'"; DBMgr.ExecuteNonQuery(sql); } } }
public static void Update_Attachment_ForEnterprise(string entorder_id, string filedata, string originalfileids, JObject json_user) { if (!string.IsNullOrEmpty(filedata)) { string webFilePath = ConfigurationManager.AppSettings["WebFilePath"]; System.Uri Uri = new Uri("ftp://" + ConfigurationManager.AppSettings["FTPServer"] + ":" + ConfigurationManager.AppSettings["FTPPortNO"]); string UserName = ConfigurationManager.AppSettings["FTPUserName"]; string Password = ConfigurationManager.AppSettings["FTPPassword"]; FtpHelper ftp = new FtpHelper(Uri, UserName, Password); JArray jarry = JsonConvert.DeserializeObject <JArray>(filedata); string sql = ""; string remote = DateTime.Now.ToString("yyyy-MM-dd"); IDatabase db = SeRedis.redis.GetDatabase(); foreach (JObject json in jarry) { if (string.IsNullOrEmpty(json.Value <string>("ID"))) { string filename = "/" + remote + "/" + json.Value <string>("NEWNAME"); string sizes = json.Value <string>("SIZES"); string filetypename = json.Value <string>("FILETYPENAME"); string extname = json.Value <string>("ORIGINALNAME").ToString().Substring(json.Value <string>("ORIGINALNAME").ToString().LastIndexOf('.') + 1); try { string[] split = json.Value <string>("NEWNAME").Split(new string[] { "." }, StringSplitOptions.RemoveEmptyEntries); string oldName = webFilePath + json.Value <string>("NEWNAME"); string newName = webFilePath + split[0] + "_0." + split[1]; FileInfo fi = new FileInfo(oldName); fi.MoveTo(Path.Combine(newName)); StreamReader sr = new StreamReader(newName, Encoding.GetEncoding("BIG5")); String line; FileStream fs = new FileStream(oldName, FileMode.Create); while ((line = sr.ReadLine()) != null) { byte[] dst = Encoding.UTF8.GetBytes(line); fs.Write(dst, 0, dst.Length); fs.WriteByte(13); fs.WriteByte(10); } fs.Flush(); fs.Close(); } catch (Exception) { throw; } sql = @"insert into LIST_ATTACHMENT (id,filename,originalname,filetype,uploadtime,uploaduserid,customercode,entid, sizes,filetypename,filesuffix) values(List_Attachment_Id.Nextval,'{0}','{1}','{2}',sysdate,{3},'{4}','{5}','{6}','{7}','{8}')"; sql = string.Format(sql, filename, json.Value <string>("ORIGINALNAME"), json.Value <string>("FILETYPE"), json_user.Value <string>("ID"), json_user.Value <string>("CUSTOMERCODE"), entorder_id, sizes, filetypename, extname); DBMgr.ExecuteNonQuery(sql); if (json.Value <string>("ORIGINALNAME").IndexOf(".txt") > 0 || json.Value <string>("ORIGINALNAME").IndexOf(".TXT") > 0) { db.ListRightPush("compal_sheet_topdf_queen", "{ENTID:'" + entorder_id + "',FILENAME:'" + filename + "'}"); } } else//如果ID已经存在 说明是已经存在的记录,不需要做任何处理 { originalfileids = originalfileids.Replace(json.Value <string>("ID") + ",", ""); } } //从数据库和文档库删除在前端移除的随附文件记录 string[] idarray = originalfileids.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); foreach (string id in idarray) { sql = @"select * from LIST_ATTACHMENT where ID='" + id + "'"; DataTable dt = DBMgr.GetDataTable(sql); if (dt.Rows.Count > 0) { ftp.DeleteFile(dt.Rows[0]["FILENAME"] + ""); } sql = @"delete from LIST_ATTACHMENT where ID='" + id + "'"; DBMgr.ExecuteNonQuery(sql); //移除转PDF的缓存 db.ListRemove("compal_sheet_topdf_queen", "{ENTID:'" + id + "',FILENAME:'" + dt.Rows[0]["FILENAME"].ToString() + "'}"); } } }