using System;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
[ServiceContract(Namespace = "")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class UploadDac
{
private string _ConnectionString; //연결문자열 보관
//ConnectionString 보관하여 사용
public UploadDac()
{
//Web.Config의 ConnectionString 을 딱 한번만 보관하여 사용....
_ConnectionString =
ConfigurationManager.ConnectionStrings
["ConnectionString"].ConnectionString;
}
//메서드 : 저장 프로시저만큼 ..
public int AddUpload
(string name, string email, string title, string PostIp, string content
, string password, string encoding, string homepage, string fileName,
int fileSize)
{
SqlConnection con = new SqlConnection(_ConnectionString);
SqlCommand cmd = new SqlCommand("WriteUpload",con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@name",name);
cmd.Parameters.AddWithValue("@email",email);
cmd.Parameters.AddWithValue("@title",title);
cmd.Parameters.AddWithValue("@PostIp",PostIp);
cmd.Parameters.AddWithValue("@content",content);
cmd.Parameters.AddWithValue("@password",password);
cmd.Parameters.AddWithValue("@encoding",encoding);
cmd.Parameters.AddWithValue("@homepage",homepage);
cmd.Parameters.AddWithValue("@fileName",fileName);
cmd.Parameters.AddWithValue("@fileSize",fileSize);
con.Open();
int result = cmd.ExecuteNonQuery();
con.Close();
return result;
}
public DataSet GetUploads()
{
SqlConnection conn = new SqlConnection(_ConnectionString);
SqlCommand cmd = new SqlCommand("ListUpload" ,conn);
cmd.CommandType= CommandType.StoredProcedure;
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds,"Upload");
return ds;
}
//수정
public int UpdateUpload(UploadEntity entity)
{
SqlConnection con = new SqlConnection(_ConnectionString);
SqlCommand cmd = new SqlCommand("ModifyUpload", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Name",entity.Name);
cmd.Parameters.AddWithValue("@Email",entity.Email);
cmd.Parameters.AddWithValue("@Title",entity.Title);
cmd.Parameters.AddWithValue("@ModifyIP",entity.ModifyIP);
cmd.Parameters.AddWithValue("@Content",entity.Content);
cmd.Parameters.AddWithValue("@Encoding", entity.Encoding);
cmd.Parameters.AddWithValue("@Homepage", entity.Homepage);
cmd.Parameters.AddWithValue("@Password", entity.Password);
cmd.Parameters.AddWithValue("@FileName", entity.FileName);
cmd.Parameters.AddWithValue("@FileSize", entity.FileSize);
cmd.Parameters.AddWithValue("@Num", entity.Num);
con.Open();
int result = cmd.ExecuteNonQuery();
con.Close();
return result;
}
//상세
public SqlDataReader GetUploadByNum(int num)
{
SqlConnection conn = new SqlConnection(_ConnectionString);
SqlCommand cmd = new SqlCommand("ViewUpload",conn);
cmd.Parameters.AddWithValue("@Num",num);
SqlDataReader dr = cmd.ExecuteReader();
return dr; //Close() =-> Using사용해서 Close 처리
}
//삭제
public int DeleteUpload(int num, string password)
{
SqlConnection con = new SqlConnection(_ConnectionString);
SqlCommand cmd = new SqlCommand("DeleteUpload", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Password", password);
cmd.Parameters.AddWithValue("@Num", num);
con.Open();
int result = cmd.ExecuteNonQuery();
con.Close();
return result;
}
//검색
public IDataReader GetUploadByWord
(string searchField, string searchQuery)
{
SqlConnection conn = new SqlConnection(_ConnectionString);
SqlCommand cmd = new SqlCommand("SearchUpload", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@SearchField", searchField);
cmd.Parameters.AddWithValue("@SearchQuery", searchQuery);
SqlDataReader dr = cmd.ExecuteReader();
return dr;
}
//다운 증가
public void UpdateDownCount(string fileName)
{
SqlConnection conn = new SqlConnection(_ConnectionString);
SqlCommand cmd = new SqlCommand("IncreaseDownCountUpload", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@fileName", fileName);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
}
} |