📄 piclib.cs
字号:
//**************************************************************************************************************
//* 本模块主要功能:
//*
//* 版权: zsjt
//* 作者: 赵现发
//* Email:zxf19810226@163.com
//* 时间: 2008年12月1日
//* (******* 请保留以上信息 *******)
//**************************************************************************************************************
using System;
using System.Data;
using System.IO;
using System.Drawing;
using System.Collections;
using System.Windows.Forms;
namespace DataAccessLayer
{
/// <summary>
/// 文件夹节点实体类。
/// </summary>
public class PicLib
{
public int PicLibID = 0;
//用于区分是否已更改过,保存之后,由外部对象重置为False
public bool HasChanged = false;
private string _text = "";
public string Text
{
get
{
return this._text;
}
set
{
if(this._text != value)
{
this._text = value;
this.HasChanged = true;
}
}
}
private string _rtf = "";
public string RTFText
{
get
{
return this._rtf;
}
set
{
if(this._rtf != value)
{
this._rtf = value;
this.HasChanged = true;
}
}
}
private string _belongto = "";
public string BelongTo
{
get
{
return this._belongto;
}
set
{
if(value.Length > 255)
{
value = value.Substring(0, 255);
}
if(value == string.Empty)
{
throw new Exception("节点的路径不能为空");
}
//有可能出错,检查是否路径以"\"结束
if(value.Substring(value.Length - 1, 1) != "\\")
{
value = value + "\\";
}
//----------------------------------------
if(this._belongto != value)
{
this._belongto = value;
this.HasChanged = true;
}
}
}
public DateTime InputDate = DateTime.Today;
//所包含之文件对象(Attachment)清单
public ArrayList AttachFiles = new ArrayList();
}
public class PicLibAccessObj : BaseAccessObj
{
private AttachFileAccessObj FileSaver;
public PicLibAccessObj(OLEDBAccessObj dbObj) : base(dbObj)
{
this.FileSaver = new AttachFileAccessObj(dbObj);
}
/// <summary>
/// 将自身数据存入数据库中,不用保存文件,因为已经在创建文件时保存了
/// </summary>
/// <param name="obj"></param>
public void SaveMeToDB(PicLib obj)
{
if(this.dbObj == null)
return;
string strSQL;
System.Collections.Specialized.ListDictionary pars = new System.Collections.Specialized.ListDictionary();
Attachment fileObj;
int PicLibFileID;
if(obj.BelongTo.Substring(obj.BelongTo.Length - 1, 1) != "\\")
{
obj.BelongTo = obj.BelongTo + "\\";
}
try
{
//保存主记录
strSQL = "AddPicLibRecord";
pars.Add("PicLibIDValue", obj.PicLibID);
pars.Add("TextValue", obj.Text);
pars.Add("BelongToValue", obj.BelongTo);
pars.Add("InputDateValue", obj.InputDate);
pars.Add("RTFTextValue", obj.RTFText);
this.dbObj.ExecSQLCommand2(strSQL, pars);
//如果有附件
if(obj.AttachFiles.Count > 0)
{
//插入数据库的关联表
strSQL = "AddPicLibFileRecord";
for(int i=0; i < obj.AttachFiles.Count; i++)
{
fileObj = obj.AttachFiles[i] as Attachment;
pars.Clear();
//获取PicLibFile表的下一个ID
PicLibFileID = this.dbObj.GetMaxValueFromTable("PicLibFile", "PicLibFileID") + 1;
pars.Add("PicLibFileIDValue", PicLibFileID);
pars.Add("PicLibIDValue", obj.PicLibID);
pars.Add("FileIDValue", fileObj.FileID);
pars.Add("InputDateValue", obj.InputDate);
this.dbObj.ExecSQLCommand2(strSQL, pars);
}
}
}
catch(Exception ex)
{
throw new Exception("在执行存储过程AddPicLibRecord或AddPicLibFileRecord时出错,系统给出的信息为:" + ex.Message);
}
}
/// <summary>
/// 更新对象所对应的数据库记录信息,不更新文件内容
/// </summary>
public void UpdateDBRow(PicLib obj, bool FileListNotChange)
{
if(obj == null)
return;
string strSQL;
System.Collections.Specialized.ListDictionary pars = new System.Collections.Specialized.ListDictionary();
Attachment fileObj;
int PicLibFileID;
try
{
strSQL = "UpdatePicLibRecord";
if(obj.Text == null)
obj.Text = "";
//有可能出错,检查是否路径以"\"结束
if(obj.BelongTo.Substring(obj.BelongTo.Length - 1, 1) != "\\")
{
obj.BelongTo = obj.BelongTo + "\\";
}
//更新主记录
pars.Add("TextValue", obj.Text);
pars.Add("BelongToValue", obj.BelongTo);
pars.Add("InputDateValue", obj.InputDate);
pars.Add("RTFTextValue", obj.RTFText);
pars.Add("PicLibIDValue", obj.PicLibID);
this.dbObj.ExecSQLCommand2(strSQL, pars);
//更新关联表记录
//如果文件列表有改变
if(FileListNotChange == false)
{
//先删除所有的相关关联表记录
strSQL = "Delete * from PicLibFile where PicLibFileID=" + obj.PicLibID;
this.dbObj.ExecSQLCommand(strSQL);
//如果有附件
if(obj.AttachFiles.Count > 0)
{
//插入数据库中的关联表
strSQL = "AddPicLibFileRecord";
for(int i=0; i<obj.AttachFiles.Count; i++)
{
fileObj = obj.AttachFiles[i] as Attachment;
//获取PicLibFile表的下一个ID
PicLibFileID = this.dbObj.GetMaxValueFromTable("PicLibFile", "PicLibFileID") + 1;
pars.Clear();
pars.Add("PicLibFileIDValue", PicLibFileID);
pars.Add("PicLibIDValue", obj.PicLibID);
pars.Add("FileIDValue", fileObj.FileID);
pars.Add("InputDateValue", obj.InputDate);
this.dbObj.ExecSQLCommand2(strSQL, pars);
}
}
}
}
catch(Exception ex)
{
throw new Exception("在执行存储过程UpdatePicLibRecord时出错,系统给出的信息为:" + ex.Message);
}
}
/// <summary>
/// 删除数据库记录
/// </summary>
/// <param name="BelongTo"></param>
public void DeleteDBRow(string BelongTo)
{
string strSQL;
try
{
//删除文件
strSQL = "DeleteFileOfPicLibNode";
System.Collections.Specialized.ListDictionary pars = new System.Collections.Specialized.ListDictionary();
pars.Add("BelongValue", BelongTo + "%");
this.dbObj.ExecSQLCommand2(strSQL, pars);
//删除关联记录
strSQL = "Delete * From PicLibFile where PicLibFile.PicLibID in (Select PicLib.PicLibID From PicLib where PicLib.BelongTo Like '" + BelongTo + "%')";
//MessageBox.Show(strSQL);
this.dbObj.ExecSQLCommand(strSQL);
//删除自身记录
strSQL = "Delete * From PicLib where BelongTo Like '" + BelongTo + "%'";
this.dbObj.ExecSQLCommand(strSQL);
}
catch(Exception ex)
{
throw new Exception("在删除PicLib记录时出错,系统给出的信息是:" + ex.Message);
}
}
/// <summary>
/// 给关联表增加一条记录
/// </summary>
/// <param name="FolderID"></param>
/// <param name="fileObj"></param>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -