Example #1
0
        public static MessageResult createEvalResult(EvalResults evalResults)
        {
            MessageResult messageResult = new MessageResult();

            try
            {
                SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
                builder.DataSource     = DBControl.DataSource;
                builder.UserID         = DBControl.UserID;
                builder.Password       = DBControl.Password;
                builder.InitialCatalog = DBControl.InitialCatalog;

                using (SqlConnection connection = new SqlConnection(builder.ConnectionString))
                {
                    connection.Open();

                    SqlCommand     command;
                    SqlDataAdapter adapter = new SqlDataAdapter();
                    String         sql     = "";

                    sql = String.Format("INSERT INTO EvalResult_01 (Username, EvalDate, ANS_1B, ANS_1B_OTHER, ANS_04U1, ANS_04U2, ANS_04U3, ANS_04U4, ANS_11, ANS_12) VALUES(N'{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}', '{8}', '{9}'); ",
                                        evalResults.username, evalResults.evalDate.ToString("MM/dd/yyyy hh:mm:ss"), evalResults.ans_1b, evalResults.ans_1b_oth, evalResults.ans_04u1, evalResults.ans_04u2, evalResults.ans_04u3, evalResults.ans_04u4, evalResults.ans_11, evalResults.ans_12);

                    command = new SqlCommand(sql, connection);

                    adapter.UpdateCommand = new SqlCommand(sql, connection);
                    adapter.UpdateCommand.ExecuteNonQuery();

                    command.Dispose();
                    connection.Close();
                    messageResult.ErrorCode = ErrorCode.S;
                    messageResult.Message   = "บันทึกข้อมูลสำเร็จ";
                }
            }
            catch (SqlException e2)
            {
                messageResult.ErrorCode = ErrorCode.E;
                messageResult.Message   = "เกิดข้อผิดพลาด! กรุณาติดต่อผู้ดูแลระบบ";
            }

            return(messageResult);
        }
Example #2
0
        public static EvalResults getEval(string userSearch)
        {
            EvalResults evalResults = new EvalResults();

            if (userSearch == "")
            {
                return(evalResults);
            }

            try
            {
                SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
                builder.DataSource     = DBControl.DataSource;
                builder.UserID         = DBControl.UserID;
                builder.Password       = DBControl.Password;
                builder.InitialCatalog = DBControl.InitialCatalog;

                using (SqlConnection connection = new SqlConnection(builder.ConnectionString))
                {
                    connection.Open();
                    StringBuilder sb = new StringBuilder();
                    sb.Append(String.Format("SELECT TOP 1 * FROM dbo.EvalResult_01 WHERE Username = '******' ORDER BY EvalDate DESC;", userSearch));

                    String sql = sb.ToString();

                    using (SqlCommand command = new SqlCommand(sql, connection))
                    {
                        using (SqlDataReader reader = command.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                string ans_04u1, ans_04u2, ans_04u3, ans_04u4;
                                ans_04u1             = reader["ANS_04U1"].ToString();
                                ans_04u2             = reader["ANS_04U2"].ToString();
                                ans_04u3             = reader["ANS_04U3"].ToString();
                                ans_04u4             = reader["ANS_04U4"].ToString();
                                evalResults.username = reader["Username"].ToString();
                                evalResults.evalDate = Convert.ToDateTime(reader["EvalDate"].ToString());

                                evalResults.ans_04u1_01 = ans_04u1[0].ToString();
                                evalResults.ans_04u1_02 = ans_04u1[1].ToString();
                                evalResults.ans_04u1_03 = ans_04u1[2].ToString();
                                evalResults.ans_04u1_04 = ans_04u1[3].ToString();
                                evalResults.ans_04u1_05 = ans_04u1[4].ToString();
                                evalResults.ans_04u1_06 = ans_04u1[5].ToString();
                                evalResults.ans_04u1_07 = ans_04u1[6].ToString();
                                evalResults.ans_04u1_08 = ans_04u1[7].ToString();
                                evalResults.ans_04u1_09 = ans_04u1[8].ToString();
                                evalResults.ans_04u1_10 = ans_04u1[9].ToString();
                                evalResults.ans_04u1_11 = ans_04u1[10].ToString();
                                evalResults.ans_04u1_12 = ans_04u1[11].ToString();
                                evalResults.ans_04u1_13 = ans_04u1[12].ToString();
                                evalResults.ans_04u1_14 = ans_04u1[13].ToString();
                                evalResults.ans_04u1_15 = ans_04u1[14].ToString();
                                evalResults.ans_04u1_16 = ans_04u1[15].ToString();
                                evalResults.ans_04u1_17 = ans_04u1[16].ToString();
                                evalResults.ans_04u1_18 = ans_04u1[17].ToString();
                                evalResults.ans_04u1_19 = ans_04u1[18].ToString();
                                evalResults.ans_04u1_20 = ans_04u1[19].ToString();

                                evalResults.ans_04u2_01 = ans_04u2[0].ToString();
                                evalResults.ans_04u2_02 = ans_04u2[1].ToString();
                                evalResults.ans_04u2_03 = ans_04u2[2].ToString();
                                evalResults.ans_04u2_04 = ans_04u2[3].ToString();
                                evalResults.ans_04u2_05 = ans_04u2[4].ToString();
                                evalResults.ans_04u2_06 = ans_04u2[5].ToString();

                                evalResults.ans_04u3_01 = ans_04u3[0].ToString();
                                evalResults.ans_04u3_02 = ans_04u3[1].ToString();
                                evalResults.ans_04u3_03 = ans_04u3[2].ToString();
                                evalResults.ans_04u3_04 = ans_04u3[3].ToString();
                                evalResults.ans_04u3_05 = ans_04u3[4].ToString();
                                evalResults.ans_04u3_06 = ans_04u3[5].ToString();
                                evalResults.ans_04u3_07 = ans_04u3[6].ToString();

                                evalResults.ans_04u4_01 = ans_04u4[0].ToString();
                                evalResults.ans_04u4_02 = ans_04u4[1].ToString();
                                evalResults.ans_04u4_03 = ans_04u4[2].ToString();
                                evalResults.ans_04u4_04 = ans_04u4[3].ToString();
                                evalResults.ans_04u4_05 = ans_04u4[4].ToString();
                                evalResults.ans_04u4_06 = ans_04u4[5].ToString();
                                evalResults.ans_04u4_07 = ans_04u4[6].ToString();
                                evalResults.ans_04u4_08 = ans_04u4[7].ToString();
                                evalResults.ans_04u4_09 = ans_04u4[8].ToString();
                                evalResults.ans_04u4_10 = ans_04u4[9].ToString();
                                evalResults.ans_04u4_11 = ans_04u4[10].ToString();
                                evalResults.ans_04u4_12 = ans_04u4[11].ToString();
                                evalResults.ans_04u4_13 = ans_04u4[12].ToString();
                                evalResults.ans_04u4_14 = ans_04u4[13].ToString();
                                evalResults.ans_04u4_15 = ans_04u4[14].ToString();
                            }
                        }
                    }
                }
            }
            catch (SqlException e2)
            {
            }

            return(evalResults);
        }