コード例 #1
0
 protected void btnSubmit_Click(object sender, EventArgs e)
 {
     if (CheckValid())
     {
         gtsvn.Tour tour = new gtsvn.Tour
         {
             TourNm      = txtNm.Text,
             DescReview  = txtDescRev.Text,
             TourReview  = CKEditor1.Text,
             Description = CKEditor2.Text,
             TourGroup   = Int32.Parse(ddGroup1.SelectedValue),
             IsPromotion = cbPromotion.Checked,
             IsProminent = cbProminent.Checked,
             IsActived   = true,
             InsDate     = DateTime.Now
         };
         data.Tour.InsertOnSubmit(tour);
         try
         {
             //submit changes to get new identity userid
             data.SubmitChanges();
             //insert into role
             int newtourid = (int)tour.TourID;
             for (int i = 0; i <= lbKind.Items.Count - 1; i++)
             {
                 if (lbKind.Items[i].Selected)
                 {
                     //insert into UserRole table
                     gtsvn.TourTourKind tourtourkind = new gtsvn.TourTourKind
                     {
                         TourID     = newtourid,
                         TourKindID = Int32.Parse(lbKind.Items[i].Value)
                     };
                     data.TourTourKind.InsertOnSubmit(tourtourkind);
                 }
             }
             data.SubmitChanges();
             lblStatus.Text        = "Thêm thành công tour <b>" + txtNm.Text + "</b>";
             ddGroup.SelectedValue = ddGroup1.SelectedValue;
             SetGridMain();
             //reset input field
             txtNm.Text             = "";
             txtDescRev.Text        = "";
             CKEditor1.Text         = "";
             CKEditor2.Text         = "";
             ddGroup1.SelectedIndex = 0;
             cbPromotion.Checked    = false;
             cbProminent.Checked    = false;
             lbKind.SelectedIndex   = -1;
         }
         catch (Exception ex)
         {
             lblStatus.Text = ex.ToString();
         }
     }
 }
コード例 #2
0
 protected void btnSubmit_Click(object sender, EventArgs e)
 {
     if (txtId.Text != "")
     {
         var result = (from t in data.Tour where (int)t.TourID == Int32.Parse(txtId.Text) select t).First();
         result.TourNm      = txtNm.Text;
         result.DescReview  = txtDescRev.Text;
         result.TourReview  = CKEditor1.Text;
         result.Description = CKEditor2.Text;
         result.TourGroup   = Int32.Parse(ddGroup1.SelectedValue);
         result.IsPromotion = (bool)cbPromotion.Checked;
         result.IsProminent = (bool)cbProminent.Checked;
         result.InsDate     = DateTime.Now;
         try
         {
             data.SubmitChanges();
             //delete old tour tourkind
             var result1 = from t in data.TourTourKind where t.TourID == Int32.Parse(txtId.Text) select t;
             foreach (var res in result1)
             {
                 data.TourTourKind.DeleteOnSubmit(res);
             }
             data.SubmitChanges();
             //insert new tour tourkind
             for (int i = 0; i <= lbKind.Items.Count - 1; i++)
             {
                 if (lbKind.Items[i].Selected)
                 {
                     //insert into TourTourKind table
                     gtsvn.TourTourKind tourtourkind = new gtsvn.TourTourKind
                     {
                         TourID     = Int32.Parse(txtId.Text),
                         TourKindID = Int32.Parse(lbKind.Items[i].Value)
                     };
                     data.TourTourKind.InsertOnSubmit(tourtourkind);
                 }
             }
             data.SubmitChanges();
             lblStatus.Text = "Thay đổi thông tin tour <b>" + txtNm.Text + "</b> thành công";
         }
         catch (Exception ex)
         {
             lblStatus.Text = "Có lỗi xảy ra. Chi tiết lỗi: " + ex.ToString();
         }
     }
 }