/// <summary> /// /// </summary> /// <param name="doc"></param> public void SaveDocumentAttributes(comm.Document doc) { using (SqlConnection con = new SqlConnection(_con)) { SqlCommand cmd = new SqlCommand(); cmd.Connection = con; cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "DocAttrSet"; cmd.Parameters.Clear(); cmd.Parameters.AddWithValue("@Key", doc.ID); cmd.Parameters.AddWithValue("@Name", doc.Name); cmd.Parameters.AddWithValue("@Kind", doc.Kind.ID); cmd.Parameters.AddWithValue("@ModifyAt", doc.ModifyAt); cmd.Parameters.AddWithValue("@UsrName", "EArchiv"); con.Open(); cmd.ExecuteNonQuery(); } }
/// <summary> /// /// </summary> /// <param name="doc"></param> public void SaveDocumentSource(comm.Document doc) { using (SqlConnection con = new SqlConnection(_con)) { SqlCommand cmd = new SqlCommand(); cmd.Connection = con; cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "DocSet"; cmd.Parameters.Clear(); cmd.Parameters.AddWithValue("@Key", doc.ID); cmd.Parameters.AddWithValue("@Name", doc.Name); cmd.Parameters.AddWithValue("@Kind", doc.Kind.ID); cmd.Parameters.AddWithValue("@ModifyAt", doc.ModifyAt); cmd.Parameters.AddWithValue("@UsrName", "EArchiv"); cmd.Parameters.AddWithValue("@Hash", doc.ConvertHash()); long len; byte[] buf; /* * long len = doc.Thumbnails.StreamSource.Length; * byte[] buf = new byte[len]; * doc.Thumbnails.StreamSource.Read(buf, 0, (int)len); * cmd.Parameters.AddWithValue("Thumbnails", buf); */ buf = new byte[2]; buf[0] = 1; buf[1] = 2; cmd.Parameters.AddWithValue("@Thumbnails", buf); FileStream s = new FileStream((doc.Source.StreamSource as FileStream).Name, FileMode.Open); len = s.Length; buf = new byte[len]; s.Position = 0; s.Read(buf, 0, (int)len); cmd.Parameters.AddWithValue("@Raw", buf); con.Open(); cmd.ExecuteNonQuery(); } }
/// <summary> /// /// </summary> /// <param name="doc"></param> /// <returns></returns> public bool MarkDeleteDocument(comm.Document doc) { using (SqlConnection con = new SqlConnection(_con)) { try { bool rslt = false; SqlCommand cmd = new SqlCommand("DocDelMark", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@Key", doc.ID); con.Open(); cmd.ExecuteNonQuery(); rslt = true; return(rslt); } catch (Exception e) { throw new Exception(e.Message); } } }
/// <summary> /// /// </summary> /// <param name="doc"></param> /// <param name="orgCode"></param> /// <param name="contractCode"></param> public void SaveDocument(comm.Document doc, string orgCode, string contractCode) { using (SqlConnection con = new SqlConnection(_con)) { using (SqlCommand cmd = new SqlCommand()) { cmd.Connection = con; cmd.CommandType = CommandType.StoredProcedure; con.Open(); SqlTransaction tranc = con.BeginTransaction(); cmd.Transaction = tranc; try { //первая часть сохраняем сам документ cmd.CommandText = "DocAdd"; cmd.Parameters.Clear(); cmd.Parameters.AddWithValue("@Name", doc.Name); cmd.Parameters.AddWithValue("@Kind", doc.Kind.ID); cmd.Parameters.AddWithValue("@UsrName", "EArchiv"); cmd.Parameters.AddWithValue("@Hash", doc.ConvertHash()); //TODO: Костыль позже убрать long len; byte[] buf; if (doc.Thumbnails != null) { len = doc.Thumbnails.StreamSource.Length; buf = new byte[len]; doc.Thumbnails.StreamSource.Read(buf, 0, (int)len); cmd.Parameters.AddWithValue("@Thumbnails", buf); } else { buf = new byte[2]; buf[0] = 1; buf[1] = 2; cmd.Parameters.AddWithValue("@Thumbnails", buf); } FileStream s = new FileStream((doc.Source.StreamSource as FileStream).Name, FileMode.Open); len = s.Length; buf = new byte[len]; s.Position = 0; s.Read(buf, 0, (int)len); cmd.Parameters.AddWithValue("@Raw", buf); int key = -1; SqlParameter parametr = new SqlParameter("@Key", key); parametr.Direction = ParameterDirection.Output; cmd.Parameters.Add(parametr); cmd.ExecuteNonQuery(); doc.setID(Convert.ToInt32(cmd.Parameters["@Key"].Value)); // вторая часть связываем документ с договором cmd.CommandText = "DocContractAdd"; cmd.Parameters.Clear(); cmd.Parameters.AddWithValue("@Doc", doc.ID); cmd.Parameters.AddWithValue("@OrgCode", orgCode); cmd.Parameters.AddWithValue("@ContractCode", contractCode); cmd.Parameters.AddWithValue("UsrName", "EContract"); parametr = new SqlParameter("@Key", key); parametr.Direction = ParameterDirection.Output; cmd.Parameters.Add(parametr); cmd.ExecuteNonQuery(); tranc.Commit(); } catch (Exception e) { tranc.Rollback(); throw new Exception(e.Message); } } } }
/// <summary> /// /// </summary> /// <param name="doc"></param> /// <param name="folder"></param> /// <param name="ls"></param> public void SaveDocument(comm.Document doc, comm.Folder folder, int ls) { using (SqlConnection con = new SqlConnection(_con)) { SqlCommand cmd = new SqlCommand(); cmd.Connection = con; cmd.CommandType = CommandType.StoredProcedure; con.Open(); SqlTransaction tranc = con.BeginTransaction(); cmd.Transaction = tranc; try { //первая часть сохраняем сам документ cmd.CommandText = "DocAdd"; cmd.Parameters.Clear(); cmd.Parameters.AddWithValue("@Name", doc.Name); cmd.Parameters.AddWithValue("@Kind", doc.Kind.ID); cmd.Parameters.AddWithValue("@UsrName", "EArchiv"); cmd.Parameters.AddWithValue("@Hash", doc.ConvertHash()); //TODO: Костыль позже убрать long len; byte[] buf; if (doc.Thumbnails != null) { len = doc.Thumbnails.StreamSource.Length; buf = new byte[len]; doc.Thumbnails.StreamSource.Read(buf, 0, (int)len); cmd.Parameters.AddWithValue("@Thumbnails", buf); } else { buf = new byte[2]; buf[0] = 1; buf[1] = 2; cmd.Parameters.AddWithValue("@Thumbnails", buf); } FileStream s = new FileStream((doc.Source.StreamSource as FileStream).Name, FileMode.Open); len = s.Length; buf = new byte[len]; s.Position = 0; s.Read(buf, 0, (int)len); cmd.Parameters.AddWithValue("@Raw", buf); int key = -1; SqlParameter parametr = new SqlParameter("@Key", key); parametr.Direction = ParameterDirection.Output; cmd.Parameters.Add(parametr); cmd.ExecuteNonQuery(); doc.setID(Convert.ToInt32(cmd.Parameters["@Key"].Value)); //вторая часть добавляем документ в папку //TODO: Надо подумать как переделать /* * cmd.CommandText = "DocFolderAdd"; * * cmd.Parameters.Clear(); * cmd.Parameters.AddWithValue("@DocID", key); * cmd.Parameters.AddWithValue("FolderID", folder.ID); * cmd.Parameters.AddWithValue("UsrName", "EArchiv"); * * parametr = new SqlParameter("@Key", key); * parametr.Direction = ParameterDirection.Output; * cmd.Parameters.Add(parametr); * * cmd.ExecuteNonQuery(); */ // третья часть связываем документ с лицевым счетом cmd.CommandText = "DocLsAdd"; cmd.Parameters.Clear(); cmd.Parameters.AddWithValue("@Doc", doc.ID); cmd.Parameters.AddWithValue("Ls", ls); cmd.Parameters.AddWithValue("UsrName", "EArchiv"); parametr = new SqlParameter("@Key", key); parametr.Direction = ParameterDirection.Output; cmd.Parameters.Add(parametr); cmd.ExecuteNonQuery(); tranc.Commit(); } catch (Exception e) { try { tranc.Rollback(); throw new Exception(e.Message); } catch (Exception ex) { throw new Exception(ex.Message); } } } }