/// <summary>
 /// Create a new Stationery object.
 /// </summary>
 /// <param name="id">Initial value of the id property.</param>
 /// <param name="code">Initial value of the code property.</param>
 /// <param name="stationery_name">Initial value of the stationery_name property.</param>
 /// <param name="category">Initial value of the category property.</param>
 /// <param name="price">Initial value of the price property.</param>
 /// <param name="reorder_level">Initial value of the reorder_level property.</param>
 /// <param name="reorder_quantity">Initial value of the reorder_quantity property.</param>
 /// <param name="quantity_in_stock">Initial value of the quantity_in_stock property.</param>
 /// <param name="pending_quantity_to_distribute">Initial value of the pending_quantity_to_distribute property.</param>
 /// <param name="unit_of_measure">Initial value of the unit_of_measure property.</param>
 public static Stationery CreateStationery(global::System.Int32 id, global::System.String code, global::System.String stationery_name, global::System.Int32 category, global::System.Double price, global::System.Int32 reorder_level, global::System.Int32 reorder_quantity, global::System.Int32 quantity_in_stock, global::System.Int32 pending_quantity_to_distribute, global::System.String unit_of_measure)
 {
     Stationery stationery = new Stationery();
     stationery.id = id;
     stationery.code = code;
     stationery.stationery_name = stationery_name;
     stationery.category = category;
     stationery.price = price;
     stationery.reorder_level = reorder_level;
     stationery.reorder_quantity = reorder_quantity;
     stationery.quantity_in_stock = quantity_in_stock;
     stationery.pending_quantity_to_distribute = pending_quantity_to_distribute;
     stationery.unit_of_measure = unit_of_measure;
     return stationery;
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the Stationeries EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToStationeries(Stationery stationery)
 {
     base.AddObject("Stationeries", stationery);
 }
        protected void ui_save_button_Click(object sender, EventArgs e)
        {
            StationeryController sationeryController = new StationeryController();

            Stationery stationery = new Stationery();
            int stationery_id;

            //getting hidden field id
            if (int.TryParse(ui_id_hiddenfield.Value, out stationery_id))
            {
                stationery.id = Convert.ToInt32(ui_id_hiddenfield.Value);
                stationery = sationeryController.actionGetStationeryByID(stationery.id);
            }

            //fields validation
            if (String.IsNullOrEmpty(ui_code_textbox.Text) ||
                String.IsNullOrEmpty(ui_name_textbox.Text) ||
                String.IsNullOrEmpty(ui_reorderlevel_textbox.Text) ||
                String.IsNullOrEmpty(ui_reorderquantity_textbox.Text) ||
                String.IsNullOrEmpty(ui_uom_textbox.Text) ||
                String.IsNullOrEmpty(ui_price_textbox.Text)
                )
            {
                Response.Cookies.Add(new HttpCookie("flash_message", "Field(s) marked with * can't be empty.") { Path = "/" });
                Response.Cookies.Add(new HttpCookie("flash_css", "alert alert-error") { Path = "/" });
                return;
                //String idstring = (supplier.id > 0) ? ("?id="+supplier.id) : ("");
                //Response.Redirect("~/StoreClerk/SupplierDetail.aspx"+idstring);
            }

            try
            {
                stationery.reorder_level = Convert.ToInt32(ui_reorderlevel_textbox.Text);
                stationery.reorder_quantity = Convert.ToInt32(ui_reorderquantity_textbox.Text);
                stationery.price = Convert.ToDouble(ui_price_textbox.Text);
            }
            catch (Exception ex)
            {
                Response.Cookies.Add(new HttpCookie("flash_message", "Price Reorder Level and Reorder Quantity only allow numbers." ) { Path = "/" });
                Response.Cookies.Add(new HttpCookie("flash_css", "alert alert-error") { Path = "/" });
                return;
            }

            //setting up object
            //setting up object
            stationery.code = ui_code_textbox.Text;
            stationery.stationery_name = ui_name_textbox.Text;
            stationery.category = Convert.ToInt32(ui_category_dropdown.SelectedValue);
            stationery.reorder_level = Convert.ToInt32(ui_reorderlevel_textbox.Text);
            stationery.reorder_quantity = Convert.ToInt32(ui_reorderquantity_textbox.Text);
            stationery.unit_of_measure = ui_uom_textbox.Text;
            stationery.bin = ui_binnum_textbox.Text;

            //stationery.quantity_in_stock = Convert.ToInt32(ui_quantityinstock_label.Text);
            //stationery.pending_quantity_to_distribute = Convert.ToInt32(ui_pendingquantity_label.Text);

            if (Page.IsPostBack) {

            }

            stationery.first_supplier = Convert.ToInt32(ui_firstsupplier_dropdown.SelectedItem.Value);
            stationery.second_supplier = Convert.ToInt32(ui_secondsupplier_dropdown.SelectedItem.Value);
            stationery.third_supplier = Convert.ToInt32(ui_thirdsupplier_dropdown.SelectedItem.Value);

            //stationery.first_supplier = 5;
            //stationery.second_supplier = 4;
            //stationery.third_supplier = 1;

            //updating db;
            Message message;
            if (stationery.id > 0)
            {
                message = sationeryController.actionUpdateStationery(stationery);
            }
            else
            {
                stationery.quantity_in_stock = 0;
                stationery.pending_quantity_to_distribute = 0;
                message = sationeryController.actionCreateStationery(stationery);
            }

            //redirecting
            if (message.condition)
            {
                Response.Cookies.Add(new HttpCookie("flash_message", "Successfully Saved.") { Path = "/" });
                Response.Cookies.Add(new HttpCookie("flash_css", "alert alert-success") { Path = "/" });
                Response.Redirect("~/StoreClerk/StatoneryDetail.aspx?id=" + stationery.id);
            }
            else
            {
                Response.Cookies.Add(new HttpCookie("flash_message", message.message) { Path = "/" });
                Response.Cookies.Add(new HttpCookie("flash_css", "alert alert-error") { Path = "/" });
                Response.Redirect("~/StoreClerk/StatoneryDetail.aspx?id=" + stationery.id);
            }
        }