コード例 #1
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);
                    }
                }
            }
        }
コード例 #2
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);
                }
            }
        }
コード例 #3
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 = "登録に失敗しました。";
                }
            }
        }
コード例 #4
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 = "登録に失敗しました。";
                }
            }
        }
コード例 #5
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);
                    }
                }
            }
        }
コード例 #6
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);
                }
            
            }

        }