Пример #1
0
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        //Guid id = new Guid();
        UserDataSet          userData             = new UserDataSet();
        UserDataTableAdapter userDataTableAdapter = new UserDataTableAdapter();

        UserDataSet.UserdataRow userdataRow = userData.Userdata.NewUserdataRow();
        DataTable a = userDataTableAdapter.GetData();


        // userdataRow.UserId = id;
        userdataRow.First  = first;
        userdataRow.Last   = last;
        userdataRow.Phone  = phone;
        userdataRow.Email  = email;
        userdataRow.TeamId = teamId;
        userData.Userdata.Rows.Add(userdataRow);
        userDataTableAdapter.Update(userData.Userdata);
        Response.Redirect("Default.aspx");
    }
        public List<Person> GetAllAccount()
        {
            UserDataTableAdapter adapter = new UserDataTableAdapter();
            List<Person> accountList = new List<Person>();
            var accountTable = adapter.GetAllAccounts();
            string id = "";
            string name = "";
            int typeId = 0;
            string type = "";
            foreach (var row in accountTable)
            {
                id = Convert.ToString(row.Id);
                name = Convert.ToString(row.Username);
                typeId = Convert.ToInt16(row.Type);
                AccountTypeTableAdapter acadapter = new AccountTypeTableAdapter();
                type = Convert.ToString(acadapter.GetTypeNameById(typeId)[0].TypeName);
                accountList.Add(new Person(id, name, type));

            }
            return accountList;
        }
 public Person loginToSystem(string username, string password)
 {
     UserDataTableAdapter udAdapter = new UserDataTableAdapter();
     try
     {
         var details = udAdapter.GetUserDataWithLogin(username, password)[0];
         string name = details.Username;
         int id = details.Id;
         AccountTypeTableAdapter acTypeAdapter = new AccountTypeTableAdapter();
         string type = acTypeAdapter.GetTypeNameById(details.Type)[0].TypeName;
         return new Person(Convert.ToString(id), name, type);
     }
     catch {
         return null;
     }
 }
        public List<SelfTestResult> getUserSelfTestResult(string userId)
        {
            UserResultInSelfTestTableAdapter userSTAdapter = new UserResultInSelfTestTableAdapter();
            List<SelfTestResult> list = new List<SelfTestResult>();
            int uId = Convert.ToInt32(userId);
            UserDataTableAdapter adapter = new UserDataTableAdapter();
            foreach (var row in userSTAdapter.GetSelfTestResultByUserId(uId))
            {
                SelfTestResult str = new SelfTestResult();
                str.questionId = row.SelfTestId;
                str.userId = row.UserId;
                str.username = adapter.GetUserDataById(str.userId)[0].Username;
                try
                {
                    str.score = row.Score;

                }
                catch (StrongTypingException e)
                {
                    str.score = -1;
                }
                try
                {
                    str.answer = row.Answer;

                }
                catch (StrongTypingException e)
                {
                    str.answer = null;
                }
                list.Add(str);
            }
            return list;
        }
        public MessageBox GetMessageBox(string courseCode, string courseNumber)
        {
            MessageBox messageBox = new MessageBox(courseCode + courseNumber, "");
            QandATableAdapter qaAdapter = new QandATableAdapter();
            CourseTableAdapter courseAdapter = new CourseTableAdapter();
            var courseIdList = courseAdapter.GetIdByCourseDetails(courseCode, Convert.ToInt32(courseNumber));
            int courseId = courseIdList[0].Id;
            var qaTable = qaAdapter.GetMessageListByCourseId(courseId);
            AnswerTypeTableAdapter answerTypeAdapter = new AnswerTypeTableAdapter();
            UserDataTableAdapter userAdapter = new UserDataTableAdapter();
            foreach (var row in qaTable)
            {
                int userId = row.AskedBy;
                string username = userAdapter.GetUserDataById(userId)[0].Username;
                Message message = new Message(username, row.Question);
                message.createTime = row.CreatedTime.ToString("G");
                message.messageId = row.Id;
                try
                {
                    Answer answer = new Answer(row.AnswerType, row.Answer);
                    message.addAnswer(answer);
                }
                catch (StrongTypingException e)
                {

                }
                messageBox.addMessage(message);
            }
            return messageBox;
        }