You probably have more formal experience than I have, and my code uses a mix-mash of SQL and LINQ, but as I do more customising I learn more and my code gets "cleaner".
Anyway: ok cool. Let's start with adding in a Product dropdown list (ddl), as this seems to be something you want to include.
Now before you read this, this is just a simple example on how I added the Product dropdown. This example doesn't include the more complex stuff of making Sub-Products and Versions dependant upon the chosen product.
The first thing I did was create a local copy of SlickTicket (ST) and a local copy of a ST db using SQL 2005 express, and then I used VS2008 and opened the Web site, using the ST folder location.
Now, please note, I'm using 28536, so it might be different if you're using a different release.
Now to add the ability to add a product ddl in I did the following:
Create a new DB table "products" with fields "product_id" (int) PK, "product_name" (varchar(100)). I then added a column to the Tickets table called "product_id" (int). Then I made a foriegn key in
the Tickets table from products.product_id to tickets.product_id.
Then you need to update the db.dbml file under App_Code. First, make sure your database is listed in Data Connections un the Server Explorer pane, and then double click the db.dbml file to open it.
Then all you need to do is (ensuring you've refreshed the data connection):
Delete the Ticket table
Drag the Ticket table from the data connection to the db.dbml file
Drag the Products table from the data connection to the db.dbml file
Save the db.dbml file.
Now we have to add the Product into the Ticket class under Ticket.Add (and Ticket.Update
if you want to treat the product as a TICKET-WIDE object) and add a way for a user to submit them using the UI:
Navigate to public static ticket Add(...
Add ", int product" before the ")"
Then in the logic add "newTicket.product_id = product;" BEFORE
Do the same for public static ticket Update(... replacing "newTicket" with "t".
Now NEW tickets are created in New_Ticket.aspx, and already existing tickets are edited in Ticket.aspx.
This is where I've mix-mashed SQL and LINQ, so if you know LINQ you might do a better job here then I did.
Anyway I added the following to the new_ticket.aspx
<asp:SqlDataSource ID="SqlProduct" runat="server"
ConnectionString="<%$ ConnectionStrings:SlickTicket %>"
SelectCommand="Select * from dbo.Products" />
<asp:DropDownList ID="ddlProduct" runat="server" DataSourceID="SqlProduct" DataTextField="Product_Name" DataValueField="Product_ID" Width="90%" />
Personally I put that in a new table under the exsiting one just under the txtTopic text box, but where you put it is up to you.
Now you need to add to the code behind to make sure it gets submitted:
protected void btnSubmit_Click(object sender, EventArgs e)
ticket newTicket = Tickets.Add(db, Server.HtmlEncode(txtTopic.Text), txtDetails.Text, Int32.Parse(ddlSubUnit.SelectedValue), Int32.Parse(ddlPriority.SelectedValue), u.id, u.sub_unit, Int32.Parse(ddlProduct.SelectedValue));
Now that should add the selected Product to the Ticket.
As I've decided that Products should be Ticket wide, therefore if it is changed later that change should be reflected in the Ticket table, and NOT the comment table, I had to add the Product input into the Ticket.aspx page to.
The same asp code will do, but a slight alteration to the code behind (ticket.aspx.cs):
protected void btnUpdate_Click(object sender, EventArgs e)
ticket _t = Tickets.Update(db2, t_id, Int32.Parse(ddlStatus.SelectedValue), Int32.Parse(ddlPriority.SelectedValue), Int32.Parse(ddlSubUnit.SelectedValue), Int32.Parse(ddlSubProduct.SelectedValue));
It's a subtle change, but VERY important if the Product is to be TICKET wide
The last thing we need to do is enable users with the ability to ADD new products to the system without them needing to connect directly to the database.
I did this by adding a new page to the project, but you could simply add it to an existing one (like admin\settings.aspx).
Here is the ASPX code I've written:
<asp:label ID="lblProduct2" runat="server" Text="Type the new product below:" />
<asp:TextBox ID="txtProduct" runat="server" />
<asp:Button ID="btnProduct" runat="server" Text="Add Product" OnClick="btnProduct_Click"/>
NOTE: I've just put the simple ASPX code you need to put the ability to enter a new Product in. Feel free to use a Collasible panel or Accordion or whatever you wish, around it.
Then the code behind needs to include this (again I used SQL, but feel free to use LINQ if you know how [I'd be interested in learning if you wouldn't mind sharing]):
protected void btnProduct_Click(object sender, EventArgs e)
if (txtProduct.Text != "")
string strNewProduct = txtProduct.Text;
string connStr = ConfigurationManager.ConnectionStrings["SlickTicket"].ConnectionString;
SqlConnection connSql = new SqlConnection(connStr);
//This checks if the entry already exists in the db table
string strSql = "Select * from Products Where Product_Name='" + strNewProduct + "'";
SqlCommand cmdSqlCheck = new SqlCommand(strSql, connSql);
sqlRead = cmdSqlCheck.ExecuteReader();
//If the entry already exists, close the db connection and report an error
lblProduct2.Text = "ERROR: Product already exists in the database.";
txtProduct.Text = "";
//Else insert the new entry, close the connection and report success
SqlCommand cmdSql = new SqlCommand("Insert into Products (Product_Name) Values ('" + strNewProduct + "')", connSql);
lblProduct2.Text = "Product added successfully - Repeat to add more.";
txtProduct.Text = "";
lblProduct2.Text = "ERROR: Please enter text in the box and try again.";
txtProduct.Text = "";
Hopefully this has all made sense. If not, let me know and I'll try to document it better.
If you have any problems with my code samples, please let me know. I've had to try and "re-simplify" them for this example.