コード例 #1
0
        /// <summary>
        ///
        /// </summary>
        private bool checkCheckBox()
        {
            bool flag = false;

            using (StudentDataContext db = new StudentDataContext())
            {
                List <string> studentId  = new List <string>();
                List <int>    year       = new List <int>();
                var           checkCount = 0;
                foreach (GridViewRow gRow in GridView1.Rows)
                {
                    CheckBox check = gRow.FindControl("Check") as CheckBox;

                    if (check.Checked)
                    {
                        studentId.Insert(checkCount, gRow.Cells[1].Text);
                        year.Insert(checkCount, int.Parse(gRow.Cells[7].Text));
                        checkCount += 1;
                    }
                }
                if (checkCount < 1)
                {
                    Message2.Text = "未選択です。";
                }
                else
                {
                    Session["idList"]   = studentId;
                    Session["yearList"] = year;
                    flag = true;
                }
            }
            return(flag);
        }
コード例 #2
0
        /// <summary>
        ///
        /// </summary>
        private void deleteRecord()
        {
            using (StudentDataContext db = new StudentDataContext())
            {
                List <string> studentId = (List <string>)Session["idList"];
                List <int>    year      = (List <int>)Session["yearList"];

                for (int i = 0; i < studentId.Count; i++)
                {
                    var deleteQuery = from record in db.STUDENT_HEALTH
                                      where record.StudentId == studentId[i] && record.Year == year[i]
                                      select record;

                    foreach (var deleteData in deleteQuery)
                    {
                        db.STUDENT_HEALTH.DeleteOnSubmit(deleteData);
                    }

                    try
                    {
                        db.SubmitChanges();
                        Session["deleted"] = true;
                    }
                    catch (Exception error)
                    {
                        Console.WriteLine(error);
                    }
                }
            }
        }
コード例 #3
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        private bool duplicateChecker()
        {
            var flag = false;

            //LINQ to SQL

            using (var db = new StudentDataContext())
            {
                var studentId = String.Format("{0:D6}", int.Parse(TextBox1.Text));

                var students = from student in db.STUDENT_BASIC
                               join health in db.STUDENT_HEALTH on student.StudentId equals health.StudentId
                               where student.StudentId == studentId && health.Year == System.Convert.ToInt32(DropDownList1.Text)
                               select student;

                bool hasMatch = students.Any();

                if (hasMatch == true)
                {
                    flag = true; //DBに重複レコード有
                }
            }


            return(flag);
        }
コード例 #4
0
        /// <summary>
        ///
        /// </summary>
        private void updateRecord()
        {
            using (StudentDataContext db = new StudentDataContext())
            {
                var height      = Math.Round(double.Parse(TextBox1.Text), 2, MidpointRounding.AwayFromZero);
                var weight      = Math.Round(double.Parse(TextBox2.Text), 2, MidpointRounding.AwayFromZero);
                var idealWeight = (height - 100) * 0.9;

                var updateQuery = from student in db.STUDENT_HEALTH
                                  where student.StudentId == Label4.Text && student.Year == System.Convert.ToInt32(Label3.Text)
                                  select student;

                foreach (var student in updateQuery)
                {
                    student.Height      = (decimal)height;
                    student.Weight      = (decimal)weight;
                    student.IdealWeight = (decimal)idealWeight;
                }

                try
                {
                    db.SubmitChanges();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }
        }
コード例 #5
0
        /// <summary>
        ///
        /// </summary>
        private void insertRecord()
        {
            //結果表示用
            //string result = string.Empty;

            using (StudentDataContext student = new StudentDataContext())
            {
                var studentId   = String.Format("{0:D6}", int.Parse(TextBox1.Text));
                var height      = Math.Round(double.Parse(TextBox2.Text), 2, MidpointRounding.AwayFromZero);
                var weight      = Math.Round(double.Parse(TextBox3.Text), 2, MidpointRounding.AwayFromZero);
                var idealWeight = (height - 100) * 0.9;
                var year        = short.Parse(DropDownList1.Text);

                STUDENT_HEALTH health = new STUDENT_HEALTH
                {
                    StudentId   = studentId,
                    Height      = (decimal)height,
                    Weight      = (decimal)weight,
                    IdealWeight = (decimal)idealWeight,
                    Year        = year
                };
                student.STUDENT_HEALTH.InsertOnSubmit(health);

                try
                {
                    student.SubmitChanges();
                    DropDownList1.Text = "2015";
                    TextBox1.Text      = "";
                    TextBox2.Text      = "";
                    TextBox3.Text      = "";
                    Label7.Text        = "登録に成功しました。";
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e);
                    Label7.Text = "登録に失敗しました。";
                }
            }
        }
コード例 #6
0
        /// <summary>
        /// IDチェック
        /// </summary>
        /// <returns>エラー内容によって返り値が変わる</returns>
        private int IDValidator()
        {
            var flag  = 0;
            var intId = 0;

            if ((!(int.TryParse(TextBox1.Text, out intId))))
            //数値でないか、intの範囲を超えた場合、エラーメッセージを表示
            {
                flag = 1;
            }
            else if ((intId < 0 || intId.ToString().Length > 6))
            //6桁以上で0より小さい数値の場合、エラーメッセージを表示
            {
                flag = 1;
            }
            else //正しい数値の場合、続行
            {
                string studentId = String.Format("{0:D6}", intId);

                //LINQ to SQL
                string conStr = "Data Source=TRAINING;Initial Catalog=RESTransaction;Integrated Security=True";

                var db = new StudentDataContext(conStr);

                var students = from s in db.STUDENT_BASIC
                               where s.StudentId == studentId
                               select s;

                bool hasMatch = students.Any();

                if (hasMatch == false)
                {
                    flag = 2;
                }
            }
            return(flag);
        }
コード例 #7
0
ファイル: New.aspx.cs プロジェクト: jokosh/StudentInformation
        /// <summary>
        /// IDチェック
        /// </summary>
        /// <returns>エラー内容によって返り値が変わる</returns>
        private int IDValidator()
        {
            var flag = 0;
            var intId = 0;

            if ((!(int.TryParse(TextBox1.Text, out intId))))
            //数値でないか、intの範囲を超えた場合、エラーメッセージを表示
            {
                flag = 1;
            }
            else if ((intId < 0 || intId.ToString().Length > 6))
            //6桁以上で0より小さい数値の場合、エラーメッセージを表示
            {
                flag = 1;
            }
            else //正しい数値の場合、続行
            {
                string studentId = String.Format("{0:D6}", intId);

                //LINQ to SQL
                string conStr = "Data Source=TRAINING;Initial Catalog=RESTransaction;Integrated Security=True";

                var db = new StudentDataContext(conStr);

                var students = from s in db.STUDENT_BASIC
                               where s.StudentId == studentId
                               select s;

                bool hasMatch = students.Any();

                if (hasMatch == false)
                {
                    flag = 2;
                }

            }
            return flag;
        }
コード例 #8
0
ファイル: New.aspx.cs プロジェクト: jokosh/StudentInformation
        /// <summary>
        /// 
        /// </summary>
        private void insertRecord()
        {
            //結果表示用
            //string result = string.Empty;

            using (StudentDataContext student = new StudentDataContext())
            {
                var studentId = String.Format("{0:D6}", int.Parse(TextBox1.Text));
                var height = Math.Round(double.Parse(TextBox2.Text), 2, MidpointRounding.AwayFromZero);
                var weight = Math.Round(double.Parse(TextBox3.Text), 2, MidpointRounding.AwayFromZero);
                var idealWeight = (height - 100) * 0.9;
                var year = short.Parse(DropDownList1.Text);

                STUDENT_HEALTH health = new STUDENT_HEALTH
               {
                   StudentId = studentId,
                   Height = (decimal)height,
                   Weight = (decimal)weight,
                   IdealWeight = (decimal)idealWeight,
                   Year = year
               };
                student.STUDENT_HEALTH.InsertOnSubmit(health);

                try
                {
                    student.SubmitChanges();
                    DropDownList1.Text = "2015";
                    TextBox1.Text = "";
                    TextBox2.Text = "";
                    TextBox3.Text = "";
                    Label7.Text = "登録に成功しました。";
                }
                catch(Exception e)
                {
                    Debug.WriteLine(e);
                    Label7.Text = "登録に失敗しました。";
                }
            }
        }
コード例 #9
0
ファイル: New.aspx.cs プロジェクト: jokosh/StudentInformation
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        private bool duplicateChecker()
        {
            var flag = false;

            //LINQ to SQL

            using (var db = new StudentDataContext())
            {
                var studentId = String.Format("{0:D6}", int.Parse(TextBox1.Text));
                
                var students = from student in db.STUDENT_BASIC
                               join health in db.STUDENT_HEALTH on student.StudentId equals health.StudentId
                               where student.StudentId ==studentId && health.Year == System.Convert.ToInt32(DropDownList1.Text)
                               select student;

                bool hasMatch = students.Any();

                if (hasMatch == true)
                {
                    flag = true; //DBに重複レコード有
                }
            }


            return flag;
        }
コード例 #10
0
        /// <summary>
        /// 
        /// </summary>
        private void deleteRecord()
        {
            using (StudentDataContext db = new StudentDataContext())
            {
                List<string> studentId = (List<string>)Session["idList"];
                List<int> year = (List<int>)Session["yearList"];

                for (int i = 0; i < studentId.Count; i++)
                {
                    var deleteQuery = from record in db.STUDENT_HEALTH
                                      where record.StudentId == studentId[i] && record.Year == year[i]
                                      select record;

                    foreach (var deleteData in deleteQuery)
                    {
                        db.STUDENT_HEALTH.DeleteOnSubmit(deleteData);
                    }

                    try
                    {
                        db.SubmitChanges();
                        Session["deleted"] = true;
                    }
                    catch (Exception error)
                    {
                        Console.WriteLine(error);
                    }
                }
            }
        }
コード例 #11
0
        /// <summary>
        /// 
        /// </summary>
        private void updateRecord()
        {
            using (StudentDataContext db = new StudentDataContext())
            {
                var height = Math.Round(double.Parse(TextBox1.Text), 2, MidpointRounding.AwayFromZero);
                var weight = Math.Round(double.Parse(TextBox2.Text), 2, MidpointRounding.AwayFromZero);
                var idealWeight = (height - 100) * 0.9;

                var updateQuery = from student in db.STUDENT_HEALTH
                               where student.StudentId == Label4.Text && student.Year == System.Convert.ToInt32(Label3.Text)
                               select student;

                foreach (var student in updateQuery)
                {
                    student.Height = (decimal)height;
                    student.Weight = (decimal)weight;
                    student.IdealWeight = (decimal)idealWeight;
                }

                try
                {
                    db.SubmitChanges();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            
            }

        }
コード例 #12
0
        /// <summary>
        /// 
        /// </summary>
        private bool checkCheckBox()
        {
            bool flag = false;
            using (StudentDataContext db = new StudentDataContext())
            {
                List<string> studentId = new List<string>();
                List<int> year = new List<int>();
                var checkCount = 0;
                foreach (GridViewRow gRow in GridView1.Rows)
                {
                    CheckBox check = gRow.FindControl("Check") as CheckBox;

                    if (check.Checked)
                    {
                        studentId.Insert(checkCount, gRow.Cells[1].Text);
                        year.Insert(checkCount, int.Parse(gRow.Cells[7].Text));
                        checkCount += 1;
                    }
                }
                if (checkCount < 1)
                {
                    Message2.Text = "未選択です。";
                }
                else
                {
                    Session["idList"] = studentId;
                    Session["yearList"] = year;
                    flag = true;
                }
            }
            return flag;
        }