Exemple #1
0
        protected void typeSaveButton_Click(object sender, EventArgs e)
        {
            Type type = new Type();

            if (typeTextBox.Text == "")
            {
                ShowMessage("Please enter type name", MessageType.Error);
            }
            else
            {
                type.TypeName = typeTextBox.Text;
                string msg = typeManager.Save(type);

                if (msg.StartsWith("Success"))
                {
                    showTypeList();
                    ShowMessage("Type name saved.", MessageType.Success);
                    typeTextBox.Text = string.Empty;
                }
                else
                {
                    ShowMessage(msg, MessageType.Error);
                }
            }
        }
        public List <Type> GetAllTypes()
        {
            List <Type>   typeList   = new List <Type>();
            SqlConnection connection = new SqlConnection(connectionString);
            //query
            string query = "SELECT * FROM Types ORDER BY TypeName";
            //execute
            SqlCommand command = new SqlCommand(query, connection);

            connection.Open();
            SqlDataReader reader = command.ExecuteReader();

            if (reader.HasRows)       // if table has list of products(product rows) or not
            {
                while (reader.Read()) //then continue its reading for each row
                {
                    Type aType = new Type();
                    aType.TypeId   = Convert.ToInt32(reader["TypeID"]);
                    aType.TypeName = reader["TypeName"].ToString();
                    typeList.Add(aType); // add types on list
                }
            }
            reader.Close();
            connection.Close();

            return(typeList);
        }
        public int SaveType(Type type)
        {
            //connection
            SqlConnection connection = new SqlConnection(connectionString);
            //query
            string query = "INSERT INTO Types (TypeName) VALUES('" + type.TypeName + "')";
            //execute
            SqlCommand command = new SqlCommand(query, connection);

            connection.Open();
            int rowAffected = command.ExecuteNonQuery();

            return(rowAffected);
        }
Exemple #4
0
        public string Save(Type type)
        {
            if (type.TypeName.Length < 3)
            {
                return("Name must be 3 charcters long");
            }
            if (typeGateway.IsTypeExist(type.TypeName))
            {
                return("Already exist");
            }
            int rowAffected = typeGateway.SaveType(type);

            if (rowAffected > 0)
            {
                return("Success");
            }
            return("Not save.");
        }