コード例 #1
0
ファイル: AnAccessory.aspx.cs プロジェクト: aneesafzall/temp
        private void DisplayAccessory()
        {
            clsAccessoryCollection MyAccessory = new clsAccessoryCollection();

            //find the record we want to display
            MyAccessory.ThisAccessory.Find(AccessroryID);
            txtName.Text        = MyAccessory.ThisAccessory.Name;
            txtDescription.Text = MyAccessory.ThisAccessory.Description;
            txtPrice.Text       = MyAccessory.ThisAccessory.Price.ToString();
            txtQuantity.Text    = MyAccessory.ThisAccessory.Quantity.ToString();
            txtType.Text        = MyAccessory.ThisAccessory.Type;
        }
コード例 #2
0
ファイル: AnAccessory.aspx.cs プロジェクト: aneesafzall/temp
        protected void btnSave_Click(object sender, EventArgs e)
        {
            //var to store any error messages
            string ErrorMsg;
            //create an instance of the address class
            clsAccessoryCollection Accessory = new clsAccessoryCollection();

            //use the objects validation method to test the data
            ErrorMsg = Accessory.ThisAccessory.Valid(txtDescription.Text, txtName.Text, txtPrice.Text, txtQuantity.Text, txtType.Text);
            //if there is no error message
            if (ErrorMsg == "")
            {
                //if we are adding a new record
                if (AccessroryID == -1)
                {
                    Accessory.ThisAccessory.Description = txtDescription.Text;

                    Accessory.ThisAccessory.Name = txtName.Text;

                    Accessory.ThisAccessory.Price = Convert.ToDouble(txtPrice.Text);

                    Accessory.ThisAccessory.Quantity = Convert.ToInt32(txtQuantity.Text);

                    Accessory.ThisAccessory.Type = txtType.Text;

                    Accessory.Add();
                }
                else//this is an existing record to update
                {
                    Accessory.ThisAccessory.Find(AccessroryID);

                    Accessory.ThisAccessory.Name = txtName.Text;

                    Accessory.ThisAccessory.Description = txtDescription.Text;

                    Accessory.ThisAccessory.Price = Convert.ToDouble(txtPrice.Text);

                    Accessory.ThisAccessory.Quantity = Convert.ToInt32(txtQuantity.Text);

                    Accessory.ThisAccessory.Type = txtType.Text;

                    Accessory.Update();
                }
                //all done so redirect back to the main page
                Response.Redirect("AccessorySearch.aspx");
            }
            else//there are errors
            {
                //display the error message
                lblError.Text = ErrorMsg;
            }
        }
コード例 #3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["method"] == "edit")
            {
                Int32 AccessoryID;

                AccessoryID = Convert.ToInt32(Request.QueryString["id"]);

                Session["AccessoryID"] = AccessoryID;

                Response.Redirect("AnAccessory.aspx");
            }
            else if (Request.QueryString["method"] == "del")
            {
                clsAccessoryCollection MyAccessory = new clsAccessoryCollection();
                //find the record to be deleted
                MyAccessory.ThisAccessory.Find(Convert.ToInt32(Request.QueryString["id"]));
                //call the delete method of the object
                MyAccessory.Delete();
                //redirect back to the main page
                Response.Redirect("AccessorySearch.aspx");
            }
            Response.Redirect("AccessorySearch.aspx");
        }
コード例 #4
0
        Int32 DisplayAccessories(string val, string searchBy)
        {
            ///this function accepts one parameter - the post code to filter the list on
            ///it populates the list box with data from the middle layer class
            ///it returns a single value, the number of records found

            //create a new instance of the clsAddress
            clsAccessoryCollection MyAccessoryList = new clsAccessoryCollection();
            //var to store the count of records
            Int32 RecordCount;

            string Name;

            string Description;

            double Price;

            int Quantity;

            string Type;
            //var to store the primary key value
            int AccessoryID;
            //var to store the index
            Int32 Index = 0;

            table.InnerHtml = "";

            string tableElement = @"<table>"
                                  + @"<tbody>
           
                   <tr >
           
                       <td > Accessory ID </ td >
               
                           <td > Name </ td >
                
                            <td> Description </ td >
                 
                             <td> Quantity </ td >
                  
                              <td> Price </ td >
                   
                                <td> Type </ td >
                                <td> </td>
                                <td> </td>
                            </tr >";

            //call the filter by post code method
            MyAccessoryList.FilterByName(val, searchBy);
            //get the count of records found
            RecordCount = MyAccessoryList.Count;
            //loop through each record found using the index to point to each record in the data table
            while (Index < RecordCount)
            {
                AccessoryID = Convert.ToInt32(MyAccessoryList.AccessoryList[Index].AccessoryID);

                Name = Convert.ToString(MyAccessoryList.AccessoryList[Index].Name);

                Description = Convert.ToString(MyAccessoryList.AccessoryList[Index].Description);

                Price = Convert.ToDouble(MyAccessoryList.AccessoryList[Index].Price);

                Quantity = Convert.ToInt32(MyAccessoryList.AccessoryList[Index].Quantity);

                Type = Convert.ToString(MyAccessoryList.AccessoryList[Index].Type);

                //   ListItem NewItem = new ListItem(AccessoryID+", "+ Name + "," + Description + ", " + Price + ", "+Quantity+", "+Type);
                tableElement += "<tr> <td>" + AccessoryID + "</td><td>" + Name + "</td> <td>" + Description + "</td> <td>" + Quantity + "</td> <td>" + Price + "</td><td>" + Type + @"</td> <td><a href=""Operation.aspx?id=" + AccessoryID + "&method=edit\"" + " class=\"btn btn-link\"> Edit </ td >";
                tableElement += "<td><a href=\"Operation.aspx?id=" + AccessoryID + "&method=del\"" + " class=\"btn btn-danger\"> Delete </ td > </tr>";
                //increment the index
                Index++;
            }
            tableElement += "</tbody></table>";

            table.InnerHtml = tableElement;
            //return the number of records found
            return(RecordCount);
        }