Build Deep high-quality website with Core Pro 5.1.8 and Theme 1.0.6
Lập trình quản lý ảnh mô hình 3 lớp dùng procedure c#
Chức năng quản lý ảnh mô hình 3 lớp dùng procedure c#
File truy vấn dữ liêu PHOTO_DAL.CS
//==============================================
// Author: ATC @ 2022
// Create date: 1/6/2022 10:46:51 PM
// Project: megastore
// Description: Auto code by ATC PRO
// Website: http://.www.atcpro.info
//==============================================
using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using megastore.Entities;
namespace megastore.DataAccess
{
public class D_Photos
{
Connection x;
public D_Photos()
{
x = new Connection();
}
public D_Photos(string s)
{
x = new Connection(s);
}
public DataTable SelectAll()
{
return x.ExecuteData("select * from Photos");
}
//---------------------------- SelectTop -------------------------------
public DataTable SelectTop(string Top ,string Where,string Order)
{
this.x.KetNoi();
SqlCommand d = new SqlCommand();
d.CommandText = "Photos_SelectTop";
d.CommandType = CommandType.StoredProcedure;
d.Connection = x.cn;
d.Parameters.AddWithValue("@Top", Top);
d.Parameters.AddWithValue("@Where", Where);
d.Parameters.AddWithValue("@Order", Order);
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(d);
da.Fill(dt);
x.cn.Close();
return dt;
}
public void INSERT(Int32 ID,String Title,String ImgUrl,Int32 Sort,String Parent,String Group,String Status,String Link,String Note)
{
string sql= "INSERT INTO Photos(ID,Title,ImgUrl,Sort,Parent,Group,Status,Link,Note) VALUES (@ID,@Title,@ImgUrl,@Sort,@Parent,@Group,@Status,@Link,@Note)";
this.x.KetNoi();
SqlCommand cm = new SqlCommand(sql,x.cn);
cm.CommandType = CommandType.Text;
cm.Parameters.AddWithValue(@"ID",ID);
cm.Parameters.AddWithValue(@"Title",Title);
cm.Parameters.AddWithValue(@"ImgUrl",ImgUrl);
cm.Parameters.AddWithValue(@"Sort",Sort);
cm.Parameters.AddWithValue(@"Parent",Parent);
cm.Parameters.AddWithValue(@"Group",Group);
cm.Parameters.AddWithValue(@"Status",Status);
cm.Parameters.AddWithValue(@"Link",Link);
cm.Parameters.AddWithValue(@"Note",Note);
cm.ExecuteNonQuery();
x.cn.Close();
}
public void UPDATE(Int32 ID,String Title,String ImgUrl,Int32 Sort,String Parent,String Group,String Status,String Link,String Note)
{
string sql= "UPDATE Photos SET [ID][email protected],[Title][email protected],[ImgUrl][email protected],[Sort][email protected],[Parent][email protected],[Group][email protected],[Status][email protected],[Link][email protected],[Note][email protected] WHERE [ID][email protected]";
this.x.KetNoi();
SqlCommand cm = new SqlCommand(sql,x.cn);
cm.CommandType = CommandType.Text;
cm.Parameters.AddWithValue(@"ID",ID);
cm.Parameters.AddWithValue(@"Title",Title);
cm.Parameters.AddWithValue(@"ImgUrl",ImgUrl);
cm.Parameters.AddWithValue(@"Sort",Sort);
cm.Parameters.AddWithValue(@"Parent",Parent);
cm.Parameters.AddWithValue(@"Group",Group);
cm.Parameters.AddWithValue(@"Status",Status);
cm.Parameters.AddWithValue(@"Link",Link);
cm.Parameters.AddWithValue(@"Note",Note);
cm.ExecuteNonQuery();
x.cn.Close();
}
public void Delete(Int32 ID)
{
this.x.KetNoi();
string sql=" DELETE FROM [Photos] WHERE [ID][email protected] ";
SqlCommand cm = new SqlCommand(sql,x.cn);
cm.CommandType = CommandType.Text;
cm.Parameters.AddWithValue(@"ID",ID);
cm.ExecuteNonQuery();
x.cn.Close();
}
}
}
Cách 2 dùng nối chuỗi
//==============================================
// Author: ATC @ 2022
// Create date: 1/6/2022 10:49:51 PM
// Project: megastore
// Description: Auto code by ATC PRO
// Website: http://.www.nhatcntt.net
//==============================================
using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using megastore.Entities;
namespace megastore.DataAccess
{
public class D_Photos
{
Connection x;
public D_Photos()
{
x = new Connection();
}
public D_Photos(string s)
{
x = new Connection(s);
}
public DataTable SelectAll()
{
return x.ExecuteData("select * from Photos");
}
public void Insert(E_Photos iPhotos)
{
string sql= "INSERT INTO Photos(ID,Title,ImgUrl,Sort,Parent,Group,Status,Link,Note) VALUES ("+iPhotos.ID +",N'"+iPhotos.Title +"',N'"+iPhotos.ImgUrl +"',"+iPhotos.Sort +",N'"+iPhotos.Parent +"',N'"+iPhotos.Group +"',N'"+iPhotos.Status +"',N'"+iPhotos.Link +"',N'"+iPhotos.Note +"')";
this.x.KetNoi();
SqlCommand cm = new SqlCommand(sql, x.cn);
cm.CommandType = CommandType.Text;
cm.ExecuteNonQuery();
x.cn.Close();
}
public void Update(E_Photos uPhotos)
{
string sql= "UPDATE Photos SET [ID]=N'"+uPhotos.ID+"',[Title]="+uPhotos.Title+",[ImgUrl]="+uPhotos.ImgUrl+",[Sort]=N'"+uPhotos.Sort+"',[Parent]="+uPhotos.Parent+",[Group]="+uPhotos.Group+",[Status]="+uPhotos.Status+",[Link]="+uPhotos.Link+",[Note]="+uPhotos.Note+" WHERE [ID]="+uPhotos.ID+"";
this.x.KetNoi();
SqlCommand cm = new SqlCommand(sql, x.cn);
cm.CommandType = CommandType.Text;
cm.ExecuteNonQuery();
x.cn.Close();
}
public void Delete(E_Photos uPhotos)
{
this.x.KetNoi();
string sql=" DELETE FROM Photos WHERE [ID]="+uPhotos.ID+" ";
SqlCommand cm = new SqlCommand(sql, x.cn);
cm.CommandType = CommandType.Text;
cm.ExecuteNonQuery();
x.cn.Close();
}
}
}
0 Nhận xét
Hãy trở thành người đầu tiên viết chia sẽ cảm nghĩ của mình bên dưới nhé!
Thêm Bình luận