download Default.aspx.cs
Language: C#
LOC: 251
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
using System;
using System.Data;
using System.Configuration;
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 System.Collections.Specialized;
using System.Data.SqlClient;
using System.Threading;
using System.Net.Mail;

public partial class _Default : System.Web.UI.Page
{
    string DBConnectionString = ConfigurationManager.ConnectionStrings["CCSConnectionString"].ConnectionString;
   // NameValueCollection useAppSetting = (NameValueCollection)Context.GetSection("appSettings");

    protected void Page_Load(object sender, EventArgs e)
    {

        if (!IsPostBack)
        {
            lblName.Text = "zn " + Context.User.Identity.Name + "A";
            lblAuthType.Text = "zOH " + Context.User.Identity.AuthenticationType + " 覡i{ҡC";
            //  Response.Write(HttpContext.Current.User.Identity.Name);
            Style bodyStyle = new Style();
            bodyStyle.ForeColor = System.Drawing.Color.Black;
            bodyStyle.BackColor = System.Drawing.Color.Wheat;  //]wIC


            //N˦[JثeHeader
            Page.Header.StyleSheet.CreateStyleRule(bodyStyle, null, "BODY");
            Page.Header.Title = "@Τ޲zt";

            lblNumOfStatistics.Text = "tβ{" + rtnNumberOfTotalComponent() + " ӤA" + rtnNumberOfContributor() + " ^m";
            lblTimeOfDoStatistics.Text = "έpɶG" + rtnTimeOfDoStatistics();
            lblIsAdmin.Text = (isAdministrator(Context.User.Identity.Name) ? "zO޲z" : "zO@ϥΪ");

            if (isAdministrator(Context.User.Identity.Name))
            {
                RadioButtonList.Items[2].Enabled = true;                
                //RadioButtonList.Items[3].Enabled = true;                
            }
            else
            {
                RadioButtonList.Items[2].Enabled = false;
                //RadioButtonList.Items[3].Enabled = false;                
            }
        }
    }

    #region ثe^m̼ƥ
    protected int rtnNumberOfContributor()
    {
        //ɻݱqƮwUSQLӭp⦹
        SqlConnection conn = null;
        SqlCommand cmd = null;      
        int totalNumberOfContributor = 0;        
        conn = new SqlConnection(DBConnectionString);
        cmd = new SqlCommand("SELECT COUNT(DISTINCT CONTRIBUTOR) FROM COMPONENT",conn);

        try
        {
            conn.Open();
            totalNumberOfContributor = (int)cmd.ExecuteScalar();

        }
        catch (Exception ex)
        {
            showMsg(ex.Message);
        }
        finally
        {            
            conn.Close();
        }

        return totalNumberOfContributor;
    }
    #endregion

    #region XLפUH
    private string[,] finOutTheTop10PersonWhoOverDownload(int iThresholdOfOverDownload)
    {
        string[,] strWhoOverDownloadWhat = new string[10,3];
        SqlConnection conn = null;
        SqlCommand cmd = null;
        SqlDataReader reader = null;
        try
        {
            ConnectionStringSettings connSettings = ConfigurationManager.ConnectionStrings["CCSConnectionString"];
            string CCSConnectionString = connSettings.ConnectionString;

            conn = new SqlConnection(CCSConnectionString);
            cmd = new SqlCommand("select Top " + iThresholdOfOverDownload.ToString() + " USER_ID, COMPONENT_ID, count(COMPONENT_ID) as CNT_OD from download_list   GROUP BY COMPONENT_ID, USER_ID", conn);

            conn.Open();
            reader = cmd.ExecuteReader();
            int ix = 0;
            while (reader.Read())
            {
                strWhoOverDownloadWhat[ix, 0] = reader["USER_ID"].ToString().Trim();
                strWhoOverDownloadWhat[ix, 1] = reader["COMPONENT_ID"].ToString().Trim();
                strWhoOverDownloadWhat[ix, 2] = reader["CNT_OD"].ToString().Trim();
                ix++;
            }
        }
        catch (Exception ex)
        {
            showMsg(ex.Message);
        }
        finally
        {
            reader.Close();
            conn.Close();
        }
        return strWhoOverDownloadWhat;
    }
    #endregion




    //`NSHb@Ӥ뤺jqU]UP󪺦ƦbeQWBƥ > 30ӡ^ApG,HeH󵹩Ҧ޲z
    #region Heemail󪺶}o̡AiwG
    private void SendMail2AdminAboutWhoOverDownload()
    {
        //Step 0. XjTQӤUeQWH

        const int iTHRESHOLD = 30;   //ne30
        string[,] s = finOutTheTop10PersonWhoOverDownload(iTHRESHOLD);


        //Step 1. dEmail
        string strEmailAddress = "";
        SqlConnection conn = null;
        SqlCommand cmd = null;
        SqlDataReader reader = null;
        try
        {
            ConnectionStringSettings connSettings = ConfigurationManager.ConnectionStrings["CCSConnectionString"];
            string CCSConnectionString = connSettings.ConnectionString;

            conn = new SqlConnection(CCSConnectionString);
            cmd = new SqlCommand("SELECT EMAIL FROM USER", conn);

            conn.Open();
            reader = cmd.ExecuteReader();
            while (reader.Read())
            {
                strEmailAddress = reader["EMAIL"].ToString().Trim();
            }
        }
        catch (Exception ex)
        {
            showMsg(ex.Message);
        }
        finally
        {
            reader.Close();
            conn.Close();
        }

        //Step 2.HoEmail 󪺶}o    
        sendEMail("", strEmailAddress);

    }

    #endregion


    #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ΪĵiHI";

        if (String.IsNullOrEmpty(strMailBody))
        {
            strMailBody = "oOѦ@Τ޲ztγqT</b>A<b><font color=\"red\">Ъ`NثeUƲ`</font><br>";

        }
        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







    #region ثeƥ
    protected int rtnNumberOfTotalComponent()
    {
        //ɻݱqƮwӭp⦹
        int totalNumberOfComponents = 0;
        SqlConnection conn = null;
        SqlCommand cmd = null;      
        conn = new SqlConnection(DBConnectionString);
        cmd = new SqlCommand("SELECT COUNT(*) FROM COMPONENT", conn);

        try
        {
            conn.Open();
            totalNumberOfComponents = (int)cmd.ExecuteScalar();

        }
        catch (Exception ex)
        {
            showMsg(ex.Message);
        }
        finally
        {
           conn.Close();
        }


        return totalNumberOfComponents;
    }
    #endregion
    
    #region έpɶ
    protected String rtnTimeOfDoStatistics()
    {
        String rtnTime = System.DateTime.Now.ToString();   //Ǧ^Ūɶ
        return rtnTime;
    }
    #endregion
    
   
   

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

    #region P_O_޲z
    public bool isAdministrator(string strUserName) {
        bool answerOfIsAdministrator = false;     
        //dTable USERIS_ADM ӧPOHO_޲z
        SqlConnection conn = null;
        SqlCommand cmd = null;    
      
        try
        {
            conn = new SqlConnection(DBConnectionString);
            cmd = new SqlCommand("SELECT IS_ADM FROM [USER] WHERE USER_ID = '" + strUserName + "'", conn);

            conn.Open();
            answerOfIsAdministrator = (bool)cmd.ExecuteScalar();          
          
        }
        catch (Exception ex)
        {
            showMsg(ex.Message);
        }
        finally {            
            conn.Close();        
        }
      
        return answerOfIsAdministrator;
    }

    #endregion

     #region ھڿܡAɦVUӥ\୶
    protected void RadioButtonList_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (RadioButtonList.Items[0].Selected == true)
        {
            Server.Transfer("~/AddNewComponent.aspx");  //sW
        }
        else if (RadioButtonList.Items[1].Selected == true)
        {
            Server.Transfer("~/SearchComponent.aspx?");   //jM
        }
        else if (RadioButtonList.Items[2].Selected == true)
        {
            Server.Transfer("~/ManagerMain.aspx");    //޲z̤
        }
        else if (RadioButtonList.Items[3].Selected == true)
        {
            Server.Transfer("~/StatisticsReport.aspx");   //έp    
        }        

    }
     #endregion
    protected void Timer1_Tick(object sender, EventArgs e)
    {       
            lblTimeNow.Text = "{bɶG" + System.DateTime.Now.ToString();       
    }
    
}



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