Exemplo n.º 1
0
        protected void btn_submit_Click(object sender, EventArgs e)
        {
            _5101BFinalProject.Models.ClientGiftshop clientgiftshop = new _5101BFinalProject.Models.ClientGiftshop();
            clientgiftshop.Gift_Sender_First_Name    = txt_sender_f_name.Text;
            clientgiftshop.Gift_Sender_Last_Name     = txt_sender_l_name.Text;
            clientgiftshop.Gift_Recipient_First_Name = txt_recipient_f_name.Text;
            clientgiftshop.Gift_Recipient_Last_Name  = txt_recipient_l_name.Text;
            clientgiftshop.Gift_Type = ddl_gift_type.SelectedItem.Value;
            clientgiftshop.Gift_Desc = txt_gift_desc.Text;

            _5101BFinalProject.Models.CalvinDb db = new _5101BFinalProject.Models.CalvinDb();

            try
            {
                db.Add(clientgiftshop);
            }
            catch (OracleException except)
            {
                if (txt_sender_f_name.Text == "")
                {
                    if (except.Message.Contains("ORA-01400"))
                    {
                        gift_send_f_name_err.Text = "Please provide Sender's first name.";
                    }
                }
                else
                {
                    gift_send_f_name_err.Text = "";
                }
                if (txt_sender_l_name.Text == "")
                {
                    if (except.Message.Contains("ORA-01400"))
                    {
                        gift_send_l_name_err.Text = "Please provide Sender's last name.";
                    }
                }
                else
                {
                    gift_send_l_name_err.Text = "";
                }
                if (txt_recipient_f_name.Text == "")
                {
                    if (except.Message.Contains("ORA-01400"))
                    {
                        gift_rec_f_name_err.Text = "Please provide Recipient's first name.";
                    }
                }
                else
                {
                    gift_rec_f_name_err.Text = "";
                }
                if (txt_recipient_l_name.Text == "")
                {
                    if (except.Message.Contains("ORA-01400"))
                    {
                        gift_rec_l_name_err.Text = "Please provide Recipient's last name.";
                    }
                }
                else
                {
                    gift_rec_l_name_err.Text = "";
                }
                // Gift Type
                if (except.Message.Contains("ORA-02290"))
                {
                    gift_type_err.Text = "Please select proper gift type.";
                }
                else
                {
                    gift_type_err.Text = "";
                }
                //Gift Description
                if (txt_gift_desc.Text == "")
                {
                    if (except.Message.Contains("ORA-01400"))
                    {
                        gift_desc_err.Text = "Please provide gift description.";
                    }
                }
                else
                {
                    gift_desc_err.Text = "";
                }
            }
            finally
            {
                thank_you_msg.Text = "Thank you, your order has been received.";
            }
        }
Exemplo n.º 2
0
        protected void btn_gs_create_Click(object sender, EventArgs e)
        {
            _5101BFinalProject.Models.GiftShopT giftshop = new _5101BFinalProject.Models.GiftShopT();
            //giftshop.Gift_Id = Convert.ToInt32(txt_gift_id2.Text); // how to put into validation
            giftshop.Gift_Sender_First_Name    = txt_sender_f_name.Text;
            giftshop.Gift_Sender_Last_Name     = txt_sender_l_name.Text;
            giftshop.Gift_Recipient_First_Name = txt_recipient_f_name.Text;
            giftshop.Gift_Recipient_Last_Name  = txt_recipient_l_name.Text;
            giftshop.Gift_Type = ddl_gift_type.SelectedItem.Value;
            giftshop.Gift_Desc = txt_gift_desc.Text;


            _5101BFinalProject.Models.CalvinDb db = new _5101BFinalProject.Models.CalvinDb();

            //if (Convert.ToInt32(txt_gift_id2.Text) == 0)
            if (txt_gift_id2.Text == "")
            {
                gift_id2_err.Text = "Please enter a valid number";
            }
            else if (txt_gift_price.Text == "")
            {
                gift_price_err.Text = "Please enter a valid number";
            }
            else if (txt_gift_sender_id.Text == "")
            {
                gift_sender_id_err.Text = "Please enter a valid number";
            }
            else if (txt_gift_recipient_id.Text == "")
            {
                gift_recipient_id_err.Text = "Please enter a valid number";
            }
            else
            {
                giftshop.Gift_Id = Convert.ToInt32(txt_gift_id2.Text);
                double giftprice = Convert.ToDouble(txt_gift_price.Text);
                giftshop.Gift_Price        = Math.Round(giftprice, 2);
                giftshop.Gift_Sender_Id    = Convert.ToInt32(txt_gift_sender_id.Text);
                giftshop.Gift_Recipient_Id = Convert.ToInt32(txt_gift_recipient_id.Text);

                gift_id2_err.Text          = "";
                gift_price_err.Text        = "";
                gift_sender_id_err.Text    = "";
                gift_recipient_id_err.Text = "";

                try
                {
                    db.Add(giftshop);
                }
                catch (OracleException except)
                {
                    if (txt_sender_f_name.Text == "")
                    {
                        if (except.Message.Contains("ORA-01400"))
                        {
                            gift_send_f_name_err.Text = "Please provide Sender's first name.";
                        }
                    }
                    else
                    {
                        gift_send_f_name_err.Text = "";
                    }
                    if (txt_sender_l_name.Text == "")
                    {
                        if (except.Message.Contains("ORA-01400"))
                        {
                            gift_send_l_name_err.Text = "Please provide Sender's last name.";
                        }
                    }
                    else
                    {
                        gift_send_l_name_err.Text = "";
                    }
                    if (txt_recipient_f_name.Text == "")
                    {
                        if (except.Message.Contains("ORA-01400"))
                        {
                            gift_rec_f_name_err.Text = "Please provide Recipient's first name.";
                        }
                    }
                    else
                    {
                        gift_rec_f_name_err.Text = "";
                    }
                    if (txt_recipient_l_name.Text == "")
                    {
                        if (except.Message.Contains("ORA-01400"))
                        {
                            gift_rec_l_name_err.Text = "Please provide Recipient's last name.";
                        }
                    }
                    else
                    {
                        gift_rec_l_name_err.Text = "";
                    }
                    // Recipient ID
                    if (except.Message.Contains("ORA-01400"))
                    {
                        gift_recipient_id_err.Text = "Please provide Recipient ID.";
                    }
                    else
                    {
                        gift_recipient_id_err.Text = "";
                    }
                    if (except.Message.Contains("ORA-01722"))
                    {
                        gift_recipient_id_err.Text = "Please input a valid number";
                    }
                    else
                    {
                        gift_recipient_id_err.Text = "";
                    }
                    if (except.Message.Contains("ORA-02291"))
                    {
                        gift_recipient_id_err.Text = "Recipient ID doesn't exist";
                    }
                    else
                    {
                        gift_recipient_id_err.Text = "";
                    }
                    // Sender ID
                    if (except.Message.Contains("ORA-01400"))
                    {
                        gift_sender_id_err.Text = "Please provide Sender ID.";
                    }
                    else
                    {
                        gift_sender_id_err.Text = "";
                    }
                    if (except.Message.Contains("ORA-01722"))
                    {
                        gift_sender_id_err.Text = "Please input a valid number";
                    }
                    else
                    {
                        gift_sender_id_err.Text = "";
                    }
                    if (except.Message.Contains("ORA-02291"))
                    {
                        gift_sender_id_err.Text = "Sender ID doesn't exist";
                    }
                    else
                    {
                        gift_sender_id_err.Text = "";
                    }
                    // Gift Price
                    if (except.Message.Contains("ORA-01400"))
                    {
                        gift_price_err.Text = "Please put price for the item.";
                    }
                    else
                    {
                        gift_price_err.Text = "";
                    }
                    if (except.Message.Contains("ORA-01722"))
                    {
                        gift_price_err.Text = "Please input a valid number";
                    }
                    else
                    {
                        gift_price_err.Text = "";
                    }
                    // Gift type
                    if (except.Message.Contains("ORA-02290"))
                    {
                        gift_type_err.Text = "Please select proper gift type.";
                    }
                    else
                    {
                        gift_type_err.Text = "";
                    }
                    // Gift Description
                    if (txt_gift_desc.Text == "")
                    {
                        if (except.Message.Contains("ORA-01400"))
                        {
                            gift_desc_err.Text = "Please provide gift description.";
                        }
                    }
                    else
                    {
                        gift_desc_err.Text = "";
                    }
                    if (except.Message.Contains("ORA-01400"))
                    {
                        gift_id2_err.Text = "Please provide Gift ID.";
                    }
                    else
                    {
                        gift_id2_err.Text = "";
                    }
                    if (except.Message.Contains("ORA-00001"))
                    {
                        gift_id2_err.Text = "Gift ID already in use.";
                    }
                    else
                    {
                        gift_id2_err.Text = "";
                    }
                    if (except.Message.Contains("ORA-01722"))
                    {
                        gift_id2_err.Text = "Please input a valid number";
                    }
                    else
                    {
                        gift_id2_err.Text = "";
                    }


                    lbl_insert_err.Text = except.Message + ". ";
                }
                finally
                {
                    lbl_insert_err.Text += Convert.ToString(db.Rows) + " rows inserted.";
                }
            }
        }