public OrderTemplateTableCollection FetchAll()
 {
     OrderTemplateTableCollection coll = new OrderTemplateTableCollection();
     Query qry = new Query(OrderTemplateTable.Schema);
     coll.LoadAndCloseReader(qry.ExecuteReader());
     return coll;
 }
 public OrderTemplateTableCollection FetchByQuery(Query qry)
 {
     OrderTemplateTableCollection coll = new OrderTemplateTableCollection();
     coll.LoadAndCloseReader(qry.ExecuteReader()); 
     return coll;
 }
 public OrderTemplateTableCollection FetchByID(object OrderTemplateID)
 {
     OrderTemplateTableCollection coll = new OrderTemplateTableCollection().Where("OrderTemplateID", OrderTemplateID).Load();
     return coll;
 }
    protected void bind_formview(string mode)
    {
        string[] _key = { "OrderTemplateID" };
        OrderTemplateTableCollection _col = new OrderTemplateTableCollection();

        switch (mode){
            case "Insert":
                {
                    //blank template
                    OrderTemplateTable _template = new OrderTemplateTable();
                    _col.Add(_template);
                    break;
                }
            case "Edit":
                {
                    int _templateid = wwi_func.vint(wwi_security.DecryptString(get_token("pid"), "publiship"));
                    _col.Add(new OrderTemplateTable(_templateid));
                    break;
                }
            case "ReadOnly":
                {
                    //readonly check to see if an orderid has been passed as a param 'src'
                    //if it has populate template with data from selected order
                    int _orderid = wwi_func.vint(wwi_security.DecryptString(get_token("src"), "publiship"));
                    if (_orderid > 0)
                    {
                        //copy from order to template
                        OrderTable _order = new OrderTable(_orderid);
                        OrderTemplateTable _template = new OrderTemplateTable();
                        _template.PublishipOrder = _order.PublishipOrder;
                        _template.OfficeIndicator = _order.OfficeIndicator;
                        _template.CompanyID = _order.CompanyID;
                        _template.ConsigneeID = _order.ConsigneeID;
                        _template.NotifyPartyID = _order.NotifyPartyID;
                        _template.AgentAtOriginID = _order.AgentAtOriginID;
                        _template.AgentAtDestinationID = _order.AgentAtDestinationID;
                        _template.PrinterID = _order.PrinterID;
                        _template.ClearingAgentID = _order.ClearingAgentID;
                        _template.OnCarriageID = _order.OnCarriageID;
                        _template.OrderControllerID = _order.OrderControllerID;
                        _template.OperationsControllerID = _order.OperationsControllerID;
                        _template.OriginPortControllerID = _order.OriginPortControllerID;
                        _template.DestinationPortControllerID = _order.DestinationPortControllerID;
                        _template.CustomersRef = _order.CustomersRef;
                        _template.ContactID = _order.ContactID;
                        _template.OriginPointID = _order.OriginPointID;
                        _template.PortID = _order.PortID;
                        _template.DestinationPortID = _order.DestinationPortID;
                        _template.FinalDestinationID = _order.FinalDestinationID;
                        _template.CountryID = _order.CountryID;
                        _template.DestinationCountryID = _order.DestinationCountryID;
                        //add to collection
                        _col.Add(_template);
                    }
                    else
                    {
                        int _templateid = wwi_func.vint(wwi_security.DecryptString(get_token("pid"), "publiship"));
                        _col.Add(new OrderTemplateTable(_templateid));

                    }
                    break;
                }
            default:
                {
                    break;
                }
        }

        this.fmvTemplate.DataSource = _col;
        this.fmvTemplate.DataKeyNames = _key;
        this.fmvTemplate.DataBind(); 
    }