本文整理汇总了C#中DataBase.Connection方法的典型用法代码示例。如果您正苦于以下问题:C# DataBase.Connection方法的具体用法?C# DataBase.Connection怎么用?C# DataBase.Connection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataBase
的用法示例。
在下文中一共展示了DataBase.Connection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: loadVideos
protected void loadVideos()
{
DataBase db = new DataBase();
SqlConnection conn = db.Connection();
SqlCommand cmd = db.GetCommand(conn, "dbo.GetVideos");
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
try
{
conn.Open();
da.Fill(ds, "Videos");
}
catch (Exception err)
{
lblError.Text = err.Message;
}
finally
{
conn.Close();
conn.Dispose();
}
if (ds.Tables["Videos"].Rows.Count == 0)
{
lblError.Text = "Нема внесено видеа во базата!";
return;
}
ViewState["dsVideos"] = ds;
gvVideos.DataSource = ds.Tables["Videos"];
gvVideos.DataBind();
}
示例2: fillNewsGrid
protected void fillNewsGrid()
{
DataSet ds = new DataSet();
DataBase db = new DataBase();
SqlConnection conn = db.Connection();
SqlCommand cmd = db.GetCommand(conn, "dbo.GetNewsArchive");
SqlDataAdapter da = new SqlDataAdapter(cmd);
try
{
conn.Open();
da.Fill(ds, "News");
}
catch (Exception err)
{
lblError.Text = err.Message;
}
finally
{
conn.Close();
conn.Dispose();
}
if (ds.Tables["News"].Rows.Count == 0)
{
lblError.Text = "Нема внесено актуелности во базата на податоци!";
return;
}
ViewState["dsNews"] = ds;
gvNews.DataSource = ds.Tables["News"];
gvNews.DataBind();
cleanControls();
}
示例3: getIOMembers
protected void getIOMembers()
{
DataBase db = new DataBase();
SqlConnection conn = db.Connection();
SqlCommand cmd = db.GetCommand(conn, "dbo.GetIOMembers");
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
try
{
conn.Open();
da.Fill(ds, "IOMembers");
}
catch (Exception err)
{
lblError.Text = err.Message;
}
finally
{
conn.Close();
conn.Dispose();
}
if (ds.Tables["IOMembers"].Rows.Count == 0)
{
lblError.Text = "Нема внесено податоци за членови на извршен одбор во базата!";
return;
}
string name = "";
string imageUrl = "";
try
{
for (int i = 0; i < ds.Tables["IOMembers"].Rows.Count; i++)
{
name = "<h2>" + ds.Tables["IOMembers"].Rows[i][1].ToString() + " "
+ ds.Tables["IOMembers"].Rows[i][2].ToString() +
" </h2>" + "Контакт Email: <a href=\"mailto:" + ds.Tables["IOMembers"].Rows[0][3].ToString() +
"\">" + ds.Tables["IOMembers"].Rows[0][3].ToString() + "</a><br/><br/>";
imageUrl = ds.Tables["IOMembers"].Rows[i][5].ToString();
MemberTemplate mb = (MemberTemplate)LoadControl("~/MemberTemplate.ascx");
Image img = (Image)mb.FindControl("MemberImage");
Label lbl = (Label)mb.FindControl("LabelInfo");
lbl.Text = name;
img.ImageUrl = imageUrl;
iomembersContent.Controls.Add(mb);
}
}
catch (Exception err)
{
lblError.Text = err.Message;
}
}
示例4: fillNewsData
protected void fillNewsData()
{
DataBase db = new DataBase();
SqlConnection conn = db.Connection();
SqlCommand cmd = db.GetCommand(conn, "dbo.FillNewsData");
cmd.Parameters.AddWithValue("@news_id", Convert.ToInt32(Request.QueryString["id"].ToString()));
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
try
{
conn.Open();
da.Fill(ds, "News");
}
catch (Exception err)
{
lblError.Text = err.Message;
}
finally
{
conn.Close();
conn.Dispose();
}
if (ds.Tables["News"].Rows.Count == 0)
{
news.Visible = false;
comments.Visible = false;
lblError.Text = "Нема податоци за веста!";
return;
}
ViewState["title"] = ds.Tables["News"].Rows[0]["title"].ToString();
imgTitleImage.ImageUrl = ds.Tables["News"].Rows[0]["title_image_url"].ToString();
lblNewsTitle.Text = ds.Tables["News"].Rows[0]["title"].ToString();
lblNewsDate.Text = ds.Tables["News"].Rows[0]["date"].ToString();
lblNewsContent.Text = ds.Tables["News"].Rows[0]["description"].ToString();
}
示例5: gvDeleteNews_RowDeleting
protected void gvDeleteNews_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
DataBase db = new DataBase();
SqlConnection conn = db.Connection();
SqlCommand cmd = db.GetCommand(conn, "dbo.DeleteNews");
int ID = Convert.ToInt32(gvDeleteNews.DataKeys[e.RowIndex].Values[0].ToString());
cmd.Parameters.AddWithValue("@news_id", ID);
int numChanges = 0;
try
{
conn.Open();
numChanges = cmd.ExecuteNonQuery();
}
catch (Exception err)
{
lblError.Text = err.Message;
}
finally
{
gvDeleteNews.EditIndex = -1;
conn.Close();
conn.Dispose();
}
if (numChanges != 0)
{
cleanControls();
fillDeleteNewsGrid();
}
string directory = Server.MapPath("~/Images/News/" + ID.ToString());
DeleteDirectoryIfExist(directory);
}
示例6: getNewsImages
protected void getNewsImages()
{
DataBase db = new DataBase();
SqlConnection conn = db.Connection();
SqlCommand cmd = db.GetCommand(conn, "dbo.GetNewsImages");
cmd.Parameters.AddWithValue("@news_id", Convert.ToInt32(Request.QueryString["id"].ToString()));
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
try
{
conn.Open();
da.Fill(ds, "Images");
}
catch (Exception err)
{
lblError.Text = err.Message;
}
finally
{
conn.Close();
conn.Dispose();
}
if (ds.Tables["Images"].Rows.Count == 0)
{
lblImages.Text = "";
return;
}
lblImages.Text = "Поставени слики за веста...";
ImageTemplate imgTmp = (ImageTemplate)LoadControl("~/ImageTemplate.ascx");
HtmlGenericControl newDiv = (HtmlGenericControl)imgTmp.FindControl("image");
string title = ViewState["title"].ToString();
if (ds.Tables["Images"].Rows.Count == 1)
{
string imageUrl = ds.Tables["Images"].Rows[0]["image_url"].ToString();
imageUrl = imageUrl.Remove(0, 2);
newDiv.InnerHtml += "<div class=\"single\"><a href=\"" + imageUrl + "\" rel=\"lightbox[roadtrip]\" title=\"" + title + "\" ><img style=\"width:200px; height:153px; \" src=\"" + imageUrl + "\" /></a></div>";
}
else
{
string imageUrl = ds.Tables["Images"].Rows[0]["image_url"].ToString();
imageUrl = imageUrl.Remove(0, 2);
newDiv.InnerHtml += "<div class=\"single first\"><a href=\"" + imageUrl + "\" rel=\"lightbox[roadtrip]\" title=\"" + title + "\" ><img style=\"width:200px; height:153px; \" src=\"" + imageUrl + "\" /></a></div>";
for (int i = 1; i < ds.Tables["Images"].Rows.Count - 1; i++)
{
imageUrl = ds.Tables["Images"].Rows[i]["image_url"].ToString();
imageUrl = imageUrl.Remove(0, 2);
newDiv.InnerHtml += "<div class=\"single\"><a href=\"" + imageUrl + "\" rel=\"lightbox[roadtrip]\" title=\"" + title + "\" ><img style=\"width:200px; height:153px; \" src=\"" + imageUrl + "\" /></a></div>";
}
imageUrl = ds.Tables["Images"].Rows[ds.Tables["Images"].Rows.Count - 1]["image_url"].ToString();
imageUrl = imageUrl.Remove(0, 2);
newDiv.InnerHtml += "<div class=\"single last\"><a href=\"" + imageUrl + "\" rel=\"lightbox[roadtrip]\" title=\"" + title + "\" ><img style=\"width:200px; height:153px; \" src=\"" + imageUrl + "\" /></a></div>";
}
newsImages.Controls.Add(imgTmp);
}
示例7: getNewsVideos
protected void getNewsVideos()
{
DataBase db = new DataBase();
SqlConnection conn = db.Connection();
SqlCommand cmd = db.GetCommand(conn, "dbo.GetNewsVideos");
cmd.Parameters.AddWithValue("@news_id", Convert.ToInt32(Request.QueryString["id"].ToString()));
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
try
{
conn.Open();
da.Fill(ds, "Videos");
}
catch (Exception err)
{
lblError.Text = err.Message;
}
finally
{
conn.Close();
conn.Dispose();
}
if (ds.Tables["Videos"].Rows.Count == 0)
{
lblVideo.Text = "";
return;
}
lblVideo.Text = "Поставени видеа за веста...";
string pattern = @"(?:youtube\.com\/(?:[^\/]+\/.+\/|(?:v|e(?:mbed)?)\/|.*[?&]v=)|youtu\.be\/)([^""&?\/ ]{11})$";
for (int i = 0; i < ds.Tables["Videos"].Rows.Count; i++)
{
string video_url = Regex.Match(ds.Tables["Videos"].Rows[i]["video_url"].ToString(), pattern).Groups[1].Value.ToString();
VideoTemplate2 vidTmp2 = (VideoTemplate2)LoadControl("~/VideoTemplate2.ascx");
HtmlControl player = (HtmlControl)vidTmp2.FindControl("player");
player.Attributes["src"] = "http://www.youtube.com/embed/" + video_url + "?enablejsapi=1";
newsVideo.Controls.Add(vidTmp2);
}
}
示例8: gvUpdate_RowUpdating
protected void gvUpdate_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
DataBase db = new DataBase();
SqlConnection conn = db.Connection();
SqlCommand cmd = db.GetCommand(conn, "dbo.UpdateMember");
int ID = Convert.ToInt32(gvUpdate.DataKeys[e.RowIndex].Values[0].ToString());
cmd.Parameters.AddWithValue("@member_id", ID);
TextBox tb = (TextBox)gvUpdate.Rows[e.RowIndex].FindControl("txtName");
cmd.Parameters.AddWithValue("@name", tb.Text);
tb = (TextBox)gvUpdate.Rows[e.RowIndex].FindControl("txtSurname");
cmd.Parameters.AddWithValue("@surname", tb.Text);
tb = (TextBox)gvUpdate.Rows[e.RowIndex].FindControl("txtEmail");
cmd.Parameters.AddWithValue("@email", tb.Text);
DropDownList cdmRole = (DropDownList)gvUpdate.Rows[e.RowIndex].FindControl("cmbRole");
cmd.Parameters.AddWithValue("@role", cdmRole.SelectedItem.Text);
FileUpload fuImage = (FileUpload)gvUpdate.Rows[e.RowIndex].FindControl("fupImage");
string imageUrl = "";
if (fuImage.HasFile)
{
imageUrl = Path.GetFileName(fuImage.PostedFile.FileName);
string fileExtension = Path.GetExtension(fuImage.PostedFile.FileName.ToString());
string pattern = @"^(.jpg|.JPG|.jpeg|.JPEG|.png|.PNG|.gif|.GIF)$";
Regex rgx = new Regex(pattern, RegexOptions.IgnoreCase);
MatchCollection matches = rgx.Matches(fileExtension);
if (matches.Count > 0)
{
try
{
string oldImage = Session["oldImageUrl"].ToString();
if (File.Exists(Server.MapPath("~/Images/Members/" + oldImage)))
File.Delete(Server.MapPath("~/Images/Members/" + oldImage));
fuImage.SaveAs(Server.MapPath("~/Images/Members/" + imageUrl));
cmd.Parameters.AddWithValue("@image_url", "~/Images/Members/" + imageUrl);
}
catch (Exception ex)
{
lblError.Text = "Настана грешка при зачувувањето на сликата.";
return;
}
}
else
{
lblError.Text = "Неправилен формат на слика. Дозволени се: .jpg .JPG .jpeg .JPEG .png .PNG .gif .GIF.";
return;
}
}
else
{
cmd.Parameters.AddWithValue("@image_url", DBNull.Value);
}
int numChanges = 0;
try
{
conn.Open();
numChanges = cmd.ExecuteNonQuery();
}
catch (Exception err)
{
lblError.Text = err.Message;
}
finally
{
gvUpdate.EditIndex = -1;
conn.Close();
conn.Dispose();
}
if (numChanges != 0)
{
cleanControls();
fillUpdateGrid();
}
}
示例9: gvUpdateVideo_RowUpdating
protected void gvUpdateVideo_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
string pattern = @"(?:youtube\.com\/(?:[^\/]+\/.+\/|(?:v|e(?:mbed)?)\/|.*[?&]v=)|youtu\.be\/)([^""&?\/ ]{11})$";
Regex rgx = new Regex(pattern, RegexOptions.IgnoreCase);
TextBox tb = (TextBox)gvUpdateVideo.Rows[e.RowIndex].Cells[2].Controls[0];
MatchCollection matches = rgx.Matches(tb.Text);
if (matches.Count > 0)
{
DataBase db = new DataBase();
SqlConnection conn = db.Connection();
SqlCommand cmd = db.GetCommand(conn, "dbo.UpdateVideo");
tb = (TextBox)gvUpdateVideo.Rows[e.RowIndex].Cells[1].Controls[0];
cmd.Parameters.AddWithValue("@title", tb.Text);
cmd.Parameters.AddWithValue("@date", DateTime.Now);
int ID = Convert.ToInt32(gvUpdateVideo.DataKeys[e.RowIndex].Values[0].ToString());
cmd.Parameters.AddWithValue("@video_id", ID);
tb = (TextBox)gvUpdateVideo.Rows[e.RowIndex].Cells[2].Controls[0];
cmd.Parameters.AddWithValue("@video_url", tb.Text);
int numChanges = 0;
try
{
conn.Open();
numChanges = cmd.ExecuteNonQuery();
}
catch (Exception err)
{
lblError.Text = err.Message;
}
finally
{
conn.Close();
conn.Dispose();
gvUpdateVideo.EditIndex = -1;
}
if (numChanges != 0)
{
cleanControls();
fillUpdateVideoGrid();
}
}
else
{
lblError.Text = "Невалиден линк за видео!";
return;
}
}
示例10: gvUpdate_RowDeleting
protected void gvUpdate_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
DataBase db = new DataBase();
SqlConnection conn = db.Connection();
SqlCommand cmd = db.GetCommand(conn, "dbo.DeleteMember");
int ID = Convert.ToInt32(gvUpdate.DataKeys[e.RowIndex].Values[0].ToString());
cmd.Parameters.AddWithValue("@member_id", ID);
int numChanges = 0;
try
{
conn.Open();
numChanges = cmd.ExecuteNonQuery();
}
catch (Exception err)
{
lblError.Text = err.Message;
}
finally
{
gvUpdate.EditIndex = -1;
conn.Close();
conn.Dispose();
}
if (numChanges != 0)
{
cleanControls();
fillUpdateGrid();
}
}
示例11: fillUpdateGrid
protected void fillUpdateGrid()
{
DataBase db = new DataBase();
SqlConnection conn = db.Connection();
SqlCommand cmd = db.GetCommand(conn, "dbo.FillUpdateGrid");
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
try
{
conn.Open();
da.Fill(ds, "Members");
}
catch (Exception err)
{
lblError.Text = err.Message;
}
finally
{
conn.Close();
conn.Dispose();
}
if (ds.Tables["Members"].Rows.Count == 0)
{
lblError.Text = "Нема внесено членови на раководство во базата!";
gvUpdate.DataSource = ds.Tables["Members"];
gvUpdate.DataBind();
return;
}
ViewState["ds"] = ds;
gvUpdate.DataSource = ds.Tables["Members"];
gvUpdate.DataBind();
}
示例12: gvAlbums_RowDataBound
protected void gvAlbums_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
try
{
DataRowView row = (DataRowView)e.Row.DataItem;
AlbumTemplate albTmp = (AlbumTemplate)e.Row.FindControl("albumTmp");
Label lblTitle = (Label)albTmp.FindControl("lblAlbumTitle");
HtmlGenericControl newDiv = (HtmlGenericControl)albTmp.FindControl("image");
lblTitle.Text = "<h3>" + row.Row["album_name"].ToString() + "</h3>Објавен: " + row.Row["date"].ToString();
string ID = row.Row["album_id"].ToString();
DataBase db = new DataBase();
SqlConnection conn = db.Connection();
SqlCommand cmd = db.GetCommand(conn, "dbo.GetImagesForAlbum");
cmd.Parameters.AddWithValue("@album_id", ID);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
try
{
conn.Open();
da.Fill(ds, "AlbumImages");
}
catch (Exception err)
{
lblError.Text = err.Message;
}
finally
{
conn.Close();
conn.Dispose();
}
string title = row.Row["album_name"].ToString();
if (ds.Tables["AlbumImages"].Rows.Count == 1)
{
string imageUrl = ds.Tables["AlbumImages"].Rows[0]["image_url"].ToString();
imageUrl = imageUrl.Remove(0, 2);
newDiv.InnerHtml += "<div class=\"single\"><a href=\"" + imageUrl + "\" rel=\"lightbox[roadtrip]\" title=\"" + title + "\" ><img style=\"width:100px; height:75px; \" src=\"" + imageUrl + "\" /></a></div>";
}
else
{
string imageUrl = ds.Tables["AlbumImages"].Rows[0]["image_url"].ToString();
imageUrl = imageUrl.Remove(0, 2);
newDiv.InnerHtml += "<div class=\"single first\"><a href=\"" + imageUrl + "\" rel=\"lightbox[roadtrip]\" title=\"" + title + "\" ><img style=\"width:100px; height:75px; \" src=\"" + imageUrl + "\" /></a></div>";
for (int i = 1; i < ds.Tables["AlbumImages"].Rows.Count - 1; i++)
{
imageUrl = ds.Tables["AlbumImages"].Rows[i]["image_url"].ToString();
imageUrl = imageUrl.Remove(0, 2);
newDiv.InnerHtml += "<div class=\"single\"><a href=\"" + imageUrl + "\" rel=\"lightbox[roadtrip]\" title=\"" + title + "\" ><img style=\"width:100px; height:75px; \" src=\"" + imageUrl + "\" /></a></div>";
}
imageUrl = ds.Tables["AlbumImages"].Rows[ds.Tables["AlbumImages"].Rows.Count - 1]["image_url"].ToString();
imageUrl = imageUrl.Remove(0, 2);
newDiv.InnerHtml += "<div class=\"single last\"><a href=\"" + imageUrl + "\" rel=\"lightbox[roadtrip]\" title=\"" + title + "\" ><img style=\"width:100px; height:75px; \" src=\"" + imageUrl + "\" /></a></div>";
}
}
catch (Exception err)
{
lblError.Text = err.Message;
}
}
}
示例13: btnAddAlbum_Click
protected void btnAddAlbum_Click(object sender, EventArgs e)
{
if (lbxAlbumImages.Items.Count == 0)
{
lblError.Text = "Изберете слики за албумот";
return;
}
DataBase db = new DataBase();
SqlConnection conn = db.Connection();
SqlCommand cmd = db.GetCommand(conn, "dbo.InsertAlbum");
cmd.Parameters.AddWithValue("@album_name", txtAlbumName.Text);
cmd.Parameters.AddWithValue("@date", DateTime.Now);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
try
{
conn.Open();
da.Fill(ds, "IDAlbum");
}
catch (Exception err)
{
lblError.Text = err.Message;
}
finally
{
conn.Close();
conn.Dispose();
}
if (ds.Tables["IDAlbum"].Rows.Count == 0)
{
lblError.Text = "Грешка при зачувувањето на албумот!";
return;
}
string albumDirectory = Server.MapPath("~/Images/Albums/" + ds.Tables["IDAlbum"].Rows[0]["ID"].ToString() + "/");
CreateDirectoryIfNotExist(albumDirectory);
if (lbxAlbumImages.Items.Count > 0)
{
for (int i = 0; i < lbxAlbumImages.Items.Count; i++)
{
conn = db.Connection();
cmd = db.GetCommand(conn, "dbo.InsertAlbumImage");
cmd.Parameters.AddWithValue("@album_id", ds.Tables["IDAlbum"].Rows[0]["ID"].ToString());
cmd.Parameters.AddWithValue("@image_url", "~/Images/Albums/" + ds.Tables["IDAlbum"].Rows[0]["ID"].ToString() + "/" + lbxAlbumImages.Items[i].ToString());
try
{
conn.Open();
cmd.ExecuteNonQuery();
}
catch (Exception err)
{
lblError.Text = err.Message;
}
finally
{
conn.Close();
conn.Dispose();
}
string sourceFile = Server.MapPath("~/Images/Temp/" + lbxAlbumImages.Items[i].ToString());
string destinationFile = Server.MapPath("~/Images/Albums/" + ds.Tables["IDAlbum"].Rows[0]["ID"].ToString() + "/" + lbxAlbumImages.Items[i].ToString());
File.Move(sourceFile, destinationFile);
}
}
string tempDirectory = Server.MapPath("~/Images/Temp/");
DeleteDirectoryIfExist(tempDirectory);
txtAlbumName.Text = "";
lblError.Text = "";
int imagesCount = lbxAlbumImages.Items.Count;
for (int i = 0; i < imagesCount; i++)
{
lbxAlbumImages.Items.RemoveAt(0);
}
fillDeleteAlbumGrid();
}
示例14: btnAddVideo_Click
protected void btnAddVideo_Click(object sender, EventArgs e)
{
string pattern = @"(?:youtube\.com\/(?:[^\/]+\/.+\/|(?:v|e(?:mbed)?)\/|.*[?&]v=)|youtu\.be\/)([^""&?\/ ]{11})$";
Regex rgx = new Regex(pattern, RegexOptions.IgnoreCase);
MatchCollection matches = rgx.Matches(txtVideoUrl.Text);
if (matches.Count > 0)
{
DataBase db = new DataBase();
SqlConnection conn = db.Connection();
SqlCommand cmd = db.GetCommand(conn, "dbo.InsertVideo");
cmd.Parameters.AddWithValue("@title", txtVideoTitle.Text);
cmd.Parameters.AddWithValue("@date", DateTime.Now);
cmd.Parameters.AddWithValue("@video_url", txtVideoUrl.Text);
int numChanges = 0;
try
{
conn.Open();
numChanges = cmd.ExecuteNonQuery();
}
catch (Exception err)
{
lblError.Text = err.Message;
}
finally
{
conn.Close();
conn.Dispose();
}
if (numChanges != 0)
{
cleanControls();
fillUpdateVideoGrid();
}
}
else
{
lblError.Text = "Невалиден линк за видео!";
}
}
示例15: btnAddNews_Click
protected void btnAddNews_Click(object sender, EventArgs e)
{
DataBase db = new DataBase();
SqlConnection conn = db.Connection();
SqlCommand cmd = db.GetCommand(conn, "dbo.InsertNews");
cmd.Parameters.AddWithValue("@title", txtNewsTitle.Text);
cmd.Parameters.AddWithValue("@description", txtNewsDescription.Text);
cmd.Parameters.AddWithValue("@date", DateTime.Now);
cmd.Parameters.AddWithValue("@title_image_url", "~/Images/logo.jpg");
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
try
{
conn.Open();
da.Fill(ds, "ID");
}
catch (Exception err)
{
lblError.Text = err.Message;
}
finally
{
conn.Close();
conn.Dispose();
}
if (ds.Tables["ID"].Rows.Count == 0)
{
lblError.Text = "Грешка при зачувувањето на сликите!";
return;
}
string newsDirectory = Server.MapPath("~/Images/News/" + ds.Tables["ID"].Rows[0]["ID"].ToString() + "/");
CreateDirectoryIfNotExist(newsDirectory);
if (lbxNewsImages.Items.Count > 0)
{
conn = db.Connection();
cmd = db.GetCommand(conn, "dbo.UpdateTitleImage");
cmd.Parameters.AddWithValue("@news_id", ds.Tables["ID"].Rows[0]["ID"].ToString());
cmd.Parameters.AddWithValue("@title_image_url", "~/Images/News/" + ds.Tables["ID"].Rows[0]["ID"].ToString() + "/" + lbxNewsImages.Items[0].ToString());
try
{
conn.Open();
cmd.ExecuteNonQuery();
}
catch (Exception err)
{
lblError.Text = err.Message;
}
finally
{
conn.Close();
conn.Dispose();
}
string sourceFile = Server.MapPath("~/Images/Temp/" + lbxNewsImages.Items[0].ToString());
string destinationFile = Server.MapPath("~/Images/News/" + ds.Tables["ID"].Rows[0]["ID"].ToString() + "/" + lbxNewsImages.Items[0].ToString());
File.Move(sourceFile, destinationFile);
if (lbxNewsImages.Items.Count > 1)
{
for (int i = 1; i < lbxNewsImages.Items.Count; i++)
{
conn = db.Connection();
cmd = db.GetCommand(conn, "dbo.InsertNewsImage");
cmd.Parameters.AddWithValue("@news_id", ds.Tables["ID"].Rows[0]["ID"].ToString());
cmd.Parameters.AddWithValue("@image_url", "~/Images/News/" + ds.Tables["ID"].Rows[0]["ID"].ToString() + "/" + lbxNewsImages.Items[i].ToString());
try
{
conn.Open();
cmd.ExecuteNonQuery();
}
catch (Exception err)
{
lblError.Text = err.Message;
}
finally
{
conn.Close();
conn.Dispose();
}
sourceFile = Server.MapPath("~/Images/Temp/" + lbxNewsImages.Items[i].ToString());
destinationFile = Server.MapPath("~/Images/News/" + ds.Tables["ID"].Rows[0]["ID"].ToString() + "/" + lbxNewsImages.Items[i].ToString());
File.Move(sourceFile, destinationFile);
}
}
}
if (lbxNewsVideos.Items.Count > 0)
//.........这里部分代码省略.........