using Newtonsoft.Json; using NFine.Code; using NFine.Data.Extensions; using NFine.Domain._03_Entity.SRM; using NFine.Repository; using System; using System.Collections.Generic; using System.Configuration; using System.Data; using System.Data.Common; using System.Data.SqlClient; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Web; namespace NFine.Application.SRM { public class ICSSrmportAlnoticeApp : RepositoryFactory { /// /// 查询公告信息 /// /// /// /// public DataTable GetGridJson(string queryJson, ref Pagination jqgridparam) { DataTable dt = new DataTable(); var queryParam = queryJson.ToJObject(); List parameter = new List(); string sql = @"select NoticeContent, NoticeID, NoticeTitle, NoticeType, CONVERT(NVARCHAR(20),NoValidDate,23) AS NoValidDate, Status, UserCode, VendorStatus, ViewCount, VISIBility, CASE when IsOutPottal='1' THEN '是'ELSE '否' END IsOutPottal, CONVERT(NVARCHAR(20),CreateDate,23) AS CreateDate from ICSSRMPORTALNOTICE Where 1=1 "; if (!string.IsNullOrWhiteSpace(queryJson)) { if (!string.IsNullOrWhiteSpace(queryParam["NoticeContent"].ToString())) { sql += " and NoticeContent like '%" + queryParam["NoticeContent"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["NoticeTitle"].ToString())) { sql += " and NoticeTitle like '%" + queryParam["NoticeTitle"].ToString() + "%' "; } if (!string.IsNullOrWhiteSpace(queryParam["TimeFrom"].ToString())) { sql += " and a.StarTime >= '" + queryParam["TimeFrom"].ToString() + "' "; } if (!string.IsNullOrWhiteSpace(queryParam["TimeTo"].ToString())) { sql += " and a.EndTime <= '" + queryParam["TimeTo"].ToString() + "' "; } if (!string.IsNullOrWhiteSpace(queryParam["Status"].ToString())) { sql += " and a.Status ='" + queryParam["Status"].ToString() + "'"; } } return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); } /// /// 获取数据字典中维护的公告类型 /// /// /// public DataTable GetNOTICETYPE() { string ItemCode = string.Empty; string F_EnCode = ""; string sqlItem = @"SELECT '' as F_ItemCode,'' as F_ItemName Union select F_ItemCode,b.F_ItemName from [dbo].[Sys_SRM_Items] a LEFT JOIN [dbo].[Sys_SRM_ItemsDetail] b on a.F_Id=b.F_itemID where F_EnCode='NOTICETYPE'"; sqlItem = string.Format(sqlItem, F_EnCode); DataTable table = SqlHelper.GetDataTableBySql(sqlItem); return table; } /// /// 保存公告 /// /// /// public void SubmitSrmportAlnotice(string queryJson, string ID) { try { DataTable dt = new DataTable(); List parameter = new List(); ICSSRMPORTALNOTICEModel[] list = JsonConvert.DeserializeObject(queryJson); string sql = string.Empty; string connString = ConfigurationManager.ConnectionStrings["connstr"].ConnectionString; SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString); conn.Open(); SqlTransaction sqlTran = conn.BeginTransaction(); SqlCommand cmd = new SqlCommand(); cmd.Transaction = sqlTran; cmd.Connection = conn; try { string UserCode = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode; string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.Replace("'", ""); foreach (var obj in list) { sql = @"IF NOT EXISTS(SELECT * FROM dbo.ICSSRMPORTALNOTICE WHERE NoticeID=@ID) BEGIN INSERT INTO dbo.ICSSRMPORTALNOTICE (CompanyCode ,CreateDate ,CreateUser ,IsOutPottal ,LogDate ,LogUser ,NoticeContent ,NoticeTitle ,NoticeType ,NoValidDate ,Status ,UserCode ,VendorStatus ,ViewCount ,VISIBility ,NOTICEID ) VALUES ( @CompanyCode ,@CreateDate ,@CreateUser ,@IsOutPottal ,@LogDate ,@LogUser ,@NoticeContent ,@NoticeTitle ,@NoticeType ,@NoValidDate ,@Status ,@UserCode ,@VendorStatus ,@ViewCount ,@VISIBility ,NEWID() ) END ELSE BEGIN UPDATE dbo.ICSSRMPORTALNOTICE SET CompanyCode=@CompanyCode ,CreateDate=@CreateDate ,CreateUser=@CreateUser ,IsOutPottal=@IsOutPottal ,LogDate=@LogDate ,LogUser=@LogUser ,NoticeContent=@NoticeContent ,NoticeTitle=@NoticeTitle ,NoticeType=@NoticeType ,NoValidDate=@NoValidDate ,UserCode=@UserCode ,VendorStatus=@VendorStatus ,VISIBility=@VISIBility WHERE NOTICEID=@ID END"; SqlParameter[] sp_Detail = { new SqlParameter("@CompanyCode",obj.CompanyCode), new SqlParameter("@CreateDate",DateTime.Now.ToString("yyyy-MM-dd")), new SqlParameter("@CreateUser",UserCode), new SqlParameter("@IsOutPottal",obj.IsOutPottal), new SqlParameter("@LogDate",DateTime.Now.ToString("yyyy-MM-dd")), new SqlParameter("@LogUser",UserCode), new SqlParameter("@NoticeContent",obj.NoticeContent), new SqlParameter("@NoticeTitle",obj.NoticeTitle), new SqlParameter("@NoticeType",obj.NoticeType), new SqlParameter("@NoValidDate",obj.NoValidDate), new SqlParameter("@ID",ID), new SqlParameter("@Status", obj.Status==""||obj.Status==null?"0":obj.Status), new SqlParameter("@UserCode",UserCode), new SqlParameter("@VendorStatus",obj.VendorStatus), new SqlParameter("@ViewCount",1), new SqlParameter("@VISIBility",obj.VISIBility), }; SqlCommandHelper.CmdExecuteNonQuery(sql, sp_Detail, cmd); } cmd.Transaction.Commit(); } catch (Exception ex) { cmd.Transaction.Rollback(); throw new Exception(ex.Message); } finally { if (conn.State == ConnectionState.Open) { conn.Close(); } conn.Dispose(); } } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 删除公告信息 /// /// /// public string DeleteSrmportAlnotice(string NoticeID) { string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode; string MUSERName = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode; //string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; NoticeID = NoticeID.TrimStart('"').TrimEnd('"').TrimEnd(','); string sql = string.Empty; sql = @"delete FROM ICSSRMPORTALNOTICE where NOTICEID in ({0})"; sql = string.Format(sql, NoticeID); string msg = ""; try { SqlHelper.ExecuteNonQuery(sql); } catch (Exception ex) { msg = ex.Message; } return msg; } /// /// 修改时获取维护信息 /// /// /// /// /// public DataTable ICSSrmportAlnoticeByCreate(string NoticeID) { DataTable dt = new DataTable(); //var queryParam = queryJson.ToJObject(); List parameter = new List(); string sql = string.Empty; sql = @"select NoticeContent, NoticeID, NoticeTitle, NoticeType, NoValidDate, Status, UserCode, VendorStatus, ViewCount, VISIBility, IsOutPottal, CreateDate ,COMPANYCODE from ICSSRMPORTALNOTICE Where 1=1 "; sql += " and NoticeID='" + NoticeID + "'"; return Repository().FindTableBySql(sql.ToString()); } public object ImportOrder() { HttpPostedFile oFile = HttpContext.Current.Request.Files["txt_file"]; //获取送货单号 //string STNO = Request.Form["STNO"].ToString(); string fileName = Path.GetFileNameWithoutExtension(oFile.FileName) + Path.GetExtension(oFile.FileName); string Paths = System.Web.HttpContext.Current.Server.MapPath("~\\File\\GGFile\\" ); if (!Directory.Exists(Paths)) { Directory.CreateDirectory(Paths); } string filePath = System.Web.HttpContext.Current.Server.MapPath("~\\File\\GGFile\\" + fileName); int iLen = oFile.ContentLength; byte[] bData = new byte[iLen]; oFile.InputStream.Read(bData, 0, iLen); FileStream fs = new FileStream(filePath, FileMode.OpenOrCreate); fs.Write(bData, 0, bData.Length); fs.Flush(); fs.Close(); fs.Dispose(); return ""; } } }