外键如何工作?

时间:2017-11-16 14:27:23

标签: c# sql asp.net visual-studio

我的日程安排(日期)有问题,即它保持为空。 所以,基本上我目前的情况是我有一个研讨会清单,用户必须从gridview中选择,还需要选择计划日期(用户点击列表研讨会后)。

我的问题是为什么日程安排日期无法转移到用户付款后为空的数据库。

我的代码列表研讨会,

protected void btnRegister_Click(object sender, EventArgs e)
{
    //Panel1.Visible = true;
    List<Seminar> seminars = SeminarMgr.getAllSeminar();
    Seminar a = seminars[gvSeminar.PageSize * gvSeminar.PageIndex + gvSeminar.SelectedIndex];
    List<Schedule> schedules = ScheduleMgr.getAllScheduleById("");
    Schedule b = schedules[gvSchedule.SelectedIndex];
    List<Speaker> speakers = SpeakerDBMgr.getAllSpeaker();
    Speaker c = speakers[gvSeminar.SelectedIndex];

    if (Session["cart"] == null)
    {
        //member session of user
        ShoppingCart s = new ShoppingCart();
        s.Member = (Member)Session["user"];

        Session["cart"] = s;
    }
    //adding a seminar by user 
    ShoppingCart sc = (ShoppingCart)Session["cart"];
    sc.Seminar = a;
    sc.Seminar.Schedule = b;
    sc.Seminar.Speaker = c;




    //redirecting a new page to shoppingcartform.aspx
    Response.Redirect("ShoppingCartForm.aspx");

}

此代码用于我的购物车表单,即付款,

    if (tbxName.Text != null && tbxCC.Text != null && ddlCCType.Text != null && tbxExpDate.Text != null)
    {
        ShoppingCart sc = (ShoppingCart)Session["cart"];
        sc.Name = tbxName.Text;
        if (rdbCash.Checked == true)
        {
            sc.OptionPay = rdbCash.Text;

        }else
        {
            sc.OptionPay = rdbCC.Text;
        }
        sc.CreditCard = tbxCC.Text;
        sc.CreditCardType = ddlCCType.Text;
        sc.SecurityCode = tbxCode.Text;
        sc.CCExpiryDate = tbxExpDate.Text;
        sc.Seminar.Schedule.Date = Convert.ToDateTime(tbxDate.Text);
        string a = lblAmount.Text;
        string b = a.Substring(1);
        lblAmount.Text = b;
        sc.TotalAmount = Convert.ToDecimal(lblAmount.Text);
        int Id = ShoppingCartDBMgr.purchaseSeminar(sc);
        lblOutput.Text = "Confirm. order id is " + Id;
        //display output for payment successfully
        //lblOutput.Text = "Payment Successfully!";
        //make it null for amount, date and session of cart after transaction are being successful
        lblAmount.Text = null;
        lblDate.Text = null;
        Session["cart"] = null;
        //send an email for confirmation
        //SmtpClient client = new SmtpClient("smtp.gmail.com");
        //client.EnableSsl = true;
        //client.Credentials = new NetworkCredential("inft3050@gmail.com", "inft.3050");

        //MailMessage msg = new MailMessage("inft3050@gmail.com", "andrian97@windowslive.com");
        //msg.Subject = "Payment confirmation";
        //msg.Body = "Thanks for joining our seminar!";
        //client.Send(msg);
    }
    else
    {
        //display an output if payment is not valid
        lblOutput.Text = "Payment is not valid!";
    }

此代码是我的数据库管理员,用于插入付款

public static int purchaseSeminar(ShoppingCart sc)
{
    int Id = -1;
    SqlConnection con = new SqlConnection(conStr);
    try
    {
        SqlCommand command = new SqlCommand();
        command.Connection = con;

        command.CommandText = "insert into Payment (payment_name, payment_ccNo, payment_ccType, payment_ccCode, payment_expDate, payment_price, payment_optionPay, payment_date, participant_email, sch_id) values (@payment_name, @payment_ccNo, @payment_ccType, @payment_ccCode, @payment_expDate, @payment_price, @payment_optionPay, @payment_date, @participant_email, @sch_id)";
        command.Parameters.AddWithValue("@payment_name", sc.Name);
        command.Parameters.AddWithValue("@payment_ccNo", sc.CreditCard);
        command.Parameters.AddWithValue("@payment_ccType", sc.CreditCardType);
        command.Parameters.AddWithValue("@payment_ccCode", sc.SecurityCode);
        command.Parameters.AddWithValue("@payment_expDate", sc.CCExpiryDate);
        command.Parameters.AddWithValue("@payment_price", sc.TotalAmount);
        command.Parameters.AddWithValue("@payment_optionPay", sc.OptionPay);
        DateTime da = DateTime.Now;
        command.Parameters.AddWithValue("@payment_date", da);
        command.Parameters.AddWithValue("@participant_email", sc.Member.Email);
        command.Parameters.AddWithValue("@sch_id", sc.Schedule.Id);
        con.Open();

        if (command.ExecuteNonQuery() > 0)
        {
            command.CommandText = "Select @@identity";
            Id = Convert.ToInt32(command.ExecuteScalar());
        }
        return Id;
    }
    finally
    {
        con.Close();
    }
}

0 个答案:

没有答案