/******************************
* 说明:附件相关接口实现
* 创建人:龚宇超
* 创建日期:2018-01-08
* 修改人:
* 修改日期:
* 修改备注:
* 版本:1.0.0.0
******************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Lskj.Core;
using System.Data.SqlClient;
using System.Data;
using Lskj.Model;
using System.Web;
namespace Lskj.Business.Impl
{
///
/// 附件相关接口实现
///
public class AttachImpl : BaseImpl
{
///
/// 说明:获取审核明细
/// 创建人:王一帆
/// 创建日期:2021-01-18
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The menu code.
/// DataRow.
///
public static DataTable GetAttachDetilTab(string typeCode, string StepCode)
{
string sqlValue = string.Format("select * from p_SystemDlltabDetailFlowTab where isnull(isvisible,0)!=1 and typecode='{0}' and stepcode='{1}'", typeCode, StepCode);
DataTable dtTable = SqlHelper.ExecuteDataTable(sqlValue);
return dtTable;
}
///
/// 说明:获取附件目录ID
/// 创建人:龚宇超
/// 创建日期:2018-01-08
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The parent identifier.
/// 主键值.
/// System.Int32.
///
public static int GetAttachDirectoryId(string parentId, string objectId)
{
try
{
string sqlValue = "select dirid from P_fm_DirectoryTab where ParentId=@ParentId and PID=@PID";
string dirId = GetResult(sqlValue, new SqlParameter[] {
new SqlParameter("@ParentId", parentId),
new SqlParameter("@PID",objectId)
}) + "";
if (string.IsNullOrEmpty(dirId) || "0".Equals(dirId))
{
// 插入新目录
sqlValue = string.Format("insert into P_fm_DirectoryTab (sName,ParentId,creator,SpeciesNo,relationCode,PID) values('{0}','{1}',1,'0201',0,'{0}');select @@identity", objectId, parentId);
dirId = GetResult(sqlValue) + "";
}
return Convert.ToInt32(dirId);
}
catch (Exception)
{
}
return 0;
}
///
/// 说明:锁定附件
/// 创建人:龚宇超
/// 创建日期:2018-02-28
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The file ids.
/// System.Int32.
///
public static int LockFiles(string fileIds)
{
if (string.IsNullOrEmpty(fileIds)) return 0;
string sqlValue = string.Format("update P_fm_FileTab set A1=1 where fileId in ({0})", fileIds.TrimEnd(','));
return SqlHelper.ExecuteNonQuery(sqlValue);
}
///
/// 说明:解锁附件
/// 创建人:龚宇超
/// 创建日期:2018-02-28
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The file ids.
/// System.Int32.
///
public static int UnLockFiles(string fileIds)
{
if (string.IsNullOrEmpty(fileIds)) return 0;
string sqlValue = string.Format("update P_fm_FileTab set A1=0 where fileId in ({0})", fileIds.TrimEnd(','));
return SqlHelper.ExecuteNonQuery(sqlValue);
}
///
/// 说明:
/// 创建人:龚宇超
/// 创建日期:2018-01-17
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// 1=上传,2=下载,3=删除,4=锁定,5=解除锁定 必填
/// The species no.
/// The file id.
/// Name of the file.
/// Size of the field.
/// 返回提示信息
/// System.Int32.
///
public static int CheckAttachOperation(int operType, string speciesNo, int fileId, string fileName, int fileSize, out string tipMsg)
{
try
{
SqlParameter pMsg = new SqlParameter("@msg", SqlDbType.VarChar, 2000);
pMsg.Direction = ParameterDirection.Output;
SqlParameter returnValue = new SqlParameter("@return", SqlDbType.Int, 4);
returnValue.Direction = ParameterDirection.ReturnValue;
SqlParameter[] param =
{
new SqlParameter("@opertype",SqlDbType.Int),
new SqlParameter("@operatorid",SqlDbType.Int),
new SqlParameter("@operatorname",SqlDbType.VarChar,50),
new SqlParameter("@fileSpecisNo",SqlDbType.VarChar,50),
new SqlParameter("@fileid",SqlDbType.Int),
new SqlParameter("@filename",SqlDbType.VarChar,200),
new SqlParameter("@filesize",SqlDbType.Int),
pMsg,
returnValue
};
param[0].Value = operType;
param[1].Value = ERPInfo.Instance.UserId;
param[2].Value = ERPInfo.Instance.UserName;
param[3].Value = speciesNo;
param[4].Value = fileId;
param[5].Value = fileName;
param[6].Value = fileSize;
DataSet ds = SqlHelper.ExecuteDataSet(CommandType.StoredProcedure, "p_SystemAttachOperation", "attach", param);
tipMsg = pMsg.Value + "";
return Convert.ToInt32(returnValue.Value + "");
}
catch (Exception)
{
}
tipMsg = string.Empty;
return 1;
}
///
/// 说明:删除签名
/// 创建人:龚宇超
/// 创建日期:2018-06-06
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The sign identifier.
/// System.Int32.
public static int DeleteSignPoint(int signId)
{
string sqlValue = string.Format("delete from P_PDFSignTab where id='{0}'", signId);
return SqlHelper.ExecuteNonQuery(sqlValue);
}
///
/// 说明:添加上传附件
/// 创建人:龚宇超
/// 创建日期:2018-06-12
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// System.Int32.
public static int InsertUpLoadFile(string fileName, string DirId, long fileSize, string speciesno)
{
string sqlValue = string.Format("INSERT INTO P_fm_FileTab(sName,ParentID,fileSize,creator,speciesno,CreateTime) " +
"VALUES('{0}',{1},'{2}',{3},'{4}','{5}')", fileName, DirId, fileSize, ERPInfo.Instance.UserId, speciesno, DateTime.Now);
return SqlHelper.ExecuteNonQuery(sqlValue);
}
///
/// 说明:插入签名点
/// 创建人:龚宇超
/// 创建日期:2018-06-07
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// 模块属性
/// 签名图片字节
/// X坐标.
/// Y坐标
/// 文档页码
/// System.Int32.
public static int InsertSignPoint(DynamicPdfViewerModel model, Byte[] byPic, float imageX, float imageY, int pageNo)
{
//存流会出现保存进去的流变化分两次处理,先添加,流通过更新进去正常
string sqlValue = string.Format(@"insert into P_PDFSignTab (FileId,BillId,BillDetailId,StepCode,OperatorId,OperateDate,Image,ImageX,ImageY,Page)
VALUES ('{0}','{1}','{2}','{3}','{4}','{5}','','{6}','{7}','{8}');Select @@IDENTITY;", model.PdfFileId, model.BillDocumentId, model.BillDeatilId, model.stepCode, ERPInfo.Instance.UserId, DateTime.Now, imageX, imageY, pageNo);
int resultId = Convert.ToInt32(SqlHelper.ExecuteScalar(CommandType.Text, sqlValue));
if (resultId > 0)
{
string sqlValue2 = string.Format("update P_PDFSignTab set Image=@Pic where id='{0}'", resultId);
SqlParameter parameter = new SqlParameter("@Pic", SqlDbType.Image);
parameter.Value = byPic;
int result = SqlHelper.ExecuteNonQuery(CommandType.Text, sqlValue2, parameter);
if (result <= 0) return 0;
}
return resultId;
}
///
/// 说明:获取(解除)锁定成功的数据条数
/// 创建人:龚宇超
/// 创建日期:2018-02-24
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The dt files.
/// 锁定标记
/// DataTable.
///
public static int GetLockDataCount(DataTable dtFiles, string lockFlag)
{
int Count = 0;
for (int i = 0; i < dtFiles.Rows.Count; i++)
{
string sqlValue = "update P_fm_FileTab set A1=@LockFlag where fileId=@fileId";
Count += ExecSqlValue(sqlValue, new SqlParameter[] { new SqlParameter("@fileId", dtFiles.Rows[i]["fileId"]), new SqlParameter("LockFlag", lockFlag) });
}
return Count;
}
///
/// 说明:更新附件关联
/// 创建人:龚宇超
/// 创建日期:2018-02-28
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// Name of the table.
/// Name of the field.
/// The field value.
/// The cond key.
/// The cond value.
/// System.Int32.
///
public static int UpdateUnionAttach(string tableName, string fieldName, string fieldValue, string condKey, string condValue)
{
if (string.IsNullOrWhiteSpace(tableName) ||
string.IsNullOrWhiteSpace(fieldName) ||
string.IsNullOrWhiteSpace(condKey))
return 0;
string sqlValue = string.Format("update {0} set {1}='{2}' where {3}='{4}'", tableName, fieldName, fieldValue, condKey, condValue); ;
return SqlHelper.ExecuteNonQuery(sqlValue);
}
///
/// 说明:获取附件信息目录Id菜单编号
/// 创建人:龚宇超
/// 创建日期:2018-02-28
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
public static string GetFilesTab(int dirId, string fileId, string txtKey)
{
string strWhere = string.Format(" where parentId='{0}'", dirId);
string sqlValue = "select * from P_fm_filetab";
if (!string.IsNullOrEmpty(txtKey)) strWhere += string.Format(" and {0} like '%{1}%'", fileId, txtKey);
sqlValue += strWhere;
return sqlValue;
}
///
/// 说明:获取系统信息
/// 创建人:龚宇超
/// 创建日期:2018-02-28
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
public static DataRow GetSystemModule(string menuCode)
{
string sqlValue = "select * from v_systemdlltab where DllCoid=@DllCoid";
DataTable dt = SqlHelper.ExecuteDataTable(sqlValue, new SqlParameter[] { new SqlParameter("@DllCoid", menuCode) });
return dt.Rows.Count > 0 ? dt.Rows[0] : null;
}
///
/// 说明:根据附件编号获取附件
/// 创建人:龚宇超
/// 创建日期:2018-06-06
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// DataTable.
public static DataRow GetTempletFile(int fileNo)
{
string sqlValue = "select * from P_fm_FileTab where fileId=@fileNo";
DataTable dt = SqlHelper.ExecuteDataTable(sqlValue, new SqlParameter[] { new SqlParameter("@fileNo", fileNo) });
return dt.Rows.Count > 0 ? dt.Rows[0] : null;
}
///
/// 说明:根据附件名字获取附件
/// 创建人:王一帆
/// 创建日期:2019-12-13
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// DataTable.
public static DataRow GetTempletFile(string sName, string webpath = "")
{
string sqlValue = "select * from P_fm_FileTab where sName=@sName";
DataTable dt = SqlHelper.ExecuteDataTable(sqlValue, new SqlParameter[] { new SqlParameter("@sName", sName) });
if (dt.Rows.Count > 1)
{
//if (!webpath.StartsWith("%")) webpath = "%" + webpath;
sqlValue = string.Format("select * from P_fm_FileTab where sName='{0}' and (webpath like '%{1}' or webpath like '%{2}')", sName, webpath, HttpUtility.UrlDecode(webpath).Replace("#", "%23").Replace("%2f", "/"));
dt = SqlHelper.ExecuteDataTable(sqlValue);
}
return dt.Rows.Count > 0 ? dt.Rows[0] : null;
}
///
/// 说明:获取附件左侧树结构数据
/// 创建人:龚宇超
/// 创建日期:2018-01-08
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The species no.
/// DataTable.
///
public static DataTable GetAttachSpecies(string speciesNo)
{
string sqlValue = string.Format("select * from bmp_ProductSpeciesTab where SpeciesNo like '{0}%'", speciesNo);
return GetDataTableResult(sqlValue);
}
///
/// 说明:获取符合锁定解锁条件的文件
/// 创建人:龚宇超
/// 创建日期:2018-02-24
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// 附件Id.
/// DataTable.
///
public static DataTable GetMatchConditionFiles(string fileNo)
{
string sqlValue = @"select a.fileId from P_fm_FileTab a
inner join bmp_ProductSpeciesTab b on a.speciesno=b.SpeciesNo
where charindex(','+cast(fileid as varchar)+',','," + fileNo + ",')>0 and (charindex('," + ERPInfo.Instance.UserName + ",',','+b.str4+',')>0 or charindex('|" + ERPInfo.Instance.UserName + "|','|'+b.str4+'|')>0 or a.creator='" + ERPInfo.Instance.UserId + "')";
object obj = SqlHelper.ExecuteScalar(CommandType.Text, "select 1 as zt from sys.columns where object_id=object_id('bmp_ProductSpeciesTab') and name='str4'");
if ((obj == null) || (obj.ToString() != "1"))
sqlValue = @"select a.fileId from P_fm_FileTab a
inner join bmp_ProductSpeciesTab b on a.speciesno=b.SpeciesNo
where charindex(','+cast(fileid as varchar)+',','," + fileNo + ",')>0 and ( a.creator='" + ERPInfo.Instance.UserId + "')";
return SqlHelper.ExecuteDataTable(sqlValue);
}
///
/// 说明:获取附件的签名集
/// 创建人:龚宇超
/// 创建日期:2018-06-06
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// DataTable.
public static DataTable GetSignSources(int fileNo)
{
string sqlValue = "select * from P_PDFSignTab where FileId=@FileNo";
return SqlHelper.ExecuteDataTable(sqlValue, new SqlParameter[] { new SqlParameter("@FileNo", fileNo) });
}
///
/// 说明:获取拍照文件列
/// 创建人:龚宇超
/// 创建日期:2018-06-11
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// DataTable.
public static DataTable GetCameraFileData()
{
string sqlValue = @" select '1' id , 'stepCode' fieldName, 65 width, '' sysname , '编号' username, '' dataFormat union
select '2' , 'Name' ,148 , '' , '文件名' , '' union
select '3' , 'Created' ,120 , '' , '时间' , '' union
select '4' , 'key' ,67 , '' , '隐藏字段' , '' ";
return SqlHelper.ExecuteDataTable(sqlValue);
}
///
/// 说明:获取附件条数
/// 创建人:龚宇超
/// 创建日期:2018-08-10
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// System.Int32.
public static int GetFileCount(string dirid, string pid)
{
DataTable dt = SqlHelper.ExecuteDataTable(string.Format("select 1 from P_fm_FileTab where parentId='{0}'", GetAttachDirectoryId(dirid, pid)));
return dt == null ? 0 : Convert.ToInt32(dt.Rows.Count);
}
}
}