download Comment.aspx.cs
Language: C#
LOC: 271
Project Info
common-component-mng-sys - Common Componen...e ...(common-component-mng-sys)
Server: Google
Type: svn
...on‑component‑mng‑sys\trunk\
   AddNewComponent.aspx
   AddNewComponent.aspx.cs
   ADLogin.aspx
   ADLogin.aspx.cs
   ...SearchActionChoice.aspx
   ...rchActionChoice.aspx.cs
   CathayBkRSS.xml
   Comment.aspx
   Comment.aspx.cs
   ...n-component-mng-sys.sln
   ...onent-mng-sys_Model.tgs
   ComponentsList.html
   Default.aspx
   Default.aspx.cs
   Downloading.aspx
   Downloading.aspx.cs
   ErrorPage.htm
   Global.asax
   Logon.aspx
   Logon.aspx.cs
   ManagerMain.aspx
   ManagerMain.aspx.cs
   MasterPage.master
   MasterPage.master.cs
   ReviseComponent.aspx
   ReviseComponent.aspx.cs
   SearchComponent.aspx
   SearchComponent.aspx.cs
   SearchResult.aspx
   SearchResult.aspx.cs
   StatisticsReport.aspx
   StatisticsReport.aspx.cs
   ...oDownloadComponent.aspx
   ...wnloadComponent.aspx.cs
   web.config
   Web.sitemap
   ...ejectReasonAndMail.aspx
   ...ctReasonAndMail.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
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;
using AjaxControlToolkit;
using System.Text;
using System.Data.SqlClient;
using System.Threading;
using System.Net.Mail;

public partial class Comment : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        // ihXǤJѼƬOComponent Name
        //bnXתWٵ lblComponentName
        string componentID = Request.QueryString["componentID"];   //γoӴե\઺i      

        lblComponentName.Text = queryComponentNameByID(componentID);  //test data      
        lblComponentVersion.Text = queryComponentVersionByID(componentID);
        lblComponentID.Text = componentID;
        lblComponentID.Visible = true;
        string strContributorEmail = queryContributorEmailByID(lblComponentID.Text.Trim());
        lblEmailTo.Text = strContributorEmail;

        if (!isThisPersionHadDownloadTheComponent(componentID, Context.User.Identity.Name))
        {
            
           // showMsg("zQ\צ");
           // Thread.Sleep(3000);
            Server.Transfer("~/Default.aspx");
        }
    }

    protected void btnComment_Click(object sender, EventArgs e)
    {
        insertCommentList();  //sWצC
        updateTotalScoreOfComponent(lblComponentID.Text.Trim());    //򱵵~s줸`
        //He׵}o
      
        sendEMail("", lblEmailTo.Text.Trim());
        Server.Transfer("~/Default.aspx");
    }


    private string queryComponentVersionByID(string strComponentID)
    {
        string strComponentVersion = String.Empty;
        ConnectionStringSettings connSettings = ConfigurationManager.ConnectionStrings["CCSConnectionString"];
        string CCSConnectionString = connSettings.ConnectionString;


        SqlConnection conn = new SqlConnection(CCSConnectionString);
        SqlCommand cmd = new SqlCommand("SELECT VERSION FROM COMPONENT WHERE COMPONENT_ID ='" + strComponentID + "' ORDER BY VERSION DESC",
                                   conn);


        conn.Open();
        SqlDataReader  reader = cmd.ExecuteReader();
        while (reader.Read())
        {
            strComponentVersion = reader["VERSION"].ToString().Trim();
                                
        }
        reader.Close();
        conn.Close();
        return strComponentVersion;
    }

   #region Hcomponent_IDdߤW
    private string queryComponentNameByID(string strComponentID) 
    {
        string strComponentName = String.Empty;
        ConnectionStringSettings connSettings = ConfigurationManager.ConnectionStrings["CCSConnectionString"];
        string CCSConnectionString = connSettings.ConnectionString;


        SqlConnection conn = new SqlConnection(CCSConnectionString);
        SqlCommand cmd = new SqlCommand("SELECT NAME FROM COMPONENT WHERE COMPONENT_ID ='" + strComponentID + "' ORDER BY NAME DESC",
                                   conn);


        conn.Open();
        SqlDataReader reader = cmd.ExecuteReader();
        while (reader.Read())
        {
            strComponentName = reader["NAME"].ToString().Trim();

        }
        reader.Close();
        conn.Close();

        return strComponentName;
    }
   #endregion

    #region Hcomponent_IDdߤ}o̪Email
    private string queryContributorEmailByID(string strComponentID)
    {
        string strContributorEmail = String.Empty;
        ConnectionStringSettings connSettings = ConfigurationManager.ConnectionStrings["CCSConnectionString"];
        string CCSConnectionString = connSettings.ConnectionString;


        SqlConnection conn = new SqlConnection(CCSConnectionString);
        SqlCommand cmd = new SqlCommand("SELECT EMAIL FROM COMPONENT WHERE COMPONENT_ID ='" + strComponentID+"' ",
                                   conn);


        conn.Open();
        SqlDataReader reader = cmd.ExecuteReader();
        while (reader.Read())
        {
            strContributorEmail = reader["EMAIL"].ToString().Trim();

        }
        reader.Close();
        conn.Close();

        return strContributorEmail;
    }
    #endregion




    #region sWצC
    private void insertCommentList()
    {

      StringBuilder strCommentTime = new StringBuilder("");
        strCommentTime.AppendFormat("{0:yyyy/MM/dd-hh:mm:ss}", System.DateTime.Now);      

        //nOO֩ɡA@FסAMFAoӤHeNULoӤAϥΫo
        string strInsertCommand = "INSERT INTO COMMENT_LIST (COMPONENT_ID, VERSION, COMMENT, USER_ID, SHOW_USER_OR_NOT, MYDATETIME)"
                                + " VALUES('" + lblComponentID.Text + "','" + lblComponentVersion.Text + "' ,'" + tbxComment.Text + "' ,'"
                                + Context.User.Identity.Name + "','" + (cbxShowUserOrNot.Checked ? "1":"0") + "','" + strCommentTime + "')";                           
        
        showMsg(strInsertCommand);
        ConnectionStringSettings connSettings = ConfigurationManager.ConnectionStrings["CCSConnectionString"];
        string CCSConnectionString = connSettings.ConnectionString;
        SqlConnection Conn = new SqlConnection(CCSConnectionString);

        try
        {
            Conn.Open();
        }
        catch (SqlException ex)
        {
            // Connection failed
            showMsg(ex.Message);
        }

        try
        {
            SqlCommand command = new SqlCommand(strInsertCommand, Conn);
            command.CommandType = System.Data.CommandType.Text;
            command.ExecuteNonQuery();
        }
        catch (SqlException ex)
        {
            showMsg(ex.Message);
        }
        finally
        {
            Conn.Close();    //remember to close the db connection
        }

    }
    #endregion
     
    #region s`
    private void updateTotalScoreOfComponent(string strComponentID) 
    {

        int iTotalScoreTillNow = queryTotalScoreOfComponent(strComponentID);

        int iNewTotalScore = iTotalScoreTillNow + Convert.ToInt32(ddlComponentScore.SelectedValue);

        string strUpdateCommand = "UPDATE COMPONENT SET TOTAL_SCORE = '" + iNewTotalScore.ToString() +"'"
                                + " WHERE COMPONENT_ID = '" + strComponentID + "'";

        showMsg(strUpdateCommand);

        ConnectionStringSettings connSettings = ConfigurationManager.ConnectionStrings["CCSConnectionString"];
        string CCSConnectionString = connSettings.ConnectionString;
       
        SqlConnection Conn = new SqlConnection(CCSConnectionString);

        try
        {
            Conn.Open();
        }
        catch (SqlException ex)
        {
            // Connection failed
            showMsg(ex.Message);
        }

        try
        {
            SqlCommand command = new SqlCommand(strUpdateCommand, Conn);
            command.CommandType = System.Data.CommandType.Text;
            command.ExecuteNonQuery();
        }
        catch (SqlException ex)
        {
            showMsg(ex.Message);
        }
        finally
        {
            Conn.Close();    //remember to close the db connection
        }
    
    }

    #endregion

    #region dߥثe`
    private int queryTotalScoreOfComponent(string strComponentID)
    {
        //dߥثe`AM[`As`
        ConnectionStringSettings connSettings = ConfigurationManager.ConnectionStrings["CCSConnectionString"];
        string CCSConnectionString = connSettings.ConnectionString;
        
        int iTotalScoreNow = 0; //lȵs
        string SelectCommand = "SELECT TOTAL_SCORE FROM COMPONENT WHERE COMPONENT_ID = '"+ strComponentID+"'";       
        SqlConnection Conn = new SqlConnection(CCSConnectionString);     

        try
        {
            Conn.Open();
        }
        catch (SqlException ex)
        {
            // Connection failed
            showMsg(ex.Message);
        }

        try
        {
            SqlCommand command = new SqlCommand(SelectCommand, Conn);
            command.CommandType = System.Data.CommandType.Text;
            iTotalScoreNow = Convert.ToInt32(command.ExecuteScalar());
        }
        catch (SqlException ex)
        {
            showMsg(ex.Message);
        }
        finally
        {
            Conn.Close();    //remember to close the db connection         
        }
        return iTotalScoreNow;
    }
    #endregion

    protected void showMsg(string AlertMessage)
    {
        Literal txtMsg = new Literal();
        txtMsg.Text = "<script>alert('" + AlertMessage + "')</script>" + "<br/>";
        Page.Controls.Add(txtMsg);
    }

    #region

    private bool isThisPersionHadDownloadTheComponent(string strComponentID, string strUserID)
    {
        bool hasBeenDownloaded = false;
        
        ConnectionStringSettings connSettings = ConfigurationManager.ConnectionStrings["CCSConnectionString"];
        string CCSConnectionString = connSettings.ConnectionString;
        SqlDataReader reader = null;
        int iQualifyCounter = 0; //lȵs
        
        SqlConnection conn = new SqlConnection(CCSConnectionString);
        SqlCommand cmd = new SqlCommand("SELECT * FROM DOWNLOAD_LIST WHERE COMPONENT_ID = '"+ strComponentID+"' AND USER_ID ='"+strUserID +"'" ,
                                  conn);

        try{
            conn.Open();
             reader = cmd.ExecuteReader();
            while (reader.Read())
            {
                iQualifyCounter++;

            }
        }catch(SqlException ex){
            showMsg(ex.Message);
        }finally{
             reader.Close();
            conn.Close();
        }        
   
    if (iQualifyCounter > 0) 
    {
        hasBeenDownloaded =true;
    }

        return hasBeenDownloaded;
    }

    #endregion

    protected void cbxShowUserOrNot_CheckedChanged(object sender, EventArgs e)
    {

    }

    #region HeEmailiT
    private void sendEMail(string strMailBody, string strMailToAddress)
    {

        //PɱHe޲z̻PϥΪ  
        String strTo = "<jiing.deng@cathaybk.com.tw>;" + strMailToAddress;
        //ӷO@Τ޲ztΩM޲z
        String strFrom = "<CCOM@cathaybk.com.tw>";
        String strMailSubject = "[@Τ]@Τ޲ztΪAqHI";

        if (String.IsNullOrEmpty(strMailBody))
        {
            strMailBody = "oOѦ@Τ޲ztγqT</b>A<b> "+ Context.User.Identity.Name +" /khzҰ^m@FצpUG<br>" + tbxComment.Text;

        }
        System.Net.Mail.SmtpClient client = new SmtpClient();
        client.Host = "PIEX2K05.cathaybk.intra.uwccb";
        client.Port = 25;
        client.UseDefaultCredentials = false;
        client.Credentials = new System.Net.NetworkCredential("uid", "pwd");  //uid, pwd please replace as yours
        client.DeliveryMethod = SmtpDeliveryMethod.Network;

        System.Net.Mail.MailMessage message = new MailMessage(strFrom, strTo, strMailSubject, strMailBody);
        message.BodyEncoding = System.Text.Encoding.UTF8;
        message.IsBodyHtml = true;

        try
        {
            client.Send(message);
            Response.Write("<font color=\"blue\">Email successfully sent.</font>");
        }
        catch (Exception ex)
        {
            Response.Write("Send Email Failed." + ex.ToString()); ;
        }
    }
    #endregion
}

About Koders | Resources | Downloads | Support | Black Duck | Submit Project | Terms of Service | DMCA | Privacy Policy | Site Map| Contact Us