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 CorporateClientsUpLoadContract : BasePage
|
{
|
|
|
/// <summary>
|
/// 选择文件
|
/// </summary>
|
List<HttpFileCollection> SelFile { set; get; }
|
/// <summary>
|
/// 合同附件集合
|
/// </summary>
|
List<OA_CorporateClientsContract> fileDataList { set; get; } = new List<OA_CorporateClientsContract>();
|
/// <summary>
|
/// 附件个数
|
/// </summary>
|
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] ,[CorporateClientsid] ,[CorporateClientsName] ,[FileName] ,[PageCode] ,[FilePath] ,[Remark] FROM[dbo].[OA_CorporateClientContract] where CorporateClientsid='{0}'ORDER BY PageCode ", pageID);
|
|
|
try
|
{
|
SqlCommand myCmd = new SqlCommand(sqlStr, DC.Connection);
|
//SqlDataAdapter myDa = new SqlDataAdapter(myCmd);
|
var a = myCmd.ExecuteReader();
|
//myDa.Dispose();
|
fileDataList = new List<OA_CorporateClientsContract>();
|
OA_CorporateClientsContract Contract;
|
while (a.Read())
|
{ //注意如何将每次读取到的记录添加到listbox1中(因为第一次做时出错了,嘿嘿)
|
Contract = new OA_CorporateClientsContract();
|
Contract.Keyid = a.GetGuid(0);
|
Contract.CorporateClientsid = a.GetGuid(1);
|
Contract.CorporateClientsName = a.GetString(2);
|
Contract.FileName = a.GetString(3);
|
Contract.PageCode = a.GetInt32(4);
|
Contract.FilePath = a.GetString(5);
|
Contract.Remark = a.GetString(6);
|
|
|
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].[OA_CorporateClientContract] where Keyid='{0}'", item.Keyid);
|
myCmd = new SqlCommand(sqlStr, DC.Connection);
|
myCmd.ExecuteNonQuery();
|
myCmd.Dispose();
|
}
|
|
}
|
|
JavaScript.MessageBox("删除成功", this);
|
// Response.Redirect("/Pages/business/CorporateClientsUpLoadContract.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();
|
Database DC = new Database();
|
string sqlStr = string.Format(@" SELECT[Keyid] ,[CorporateClientsid] ,[CorporateClientsName] ,[FileName] ,[PageCode] ,[FilePath] ,[Remark] FROM[dbo].[OA_CorporateClientContract] where Keyid='{0}'ORDER BY PageCode ", keyid);
|
|
|
try
|
{
|
SqlCommand myCmd = new SqlCommand(sqlStr, DC.Connection);
|
//SqlDataAdapter myDa = new SqlDataAdapter(myCmd);
|
var a = myCmd.ExecuteReader();
|
//myDa.Dispose();
|
fileDataList = new List<OA_CorporateClientsContract>();
|
OA_CorporateClientsContract Contract;
|
while (a.Read())
|
{ //注意如何将每次读取到的记录添加到listbox1中(因为第一次做时出错了,嘿嘿)
|
Contract = new OA_CorporateClientsContract();
|
Contract.Keyid = a.GetGuid(0);
|
Contract.CorporateClientsid = a.GetGuid(1);
|
Contract.CorporateClientsName = a.GetString(2);
|
Contract.FileName = a.GetString(3);
|
Contract.PageCode = a.GetInt32(4);
|
Contract.FilePath = a.GetString(5);
|
Contract.Remark = a.GetString(6);
|
|
|
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].[OA_CorporateClientContract] where Keyid='{0}'", keyid);
|
myCmd = new SqlCommand(sqlStr, DC.Connection);
|
myCmd.ExecuteNonQuery();
|
JavaScript.MessageBox("删除成功", this);
|
// Response.Redirect("/Pages/business/CorporateClientsUpLoadContract.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;
|
Guid Keyid = Request["Keyid"].ToGuid2();
|
|
if(Keyid==null)
|
{
|
JavaScript.MessageBox("未找到该客户", this, false, false);
|
return;
|
}
|
Database DC = new Database();
|
string sqlStr =string.Format(@" select * from (select ROW_NUMBER() OVER(Order by PageCode) AS RowNumber,* from [dbo].[OA_CorporateClientContract] where CorporateClientsid='{0}' ) as b where b.RowNumber BETWEEN ({1}-1)*({2})+1 and {1}*{2} order by PageCode ", 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 <OA_CorporateClientsContract>();
|
OA_CorporateClientsContract Contract ;
|
while (a.Read())
|
{ //注意如何将每次读取到的记录添加到listbox1中(因为第一次做时出错了,嘿嘿)
|
Contract = new OA_CorporateClientsContract();
|
Contract.Keyid = a.GetGuid(1);
|
Contract.CorporateClientsid = a.GetGuid(2);
|
Contract.CorporateClientsName = a.GetString(3);
|
Contract.FileName = a.GetString(4);
|
Contract.PageCode = a.GetInt32(5);
|
Contract.FilePath = a.GetString(6);
|
Contract.Remark = a.GetString(7);
|
|
|
fileDataList.Add(Contract);
|
}
|
a.Close(); //关闭sqldatareader
|
sqlStr = string.Format("select count(*) from [dbo].[OA_CorporateClientContract] where CorporateClientsid='{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<OA_CorporateClientsContract>();
|
|
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<HttpPostedFile> fileList = new List<HttpPostedFile>();
|
|
|
for (int i=0;i< files.Count;i++)
|
{
|
|
if (files.Keys[i]=="file2")
|
{
|
postedFile = files[i];
|
if (postedFile.ContentLength == 0)
|
continue;
|
fileList.Add(postedFile);
|
}
|
|
}
|
|
upLoadContractFile uploadContract = null;
|
OA_CorporateClientsContract 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 upLoadContractFile();
|
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 OA_CorporateClientsContract
|
{
|
CorporateClientsid = Request["Keyid"].ToGuid2(),
|
FileName = System.IO.Path.GetFileName(item.FileName),
|
PageCode = page,
|
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] ,[CorporateClientsid] ,[CorporateClientsName] ,[FileName] ,[PageCode] ,[FilePath] ,[Remark] FROM[dbo].[OA_CorporateClientContract] where CorporateClientsid='{0}'ORDER BY PageCode ", pageID);
|
|
|
try
|
{
|
SqlCommand myCmd = new SqlCommand(sqlStr, DC.Connection);
|
//SqlDataAdapter myDa = new SqlDataAdapter(myCmd);
|
var a = myCmd.ExecuteReader();
|
//myDa.Dispose();
|
fileDataList = new List<OA_CorporateClientsContract>();
|
OA_CorporateClientsContract Contract;
|
while (a.Read())
|
{ //注意如何将每次读取到的记录添加到listbox1中(因为第一次做时出错了,嘿嘿)
|
Contract = new OA_CorporateClientsContract();
|
Contract.Keyid = a.GetGuid(0);
|
Contract.CorporateClientsid = a.GetGuid(1);
|
Contract.CorporateClientsName = a.GetString(2);
|
Contract.FileName = a.GetString(3);
|
Contract.PageCode = a.GetInt32(4);
|
Contract.FilePath = a.GetString(5);
|
Contract.Remark = a.GetString(6);
|
|
|
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].[OA_CorporateClientContract] where Keyid='{0}'", item.Keyid);
|
myCmd = new SqlCommand(sqlStr, DC.Connection);
|
myCmd.ExecuteNonQuery();
|
myCmd.Dispose();
|
}
|
|
}
|
|
JavaScript.MessageBox("删除成功", this);
|
// Response.Redirect("/Pages/business/CorporateClientsUpLoadContract.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();
|
}
|
protected void btn_Submit_Click(object sender, EventArgs e)
|
{
|
|
var files = Request.Files;
|
if (files.Count <= 0)
|
return;
|
// return;
|
HttpPostedFile postedFile=null;
|
|
|
|
for (int i = 0; i < files.Count; i++)
|
{
|
|
if (files.Keys[i] == "filesel")
|
{
|
postedFile = files[i];
|
if (postedFile.ContentLength == 0)
|
{
|
return;
|
}
|
|
break;
|
}
|
|
}
|
|
|
|
Guid? g = GetContractFileID();
|
upLoadContractFile uploadContract = new upLoadContractFile();
|
if (g != null)
|
{
|
try
|
{
|
uploadContract.SavAndUpDataContractFile(postedFile,CountractFileKeiId :g);
|
|
JavaScript.MessageBoxandhideLoadingIndicator("上传文件成功", this);
|
//JavaScript.RefreshSelf(this);
|
//JavaScript.RefreshOpener(this);
|
BindList();
|
}
|
catch (Exception)
|
{
|
JavaScript.MessageBoxandhideLoadingIndicator("上传文件失败", this);
|
// JavaScript.RefreshSelf(this);
|
//JavaScript.RefreshOpener(this);
|
BindList();
|
|
}
|
|
return;
|
}
|
|
//新建走下面页面
|
OA_CorporateClientsContract contract = new OA_CorporateClientsContract
|
{
|
CorporateClientsid = Request["Keyid"].ToGuid2(),
|
FileName = System.IO.Path.GetFileName(postedFile.FileName),
|
PageCode = Convert.ToInt32(this.TextPage.Value),
|
Creater= CurrentUser.TrueMemberId,
|
|
};
|
|
|
|
try
|
{
|
uploadContract.SavAndUpDataContractFile(postedFile, contract);
|
|
JavaScript.MessageBox("上传文件成功", this);
|
//JavaScript.RefreshSelf(this);
|
//JavaScript.RefreshOpener(this);
|
BindList();
|
}
|
catch (Exception )
|
{
|
JavaScript.MessageBox("上传文件失败", this);
|
// JavaScript.RefreshSelf(this);
|
//JavaScript.RefreshOpener(this);
|
BindList();
|
|
}
|
|
|
// CY.WebForm.cs.UploadCS.Upload(System.Web.HttpContext.Current.Request.MapPath("contractImgs/") + Guid.NewGuid().ToString() + fileName)
|
|
|
//var files = Request.Files;
|
//for (int iFile = 0; iFile < files.Count; iFile++)
|
//{
|
// ///'检查文件扩展名字
|
// HttpPostedFile postedFile = files[iFile];
|
// string fileName, fileExtension;
|
// fileName = System.IO.Path.GetFileName(postedFile.FileName);
|
// if (fileName != "")
|
// {
|
// fileExtension = System.IO.Path.GetExtension(fileName);
|
// //strMsg.Append("上传的文件类型:" + postedFile.ContentType.ToString() + "<br>");
|
// //strMsg.Append("客户端文件地址:" + postedFile.FileName + "<br>");
|
// //strMsg.Append("上传文件的文件名:" + fileName + "<br>");
|
// //strMsg.Append("上传文件的扩展名:" + fileExtension + "<br><hr>");
|
// ///'可根据扩展名字的不同保存到不同的文件夹
|
// ///注意:可能要修改你的文件夹的匿名写入权限。
|
// ///
|
|
// // postedFile.SaveAs(System.Web.HttpContext.Current.Request.MapPath("contractImgs/") + Guid.NewGuid().ToString()+ fileName);
|
|
|
// }
|
//}
|
|
}
|
|
public void test()
|
{
|
return;
|
}
|
|
/// <summary>
|
/// 获取当前页面的guiid,判断是否是新建页面 如果没有,则获取页面的页码
|
/// </summary>
|
/// <returns></returns>
|
public Guid? GetContractFileID(int? Pagecode=null)
|
{
|
Guid Keyid = Request["Keyid"].ToGuid2();
|
Database DC = new Database();
|
if (Pagecode != null)
|
{
|
try
|
{
|
Pagecode = Convert.ToInt32(Pagecode);
|
}
|
catch (Exception)
|
{
|
|
return null;
|
}
|
}
|
else
|
{
|
try
|
{
|
Pagecode = Convert.ToInt32(this.TextPage.Value);
|
}
|
catch (Exception)
|
{
|
|
return null;
|
}
|
|
}
|
|
|
|
string sqlStr = string.Format(@" SELECT[Keyid] FROM[dbo].[OA_CorporateClientContract] where CorporateClientsid='{0}' and [PageCode]='{1}' ", Keyid, Pagecode);
|
|
try
|
{
|
SqlCommand myCmd = new SqlCommand(sqlStr, DC.Connection);
|
//SqlDataAdapter myDa = new SqlDataAdapter(myCmd);
|
var a = myCmd.ExecuteReader();
|
//myDa.Dispose();
|
List<OA_CorporateClientsContract> ff = new List<OA_CorporateClientsContract>();
|
OA_CorporateClientsContract Contract;
|
while (a.Read())
|
{ //注意如何将每次读取到的记录添加到listbox1中(因为第一次做时出错了,嘿嘿)
|
Contract = new OA_CorporateClientsContract();
|
Contract.Keyid = a.GetGuid(0);
|
ff.Add(Contract);
|
}
|
a.Close(); //关闭sqldatareader
|
if (ff.Count >= 0)
|
return ff[0].Keyid;
|
else return null;
|
}
|
catch (Exception ee)
|
{
|
new Log4NetAdapter().Log("查找合同出错:" + ee.Message);
|
return null;
|
}
|
finally
|
{
|
if (DC.Connection.State != System.Data.ConnectionState.Closed)
|
DC.Connection.Close();
|
}
|
|
}
|
|
public int pagecount(HttpPostedFile file)
|
{
|
try
|
{
|
string filepagecode = System.IO.Path.GetFileNameWithoutExtension(file.FileName);
|
return Convert.ToInt32(filepagecode);
|
|
}
|
catch (Exception)
|
{
|
|
JavaScript.MessageBox(file.FileName + "文件上传失败,命名规则冲突", this);
|
throw;
|
}
|
|
|
}
|
|
|
|
|
}
|
}
|