コード例 #1
0
ファイル: BuyerDAL.cs プロジェクト: AMS-Capstone/AMS
        //Get all Buyers
        public int CreateBuyer(Buyer buyer)
        {
            int id = 0;
            MySqlConnection conn = new MySqlConnection(connectionString);
            conn.Open();

            try
            {
                MySqlCommand cmd = new MySqlCommand();
                cmd.CommandText = "ADD_BUYER";
                cmd.Parameters.Add(new MySqlParameter("@N_BuyerFirstName", buyer.BuyerFirstName));
                cmd.Parameters.Add(new MySqlParameter("@N_BuyerLastName", buyer.BuyerLastName));
                cmd.Parameters.Add(new MySqlParameter("@N_BuyerAddress", buyer.BuyerAddress));
                cmd.Parameters.Add(new MySqlParameter("@N_BuyerCity", buyer.BuyerCity));
                cmd.Parameters.Add(new MySqlParameter("@N_BuyerProvince", buyer.BuyerProvince));
                cmd.Parameters.Add(new MySqlParameter("@N_BuyerPostalCode", buyer.BuyerPostalCode));
                cmd.Parameters.Add(new MySqlParameter("@N_BuyerPhone", buyer.BuyerPhone));
                cmd.Parameters.Add(new MySqlParameter("@N_BuyerBidderNumber", buyer.BidderNum));
                cmd.Parameters.Add(new MySqlParameter("@N_BuyerPermanent", buyer.BuyerIsPermanent));
                cmd.Parameters.Add(new MySqlParameter("@N_BuyerBanned", buyer.IsBanned));

                MySqlParameter returnParameter = new MySqlParameter();
                returnParameter.Direction = System.Data.ParameterDirection.ReturnValue;

                cmd.Parameters.Add(returnParameter);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Connection = conn;
                cmd.ExecuteNonQuery();

                id = Convert.ToInt32(returnParameter.Value.ToString());
            }
            catch (Exception ex)
            {
                //Panic
                throw ex;
            }
            finally
            {
                //Tie the loose ends here
                conn.Close();
            }
            return id;
        }
コード例 #2
0
ファイル: Buyers.aspx.cs プロジェクト: AMS-Capstone/AMS
        protected void BTNSubmit_Click(object sender, EventArgs e)
        {
            Buyer buyer = new Buyer();
            if (TXTBidNum.Text.ToString() != null)
            {
                buyer.BidderNum = Convert.ToInt32(TXTBidNum.Text.ToString());
            }
            else
            {
                buyer.BidderNum = 0;
            }
            buyer.BuyerFirstName = TXTFirstName.Text;
            buyer.BuyerLastName = TXTLastName.Text;
            buyer.BuyerAddress = TXTAddress.Text;
            buyer.BuyerCity = TXTCIty.Text;
            buyer.BuyerProvince = DDLProvince.SelectedValue;
            buyer.BuyerPostalCode = TXTPostal.Text;
            buyer.BuyerPhone = TXTPhone.Text;
            buyer.BuyerDriverLicense = TXTDLicense.Text;
            buyer.IsBanned = CHKBanned.Checked;
            buyer.BuyerIsPermanent = CHKPermanent.Checked;
            buyer.Notes = TXTNotes.Text;

            try
            {
                //Call DAL
                int id = buyerService.CreateBuyer(buyer);
            }
            catch (Exception ex)
            {
                AlertDiv.InnerHtml = "<div class=\"alert alert-danger fade in\">" +
                "<a href=\"#\" class=\"close\" data-dismiss=\"alert\">&times;</a>" +
                "<strong>Error!&nbsp;</strong><label id=\"Alert\" runat=\"server\">" + ex.Message +
                "</label></div>";
            }
        }
コード例 #3
0
ファイル: BuyerDAL.cs プロジェクト: AMS-Capstone/AMS
        //Get all Buyers
        public int UpdateBuyer(Buyer buyer)
        {
            int id = 0;
            MySqlConnection conn = new MySqlConnection(connectionString);
            conn.Open();

            try
            {
                MySqlCommand cmd = new MySqlCommand();
                cmd.CommandText = "UPDATE_BUYER";
                cmd.Parameters.Add(new MySqlParameter("@N_BuyerID", buyer.BuyerID));
                cmd.Parameters.Add(new MySqlParameter("@N_BuyerFirstName", buyer.BuyerFirstName));
                cmd.Parameters.Add(new MySqlParameter("@N_BuyerLastName", buyer.BuyerLastName));
                cmd.Parameters.Add(new MySqlParameter("@N_BuyerAddress", buyer.BuyerAddress));
                cmd.Parameters.Add(new MySqlParameter("@N_BuyerCity", buyer.BuyerCity));
                cmd.Parameters.Add(new MySqlParameter("@N_BuyerProvince", buyer.BuyerProvince));
                cmd.Parameters.Add(new MySqlParameter("@N_BuyerPostalCode", buyer.BuyerPostalCode));
                cmd.Parameters.Add(new MySqlParameter("@N_BuyerPhone", buyer.BuyerPhone));
                cmd.Parameters.Add(new MySqlParameter("@N_BuyerBidderNumber", buyer.BidderNum));
                cmd.Parameters.Add(new MySqlParameter("@N_BuyerPermanent", buyer.BuyerIsPermanent));
                cmd.Parameters.Add(new MySqlParameter("@N_BuyerBanned", buyer.IsBanned));
                cmd.Parameters.Add(new MySqlParameter("@N_BuyerNotes", buyer.Notes));

                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Connection = conn;
                cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                //Panic
                throw ex;
            }
            finally
            {
                //Tie the loose ends here
                conn.Close();
            }
            return id;
        }