V
vikas
I am trying to create a document version management system using
ADO.net and SQL server.
I am storing the document in an Image field in the database.
I could sucessfully implement check in , check out, undo check out
functions but i am having one problem.
When i check out a document , make some changes to it and do check in
all previous versions of the document are also changes in such a way
that they also have the same document.
to chekin a document i first create a new database row..copy thw basic
infor from previous row..and then load the new document in the row..
please see the code below
//Get values from data row associated with the grid and make changes
in the master dataset table
private bool CheckInRow(DataRow dr, String sFile)
{
double fVersionNo ;
DataTable dt =null;
DataRow drNew = null;
fVersionNo = Convert.ToDouble(dr[m_strVersionCol].ToString());
dt = m_dsMaster.Tables[m_strTable];
drNew = dt.NewRow();
drNew[CUtil.GetColumn(m_strIDCol)] = new
TnrData.CUtil().GetTempID();
drNew[CUtil.GetColumn(m_strIDParentCol)] = dr[m_strIDParentCol];
drNew[CUtil.GetColumn(m_strShortCutCol)] = dr[m_strShortCutCol];
drNew[CUtil.GetColumn(m_strDocNameCol)] = dr[m_strDocNameCol];
drNew[CUtil.GetColumn(m_strDateRecievedCol)] = DateTime.Now;
drNew[CUtil.GetColumn(m_strAddedByCol)] = dr[m_strAddedByCol];
drNew[CUtil.GetColumn(m_strCommentCol)] = dr[m_strCommentCol];
drNew[CUtil.GetColumn(m_strIDDocTypeCol)] = dr[m_strIDDocTypeCol];
drNew[CUtil.GetColumn(m_strFileNameCol)] = dr[m_strFileNameCol];
drNew[CUtil.GetColumn(m_strSizeCol)] = CLGN.GetFileSize(sFile) /
1000;
drNew[CUtil.GetColumn(m_strLiveLinkCol)] = dr[m_strLiveLinkCol];
drNew[CUtil.GetColumn(m_strDocTypeCol)] = dr[m_strDocTypeCol];
drNew[CUtil.GetColumn(m_strCurrentCol)] = true;
drNew[CUtil.GetColumn(m_strCheckedOutCol)] = false;
drNew[CUtil.GetColumn(m_strVersionCol)] = fVersionNo + 1.0;
//CLGN.SetFileToRow(drNew, sFile,
CUtil.GetColumn(m_strDocImageCol));
try
{
//Create a temporary file for check in as SQL server needs to have
unique blob file
StringBuilder sb = new StringBuilder(sFile);
sb.Append("Tnr");sb.Append(drNew[CUtil.GetColumn(m_strVersionCol)].ToString());
sb.Append(".");sb.Append(drNew[CUtil.GetColumn(m_strDocTypeCol)].ToString());
String strCheckInFileName = sb.ToString();
//Make sure that file does not exist and then copy to create a
temporary file
File.Delete(strCheckInFileName);
File.Copy(sFile,strCheckInFileName);
FileStream fs = new
FileStream(strCheckInFileName,FileMode.Open,FileAccess.Read);
Byte[] bt = new Byte[(int)(fs.Length)];
fs.Read(bt, 0, (int)(fs.Length));
fs.Close();
drNew[CUtil.GetColumn(m_strDocImageCol)] = bt;
File.Delete(strCheckInFileName);
}
catch(System.IO.IOException ioe)
{
MessageBox.Show("Can Not Read File! \nThe Document File '" +
dr[m_strFileNameCol].ToString() +"' Does Not Exist In Checked Out
Folder Or Is Locked By Some Other Application.\n Please Close All
Aplications Using The File Before Checking In" , "",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return false;
}
dt.Rows.Add(drNew);
return true;
Could somebody please help and explain this behavior
Thanks,
Vikas
ADO.net and SQL server.
I am storing the document in an Image field in the database.
I could sucessfully implement check in , check out, undo check out
functions but i am having one problem.
When i check out a document , make some changes to it and do check in
all previous versions of the document are also changes in such a way
that they also have the same document.
to chekin a document i first create a new database row..copy thw basic
infor from previous row..and then load the new document in the row..
please see the code below
//Get values from data row associated with the grid and make changes
in the master dataset table
private bool CheckInRow(DataRow dr, String sFile)
{
double fVersionNo ;
DataTable dt =null;
DataRow drNew = null;
fVersionNo = Convert.ToDouble(dr[m_strVersionCol].ToString());
dt = m_dsMaster.Tables[m_strTable];
drNew = dt.NewRow();
drNew[CUtil.GetColumn(m_strIDCol)] = new
TnrData.CUtil().GetTempID();
drNew[CUtil.GetColumn(m_strIDParentCol)] = dr[m_strIDParentCol];
drNew[CUtil.GetColumn(m_strShortCutCol)] = dr[m_strShortCutCol];
drNew[CUtil.GetColumn(m_strDocNameCol)] = dr[m_strDocNameCol];
drNew[CUtil.GetColumn(m_strDateRecievedCol)] = DateTime.Now;
drNew[CUtil.GetColumn(m_strAddedByCol)] = dr[m_strAddedByCol];
drNew[CUtil.GetColumn(m_strCommentCol)] = dr[m_strCommentCol];
drNew[CUtil.GetColumn(m_strIDDocTypeCol)] = dr[m_strIDDocTypeCol];
drNew[CUtil.GetColumn(m_strFileNameCol)] = dr[m_strFileNameCol];
drNew[CUtil.GetColumn(m_strSizeCol)] = CLGN.GetFileSize(sFile) /
1000;
drNew[CUtil.GetColumn(m_strLiveLinkCol)] = dr[m_strLiveLinkCol];
drNew[CUtil.GetColumn(m_strDocTypeCol)] = dr[m_strDocTypeCol];
drNew[CUtil.GetColumn(m_strCurrentCol)] = true;
drNew[CUtil.GetColumn(m_strCheckedOutCol)] = false;
drNew[CUtil.GetColumn(m_strVersionCol)] = fVersionNo + 1.0;
//CLGN.SetFileToRow(drNew, sFile,
CUtil.GetColumn(m_strDocImageCol));
try
{
//Create a temporary file for check in as SQL server needs to have
unique blob file
StringBuilder sb = new StringBuilder(sFile);
sb.Append("Tnr");sb.Append(drNew[CUtil.GetColumn(m_strVersionCol)].ToString());
sb.Append(".");sb.Append(drNew[CUtil.GetColumn(m_strDocTypeCol)].ToString());
String strCheckInFileName = sb.ToString();
//Make sure that file does not exist and then copy to create a
temporary file
File.Delete(strCheckInFileName);
File.Copy(sFile,strCheckInFileName);
FileStream fs = new
FileStream(strCheckInFileName,FileMode.Open,FileAccess.Read);
Byte[] bt = new Byte[(int)(fs.Length)];
fs.Read(bt, 0, (int)(fs.Length));
fs.Close();
drNew[CUtil.GetColumn(m_strDocImageCol)] = bt;
File.Delete(strCheckInFileName);
}
catch(System.IO.IOException ioe)
{
MessageBox.Show("Can Not Read File! \nThe Document File '" +
dr[m_strFileNameCol].ToString() +"' Does Not Exist In Checked Out
Folder Or Is Locked By Some Other Application.\n Please Close All
Aplications Using The File Before Checking In" , "",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return false;
}
dt.Rows.Add(drNew);
return true;
Could somebody please help and explain this behavior
Thanks,
Vikas