コード例 #1
0
        public void getNews()
        {
            niapsEntities1 db = new niapsEntities1();
            // news ne = new news();
            var           msg = db.news.OrderByDescending(n => n.date);
            StringBuilder sb  = new StringBuilder();
            int           i   = 1;

            foreach (var value in msg)
            {
                sb.Append(string.Format(@"<table width='400px'>
                    <tr>
                        <td>Title:</td><td>{0} </td>
                </tr>
                <tr>
                        <td></td><td>{1}<a href=""newsRoom.aspx"">read more...</a></td>
                </tr>
                    <tr>
                        <td>Author:</td><td>{2}&nbsp;&nbsp;&nbsp;Date:&nbsp; {3}</td>
                </tr>
                    <tr>
                        <td></td><td></td>
                </tr>
	                </table>"    , value.postebBy, niaps_ver_1._0.truncString.TruncateAtWord(value.message, 70), value.newsBy, value.date.ToShortDateString()));
                if (i.Equals(5))
                {
                    break;
                }
                i++;
            }
            newsLabel.Text = sb.ToString();
            db.Dispose();
        }
コード例 #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            niapsEntities1 db = new niapsEntities1();
            // news ne = new news();
            var           msg = db.news.OrderByDescending(n => n.date);
            StringBuilder sb  = new StringBuilder();

            foreach (var value in msg)
            {
                sb.Append(string.Format(@"<table  id=""box-table-a"">
                    <tr>
                        <td>Title:</td><td>{0} </td>
                </tr>
                <tr>
                        <td></td><td>{1}</td>
                </tr>
                    <tr>
                        <td>Author:</td><td>{2}&nbsp;&nbsp;&nbsp;Date:&nbsp; {3}</td>
                </tr>
	                </table>"    , value.postebBy, value.message, value.newsBy, value.date.ToShortDateString()));
            }
            newsLabel.Text = sb.ToString();
            db.Dispose();
        }
コード例 #3
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            if (FileUpload1.HasFile)
            {
                string path = string.Concat((Server.MapPath("~/temp/" + FileUpload1.FileName)));
                FileUpload1.PostedFile.SaveAs(path);
                OleDbConnection  OleDbcon = new OleDbConnection("Provider=Microsoft.Ace.OLEDB.12.0;Data Source=" + path + ";Extended Properties=Excel 12.0;");
                OleDbCommand     cmd      = new OleDbCommand("select * from [Sheet1$]", OleDbcon);
                OleDbDataAdapter odr      = new OleDbDataAdapter(cmd);

                OleDbcon.Open();
                DataSet ds = new DataSet();
                odr.Fill(ds);
                odr.Dispose();
                OleDbcon.Close();
                OleDbcon.Dispose();

                using (niapsEntities1 db = new niapsEntities1())
                {
                    foreach (DataRow dr in ds.Tables[0].Rows)
                    {
                        try
                        {
                            assetRecord ct = new assetRecord();
                            ct.assetId = dr["ASSET_ID"].ToString();
                            ct.name    = dr["ASSET_NAME"].ToString();
                            CultureInfo provider = new CultureInfo("en-US");
                            Thread.CurrentThread.CurrentCulture = provider;
                            ct.datePurchased = DateTime.Parse(dr["DATE_PURCHASED"].ToString());
                            ct.receivingDept = dr["RECEIVING_DEPT"].ToString();
                            ct.cost          = decimal.Parse(dr["COST"].ToString());
                            ct.remark        = dr["REMARK"].ToString();
                            ct.insurance     = dr["INSURER"].ToString();
                            ct.policyNumber  = dr["INSURANCE_POLICY_No"].ToString();
                            ct.sumInsured    = decimal.Parse(dr["SUM_INSURED"].ToString());
                            CultureInfo provider1 = new CultureInfo("en-US");
                            Thread.CurrentThread.CurrentCulture = provider1;
                            ct.coverDate = DateTime.Parse(dr["COVER_DATE"].ToString());
                            CultureInfo provider2 = new CultureInfo("en-US");
                            Thread.CurrentThread.CurrentCulture = provider2;
                            ct.expirydate = DateTime.Parse(dr["EXPIRY_DATE"].ToString());
                            ct.status     = dr["STATUS"].ToString();
                            ct.vendor     = dr["VENDOR"].ToString();
                            ct.premium    = dr["PREMIUM"].ToString();
                            db.assetRecords.Add(ct);
                            db.SaveChanges();
                            Label1.ForeColor = Color.Green;
                            Label1.Text      = "Successfully inserted";
                        }
                        catch (Exception ex)
                        {
                            Label1.ForeColor = Color.Red;
                            Label1.Text      = ex.Message;
                        }
                    }
                }
            }
            else
            {
                Label1.ForeColor = Color.Red;
                Label1.Text      = "Please select the file";
            }
        }
コード例 #4
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            if (FileUpload1.HasFile)
            {
                string path = string.Concat((Server.MapPath("~/temp/" + FileUpload1.FileName)));
                FileUpload1.PostedFile.SaveAs(path);
                OleDbConnection  OleDbcon = new OleDbConnection("Provider=Microsoft.Ace.OLEDB.12.0;Data Source=" + path + ";Extended Properties=Excel 12.0;");
                OleDbCommand     cmd      = new OleDbCommand("select * from [Sheet1$]", OleDbcon);
                OleDbDataAdapter odr      = new OleDbDataAdapter(cmd);

                OleDbcon.Open();
                DataSet ds = new DataSet();
                odr.Fill(ds);
                odr.Dispose();
                OleDbcon.Close();
                OleDbcon.Dispose();

                using (niapsEntities1 db = new niapsEntities1())
                {
                    employmentRecord   er  = new employmentRecord();
                    currentStaffRecord cst = new currentStaffRecord();
                    foreach (DataRow dr in ds.Tables[0].Rows)
                    {
                        try
                        {
                            er.staffId = dr["Staff_id_No"].ToString();
                            er.company = dr["Company"].ToString();

                            string      dateString = dr["DateJoined"].ToString();
                            CultureInfo provider   = new CultureInfo("en-US");
                            Thread.CurrentThread.CurrentCulture = provider;
                            DateTime sd = DateTime.Parse(dateString);
                            er.startDate = sd;

                            string   dateString1 = dr["Date_Left"].ToString();
                            DateTime ed          = DateTime.Parse(dateString1);
                            er.endDate  = ed;
                            er.postHeld = dr["Post_held"].ToString();
                            er.duties   = dr["Duties"].ToString();
                            db.employmentRecords.Add(er);
                            db.SaveChanges();

                            cst.staffId       = dr["Staff_id_No"].ToString();
                            cst.designation   = dr["Designation"].ToString();
                            cst.department    = dr["Department"].ToString();
                            cst.qualification = Request.QueryString["bq"].ToString();
                            CultureInfo provider2 = new CultureInfo("en-US");
                            Thread.CurrentThread.CurrentCulture = provider2;
                            cst.date_Joined     = DateTime.Parse(dr["Dete_of_employment"].ToString());
                            cst.degree          = Request.QueryString["degree"].ToString();
                            cst.probationPeriod = Int32.Parse(dr["Probation_Period"].ToString());
                            string conDate = dr["ConfirmationDate"].ToString();
                            cst.dateOfConfirmation = DateTime.Parse(conDate);
                            db.currentStaffRecords.Add(cst);
                            db.SaveChanges();

                            Label1.ForeColor = Color.Green;
                            Label1.Text      = "Successfully inserted";
                        }
                        catch (Exception ex)
                        {
                            Label1.ForeColor = Color.Red;
                            Label1.Text      = ex.Message;
                        }
                    }
                }
            }
            else
            {
                Label1.ForeColor = Color.Red;
                Label1.Text      = "Please select the file";
            }
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            if (FileUpload1.HasFile)
            {
                string path = string.Concat((Server.MapPath("~/temp/" + FileUpload1.FileName)));
                FileUpload1.PostedFile.SaveAs(path);
                OleDbConnection  OleDbcon = new OleDbConnection("Provider=Microsoft.Ace.OLEDB.12.0;Data Source=" + path + ";Extended Properties=Excel 12.0;");
                OleDbCommand     cmd      = new OleDbCommand("select * from [Sheet1$]", OleDbcon);
                OleDbDataAdapter odr      = new OleDbDataAdapter(cmd);

                OleDbcon.Open();
                DataSet ds = new DataSet();
                odr.Fill(ds);
                odr.Dispose();
                OleDbcon.Close();
                OleDbcon.Dispose();

                using (niapsEntities1 db = new niapsEntities1())
                {
                    foreach (DataRow dr in ds.Tables[0].Rows)
                    {
                        try
                        {
                            staffRecord sr = new staffRecord();
                            sr.staffId = dr["staffIdNo"].ToString();
                            sr.fName   = dr["FirstName"].ToString();
                            sr.lName   = dr["LastName"].ToString();
                            sr.gender  = dr["Gender"].ToString();
                            string   dateString = dr["date_of_birth"].ToString();
                            DateTime result;
                            result         = DateTime.Parse(dateString);
                            sr.dateOfBirth = result;
                            string staffAge = ((DateTime.Now.Year) - (result.Year)).ToString();
                            sr.email                = dr["email"].ToString();
                            sr.mobile               = dr["mobile"].ToString();
                            sr.address              = dr["address"].ToString();
                            sr.state                = dr["state_of_origin"].ToString();
                            sr.Lga                  = dr["lga"].ToString();
                            sr.middleName           = dr["MiddleName"].ToString();
                            sr.marritalStatus       = dr["mStatus"].ToString();
                            sr.formOfIdentification = dr["form_of_identity"].ToString();
                            sr.passport             = dr["passportLink"].ToString();
                            sr.age                  = Int32.Parse(staffAge);
                            sr.idNumber             = dr["id_number"].ToString();
                            sr.status               = "active";
                            db.staffRecords.Add(sr);
                            db.SaveChanges();

                            //populate user table with staff login parameters
                            staffNextOfKin st = new staffNextOfKin();
                            st.staffId       = dr["staffIdNo"].ToString();
                            st.fName         = dr["nFirstName"].ToString();
                            st.lname         = dr["last_name"].ToString();
                            st.gender        = dr["gender"].ToString();
                            st.address       = dr["address"].ToString();
                            st.contactMobile = dr["phone"].ToString();
                            st.relationship  = dr["relationship"].ToString();
                            db.staffNextOfKins.Add(st);
                            db.SaveChanges();

                            user use = new user();
                            use.email    = dr["email"].ToString();
                            use.staffId  = dr["staffIdNo"].ToString();
                            use.role     = "staff";
                            use.username = dr["userName"].ToString();
                            string temPsw = randomPsw();
                            use.password = CreateHash(temPsw);
                            use.status   = "active";
                            db.users.Add(use);
                            db.SaveChanges();


                            System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
                            mail.To.Add(dr["email"].ToString());
                            mail.From            = new MailAddress("*****@*****.**", "NIA Personnel System", System.Text.Encoding.UTF8);
                            mail.Subject         = "Your NIAPS Logon Detail";
                            mail.SubjectEncoding = System.Text.Encoding.UTF8;
                            mail.Body            = "Your account details on NIA Personnel System (NIAPS) are: <b />user name =" + dr["userName"].ToString() + " <b />password ="******"*****@*****.**", "niaps123");
                            client.Port        = 587;
                            client.Host        = "smtp.gmail.com";
                            client.EnableSsl   = true;
                            client.Send(mail);
                        }
                        catch (Exception ex)
                        {
                            //continue;
                            //Label1.ForeColor = Color.Red;
                            Label1.Text = ex.Message;
                        }
                    }
                }
                Label1.ForeColor = Color.Green;
                Label1.Text      = "Successfully inserted";
            }
            else
            {
                Label1.ForeColor = Color.Red;
                Label1.Text      = "Please select the file";
            }
        }