Пример #1
0
        public int SaveShopingCost(ShopingModel shoping)
        {
            try
            {
                connection = new SqlConnection(connectionString);
                connection.Open();
                query = "insert into Shoping (MemberId,Date,Cost) values (@MemberId,@Date,@Cost)";
                //query = "insert into Members (Name,Email,Phone) values ('"+member.MemberName+"','"+member.Email+"','"+member.Phone+"')";
                command = new SqlCommand(query, connection);
                command.Parameters.Clear();
                command.Parameters.AddWithValue("MemberId", shoping.MemberId);
                command.Parameters.AddWithValue("Date", shoping.Date);
                command.Parameters.AddWithValue("Cost", shoping.Cost);
                return(command.ExecuteNonQuery());
            }
            catch (Exception exception)
            {
                throw;
            }


            finally
            {
                connection.Close();
            }
        }
Пример #2
0
        private void saveButton_Click(object sender, EventArgs e)
        {
            ShopingModel aShoping = new ShopingModel();

            aShoping.MemberId = Convert.ToInt32(nameComboBox.SelectedValue);
            aShoping.Date     = Convert.ToDateTime(shopingDateTimePicker.Text);

            if (aShoping.MemberId == -1)
            {
                MessageBox.Show("Please select name");
                return;
            }

            try
            {
                aShoping.Cost = Convert.ToInt32(costTextBox.Text);
            }
            catch (Exception exception)
            {
                MessageBox.Show("Input must be integer Number");
            }


            if (saveButton.Text == "Save")
            {
                string message = aShopingManager.SaveShopingCost(aShoping);
                MessageBox.Show(message);
            }
            else
            {
            }
            GetShopingListWithMember();
            Reset();
        }
Пример #3
0
        public string SaveShopingCost(ShopingModel shoping)
        {
            bool isExist = aShopingGateway.IsExistShoping(shoping);

            if (isExist)
            {
                return("Already Cost Added");
            }

            int rowAffected = aShopingGateway.SaveShopingCost(shoping);

            if (rowAffected > 0)
            {
                return("Save Shoping Cost");
            }
            return("Failed to Add");
        }
Пример #4
0
        public bool IsExistShoping(ShopingModel shoping)
        {
            connection = new SqlConnection(connectionString);
            connection.Open();
            query   = "SELECT * FROM Shoping WHERE MemberId=@MemberId AND Date=@Date";
            command = new SqlCommand(query, connection);
            command.Parameters.Clear();
            command.Parameters.AddWithValue("MemberId", shoping.MemberId);
            command.Parameters.AddWithValue("Date", shoping.Date);
            reader = command.ExecuteReader();

            bool rowAffected = reader.HasRows;

            reader.Close();
            connection.Close();
            return(rowAffected);
        }