using CY.Infrastructure.Common; using CY.Infrastructure.Logging; using CY.SQLDAL; using System; using System.Collections.Generic; using System.Data.SqlClient; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using static CY.WebForm.MainPage; using CY.Model.OA; using CY.WebForm.Helper; using CY.Infrastructure.Query; using System.IO; namespace CY.WebForm.Pages.business { public partial class OrderUpLoadLiuyang : BasePage { /// /// 选择文件 /// List SelFile { set; get; } /// /// 留样附件集合 /// List fileDataList { set; get; } = new List(); /// /// 附件个数 /// public int FileCount { get; set; } protected void Page_Load(object sender, EventArgs e) { UCPager1.AspNetPager.PageSize=5; UCPager1.AspNetPager.PageChanged += AspNetPager1_PageChanged; if (Request["deleteKeyIds"] != null&& Request["deleteKeyIds"]!="") { if (Request["deleteKeyIds"] == "all") { //删除说有页面 string keyid = Request["deleteKeyIds"].ToString(); string pageID = Request["Keyid"]; Database DC = new Database(); string sqlStr = string.Format(@" select [Keyid],[orderid],[FileName],[FilePath],[Remark],[Creater],[CreateTime],[Updater],[LastUpdateTime] FROM [ECTEST].[dbo].[EC_OrderLiuyang] where [orderid]={0} ORDER BY [CreateTime] ", pageID); try { SqlCommand myCmd = new SqlCommand(sqlStr, DC.Connection); //SqlDataAdapter myDa = new SqlDataAdapter(myCmd); var a = myCmd.ExecuteReader(); //myDa.Dispose(); fileDataList = new List(); EC_OrderLiuyang Contract; while (a.Read()) { //注意如何将每次读取到的记录添加到listbox1中(因为第一次做时出错了,嘿嘿) Contract = new EC_OrderLiuyang(); Contract.Keyid = a.GetGuid(0); Contract.orderid = a.GetInt32(1); Contract.FileName = a.GetString(2); Contract.FilePath = a.GetString(3); Contract.Remark = a.GetString(4); fileDataList.Add(Contract); } a.Close(); //关闭sqldatareader if (fileDataList.Count > 0) { foreach (var item in fileDataList) { FileInfo file = new FileInfo(Server.MapPath(item.FilePath));//指定文件路径 if (file.Exists)//判断文件是否存在 { file.Attributes = FileAttributes.Normal;//将文件属性设置为普通,比方说只读文件设置为普通 file.Delete();//删除文件 } sqlStr = string.Format(@" DELETE FROM [dbo].[EC_OrderLiuyang] where Keyid='{0}'", item.Keyid); myCmd = new SqlCommand(sqlStr, DC.Connection); myCmd.ExecuteNonQuery(); myCmd.Dispose(); } } JavaScript.MessageBox("删除成功", this); // Response.Redirect("/Pages/business/OrderUpLoadLiuyang.aspx"); } catch (Exception ee) { new Log4NetAdapter().Log("查找留样出错:" + ee.Message); JavaScript.MessageBox("删除失败", this); } finally { if (DC.Connection.State != System.Data.ConnectionState.Closed) DC.Connection.Close(); } } else { //删除页面 string keyid = Request["deleteKeyIds"].ToString(); string orderid = Request["Keyid"].ToString(); Database DC = new Database(); string sqlStr = string.Format(@" select [Keyid],[orderid],[FileName],[FilePath],[Remark],[Creater],[CreateTime],[Updater],[LastUpdateTime] FROM [ECTEST].[dbo].[EC_OrderLiuyang] where Keyid='{0}'ORDER BY [CreateTime] ", keyid); try { SqlCommand myCmd = new SqlCommand(sqlStr, DC.Connection); //SqlDataAdapter myDa = new SqlDataAdapter(myCmd); var a = myCmd.ExecuteReader(); //myDa.Dispose(); fileDataList = new List(); EC_OrderLiuyang Contract; while (a.Read()) { //注意如何将每次读取到的记录添加到listbox1中(因为第一次做时出错了,嘿嘿) Contract = new EC_OrderLiuyang(); Contract.Keyid = a.GetGuid(0); Contract.orderid = a.GetInt32(1); Contract.FileName = a.GetString(2); Contract.FilePath = a.GetString(3); Contract.Remark = a.GetString(4); fileDataList.Add(Contract); } a.Close(); //关闭sqldatareader if (fileDataList.Count > 0) { FileInfo file = new FileInfo(Server.MapPath(fileDataList[0].FilePath));//指定文件路径 if (file.Exists)//判断文件是否存在 { file.Attributes = FileAttributes.Normal;//将文件属性设置为普通,比方说只读文件设置为普通 file.Delete();//删除文件 } } sqlStr = string.Format(@" DELETE FROM [dbo].[EC_OrderLiuyang] where Keyid='{0}'", keyid); myCmd = new SqlCommand(sqlStr, DC.Connection); myCmd.ExecuteNonQuery(); //if (fileDataList.Count<=1) //{ // sqlStr = string.Format(@" update [EC_OrderBasic] set [LiuyangStatus] = 0 where [Keyid]= {0} ", orderid); // myCmd = new SqlCommand(sqlStr, DC.Connection); // myCmd.ExecuteNonQuery(); //} JavaScript.MessageBox("删除成功", this); // Response.Redirect("/Pages/business/OrderUpLoadLiuyang.aspx"); } catch (Exception ee) { new Log4NetAdapter().Log("查找留样出错:" + ee.Message); JavaScript.MessageBox("删除失败", this); } finally { if (DC.Connection.State != System.Data.ConnectionState.Closed) DC.Connection.Close(); } } Response.AppendHeader("deleteKeyIds", ""); } if (!IsPostBack) BindList(); } public Guid GetKeyid() { return Request["Keyid"].ToGuid2(); } //绑定列表 private void BindList() { Pagination pa = new Pagination(); pa.PageSize = UCPager1.AspNetPager.PageSize; pa.PageIndex = UCPager1.AspNetPager.CurrentPageIndex; int Keyid = Request["Keyid"].ToInt32().Value ; if(Keyid==0) { JavaScript.MessageBox("未找到该客户", this, false, false); return; } Database DC = new Database(); string sqlStr =string.Format(@" select * from (select ROW_NUMBER() OVER(Order by CreateTime ) AS RowNumber,* from [dbo].[EC_OrderLiuyang] where orderid='{0}' ) as b where b.RowNumber BETWEEN ({1}-1)*({2})+1 and {1}*{2} order by CreateTime ", Keyid,pa.PageIndex,pa.PageSize); int count = 0; try { SqlCommand myCmd = new SqlCommand(sqlStr, DC.Connection); //SqlDataAdapter myDa = new SqlDataAdapter(myCmd); var a = myCmd.ExecuteReader(); //myDa.Dispose(); fileDataList = new List (); EC_OrderLiuyang Contract ; while (a.Read()) { //注意如何将每次读取到的记录添加到listbox1中(因为第一次做时出错了,嘿嘿) Contract = new EC_OrderLiuyang(); Contract.Keyid = a.GetGuid(1); Contract.orderid = a.GetInt32(2); Contract.FileName = a.GetString(3); Contract.FilePath = a.GetString(4); Contract.Remark = a.GetString(5); fileDataList.Add(Contract); } a.Close(); //关闭sqldatareader sqlStr = string.Format("select count(*) from [dbo].[EC_OrderLiuyang] where orderid='{0}'", Keyid); myCmd = new SqlCommand(sqlStr, DC.Connection); count = (int)myCmd.ExecuteScalar(); } catch (Exception ee) { new Log4NetAdapter().Log("查找留样出错:" + ee.Message); } finally { if (DC.Connection.State != System.Data.ConnectionState.Closed) DC.Connection.Close(); } FileCount = fileDataList.Count; this.RepClientList.DataSource = fileDataList;// fileDataList.AsEnumerable(); this.RepClientList.DataBind(); UCPager1.AspNetPager.RecordCount = count; } //分页事件 protected void AspNetPager1_PageChanged(object src, EventArgs e) { BindList(); } protected void btn_Submit_Click_multi(object sender, EventArgs e) { var files = Request.Files; //if (files.Count <= 0) // return; HttpPostedFile postedFile; List fileList = new List(); for (int i=0;i< files.Count;i++) { if (files.Keys[i]=="file2") { postedFile = files[i]; if (postedFile.ContentLength == 0) continue; fileList.Add(postedFile); } } upLoadLiuyangFile uploadContract = new upLoadLiuyangFile(); EC_OrderLiuyang contract = null; //Guid? g = null; foreach (var item in fileList) { //int page = 0; //try //{ // page = pagecount(item); //} //catch (Exception) //{ // continue; //} //try //{ // g = GetContractFileID(page); //} //catch (Exception) //{ // continue; //} //uploadContract = new upLoadLiuyangFile(); //if (g != null) //{ // try // { // uploadContract.SavAndUpDataContractFile(item, CountractFileKeiId: g); // JavaScript.MessageBoxandhideLoadingIndicator( "上传文件成功", this); // //JavaScript.RefreshSelf(this); // //JavaScript.RefreshOpener(this); // } // catch (Exception) // { // JavaScript.MessageBoxandhideLoadingIndicator("上传文件失败", this); // // JavaScript.RefreshSelf(this); // //JavaScript.RefreshOpener(this); // } // continue; //} //新建走下面页面 contract = new EC_OrderLiuyang { orderid = Request["Keyid"].ToInt32().Value, FileName = System.IO.Path.GetFileName(item.FileName), Creater = CurrentUser.TrueMemberId, }; try { uploadContract.SavAndUpDataContractFile(item, contract); JavaScript.MessageBox("上传文件成功", this); } catch (Exception) { JavaScript.MessageBox( "上传文件失败", this); } } BindList(); } protected void btn_Submit_Click_DELLALL(object sender, EventArgs e) { string pageID = Request["Keyid"]; Database DC = new Database(); string sqlStr = string.Format(@" SELECT [Keyid],[orderid],[FileName],[FilePath],[Remark],[Creater],[CreateTime],[Updater],[LastUpdateTime] FROM [ECTEST].[dbo].[EC_OrderLiuyang] where orderid={0} ORDER BY CreateTime ", pageID); try { SqlCommand myCmd = new SqlCommand(sqlStr, DC.Connection); //SqlDataAdapter myDa = new SqlDataAdapter(myCmd); var a = myCmd.ExecuteReader(); //myDa.Dispose(); fileDataList = new List(); EC_OrderLiuyang Contract; while (a.Read()) { //注意如何将每次读取到的记录添加到listbox1中(因为第一次做时出错了,嘿嘿) Contract = new EC_OrderLiuyang(); Contract.Keyid = a.GetGuid(0); Contract.orderid = a.GetInt32(1); Contract.FileName = a.GetString(2); Contract.FilePath = a.GetString(3); Contract.Remark = a.GetString(4); fileDataList.Add(Contract); } a.Close(); //关闭sqldatareader if (fileDataList.Count > 0) { foreach (var item in fileDataList) { FileInfo file = new FileInfo(Server.MapPath(item.FilePath));//指定文件路径 if (file.Exists)//判断文件是否存在 { file.Attributes = FileAttributes.Normal;//将文件属性设置为普通,比方说只读文件设置为普通 file.Delete();//删除文件 } sqlStr = string.Format(@" DELETE FROM [dbo].[EC_OrderLiuyang] where Keyid='{0}'", item.Keyid); myCmd = new SqlCommand(sqlStr, DC.Connection); myCmd.ExecuteNonQuery(); } sqlStr = string.Format(@" update [EC_OrderBasic] set [LiuyangStatus] = 0 where [Keyid]= {0} ", pageID); myCmd = new SqlCommand(sqlStr, DC.Connection); myCmd.ExecuteNonQuery(); myCmd.Dispose(); } JavaScript.MessageBox("删除成功", this); // Response.Redirect("/Pages/business/OrderUpLoadLiuyang.aspx"); } catch (Exception ee) { new Log4NetAdapter().Log("查找留样出错:" + ee.Message); JavaScript.MessageBox("删除失败", this); } finally { if (DC.Connection.State != System.Data.ConnectionState.Closed) DC.Connection.Close(); } BindList(); } public void test() { return; } } }