-
Notifications
You must be signed in to change notification settings - Fork 0
/
AddNews.aspx.cs
115 lines (93 loc) · 3.74 KB
/
AddNews.aspx.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class AddNews : System.Web.UI.Page
{
//protected void dropFill()
//{
// FirstClass db = new FirstClass();
// DataTable dt = new DataTable();
// dt = db.dbOut("SELECT TOP 100 PERCENT NewsGroupID, NewgGroupDescription FROM NewsGroups ORDER BY NewgGroupDescription");
// DropDownList1.DataSource = dt;
// DropDownList1.DataTextField = "NewgGroupDescription";
// DropDownList1.DataValueField = "NewsGroupID";
// DropDownList1.DataBind();
//}
private string GetNameForFile()
{
FirstClass db = new FirstClass();
string DateNow = db.dtShamsi();
DateNow = DateNow.Replace("/", "");
DateNow += DateTime.Now.Hour.ToString().Trim() + DateTime.Now.Minute.ToString().Trim() + DateTime.Now.Second.ToString().Trim();
return DateNow.Trim();
}
protected void Page_Load(object sender, EventArgs e)
{
if (Session["UserName"] == null)
{
Response.Redirect("Default.aspx?ID=" + DateTime.Now.Ticks.ToString());
}
if (!IsPostBack)
{
FirstClass db = new FirstClass();
DataTable dt = new DataTable();
dt = db.dbOut("SELECT TOP 100 PERCENT NewsGroupID, NewgGroupDescription FROM NewsGroups ORDER BY NewgGroupDescription");
DropDownList1.DataSource = dt;
DropDownList1.DataTextField = "NewgGroupDescription";
DropDownList1.DataValueField = "NewsGroupID";
DropDownList1.DataBind();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
string ImgExtention = "";
string FileNme = "";
if (FileUpload1.HasFile)
{
ImgExtention = System.IO.Path.GetExtension(FileUpload1.FileName);
}
if (ImgExtention != "")
{
FileNme = GetNameForFile();
}
if (FileUpload1.HasFile)
{
string savePath = Server.MapPath("UploadedUserFiles") + "\\" + FileNme + ImgExtention;
FileUpload1.SaveAs(savePath);
}
FirstClass db = new FirstClass();
db.cmd.Parameters.Add("@NewsTitle", SqlDbType.NVarChar).Value = TextBox1.Text.Trim();
db.cmd.Parameters.Add("@NewsGroupID", SqlDbType.Int).Value = DropDownList1.SelectedValue;
db.cmd.Parameters.Add("@NewsPic", SqlDbType.NVarChar).Value = ("UploadedUserFiles") + "\\" + FileNme + ImgExtention;
db.cmd.Parameters.Add("@newsBody", SqlDbType.NText).Value = TextBox2.Text.Trim();
db.cmd.Parameters.Add("@DateOfAdding", SqlDbType.NVarChar).Value = db.dtShamsi();
db.cmd.Parameters.Add("@UserName", SqlDbType.NVarChar).Value = Session["UserName"].ToString();
db.cmd.Parameters.Add("@ArchivedBit", SqlDbType.Bit).Value = 0;
if (int.Parse(Session["UserTypeID"].ToString()) == 3)
{
db.cmd.Parameters.Add("@ShowPermiss", SqlDbType.Bit).Value = 0;
}
else
{
db.cmd.Parameters.Add("@ShowPermiss", SqlDbType.Bit).Value = 1;
}
db.exeCommand("sp_tblNews_Insert");
txtClear();
}
protected void txtClear()
{
TextBox1.Text = "";
TextBox2.Text = "";
}
protected void Button2_Click(object sender, EventArgs e)
{
txtClear();
}
}