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) ? "zOz" : "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ɱHez̻PϥΪ
String strTo = "<jiing.deng@cathaybk.com.tw>;" + strMailToAddress;
//ӷO@ΤztΩMz
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();
}
}