using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
namespace CIF.Modules.Northwind
{
public partial class OrdersGridDetailsView : System.Web.UI.UserControl
{
#region Private/Protected Members
protected bool m_bAllowEditInDetailsView = false;
protected ViewMode m_ViewMode = ViewMode.GridView;
protected enum ViewMode { Unknown, GridView, DetailsView }
private const string DATETIME_FORMAT = "MM/dd/yyyy";
#endregion
#region Public Properties
/// <summary>
/// Forces editing to occur in a detailsview control instead of the gridview
/// </summary>
public bool AllowEditInDetailsView
{
get
{
return m_bAllowEditInDetailsView;
}
set
{
m_bAllowEditInDetailsView = value;
}
}
/// <summary>
/// Allows sorting to be enabled in the gridview
/// </summary>
public bool AllowRecordSorting
{
get
{
return gvOrders.AllowSorting;
}
set
{
gvOrders.AllowSorting = value;
}
}
/// <summary>
/// Allows record selection in the gridview
/// </summary>
public bool AllowRecordSelection
{
get
{
return gvOrders.AutoGenerateSelectButton;
}
set
{
gvOrders.AutoGenerateSelectButton = value;
}
}
/// <summary>
/// Allows user to insert a record into the gridview/detailsview
/// </summary>
public bool AllowRecordInserting
{
get
{
return dvOrders.AutoGenerateInsertButton;
}
set
{
dvOrders.AutoGenerateInsertButton = value;
lbtnAddNewOrders.Visible = value;
}
}
/// <summary>
/// Allows user to update a record in the gridview/detailsview
/// </summary>
public bool AllowRecordEditing
{
get
{
return gvOrders.AutoGenerateEditButton;
}
set
{
gvOrders.AutoGenerateEditButton = value;
dvOrders.AutoGenerateEditButton = value;
}
}
/// <summary>
/// Allows user to delete a record in the gridview/detailsview
/// </summary>
public bool AllowRecordDeleting
{
get
{
return gvOrders.AutoGenerateDeleteButton;
}
set
{
gvOrders.AutoGenerateDeleteButton = value;
dvOrders.AutoGenerateDeleteButton = value;
}
}
#endregion
#region Public Functions
/// <summary>
/// Initialize the member variables and bind the gridview/detailsview
/// </summary>
public void Initialize()
{
AllowRecordSorting = true;
AllowRecordDeleting = true;
AllowRecordEditing = true;
AllowRecordInserting = true;
AllowRecordSelection = true;
AllowEditInDetailsView = true;
ClearDataViews();
BindDataViews();
ShowFooterInsertControls(false);
}
/// <summary>
/// Format a date-time field according to the predefined format
/// </summary>
/// <param name="dtvalue"></param>
public string FormatDateTime(object dtvalue)
{
string sDateTime = Convert.ToString(dtvalue);
if (MSCD.Utilities.Validation.IsDateTime(sDateTime) == true)
{
System.DateTime dt = System.DateTime.Parse(sDateTime);
if (dt == new DateTime(1900, 1, 1))
sDateTime = string.Empty;
else
sDateTime = dt.ToString(DATETIME_FORMAT);
}
return sDateTime;
}
#endregion
#region Private/Protected Properties
/// <summary>
/// Private variable for storing the latest sorted column expression
/// </summary>
private string SortExpression
{
get
{
if (ViewState["SortExpression"] != null)
return (string)ViewState["SortExpression"];
else
return string.Empty;
}
set
{
if (ViewState["SortExpression"] == null)
{
ViewState.Add("SortExpression", value);
}
else
{
ViewState["SortExpression"] = value;
}
}
}
/// <summary>
/// Private variable for storing the latest sorted column direction
/// </summary>
private string SortDirection
{
get
{
if (ViewState["SortDirection"] != null)
return (string)ViewState["SortDirection"];
else
return "ASC";
}
set
{
if (ViewState["SortDirection"] == null)
{
ViewState.Add("SortDirection", value);
}
else
{
ViewState["SortDirection"] = value;
}
}
}
#endregion
#region Private/Protected Functions
/// <summary>
/// Sets the new ViewMode for the control and updates the display accordingly
/// </summary>
/// <param name="vmNewViewMode"></param>
protected void SetBehavior(ViewMode vmNewViewMode)
{
m_ViewMode = vmNewViewMode;
SetBehavior();
}
/// <summary>
/// Handles the display of the gridview/detailsview controls according to the ViewMode
/// </summary>
protected void SetBehavior()
{
bool bHasGridRows = (gvOrders.Rows.Count > 0);
if ((bHasGridRows == false) && (AllowRecordInserting == true))
{
m_ViewMode = ViewMode.DetailsView;
}
switch (m_ViewMode)
{
case ViewMode.Unknown:
pnlGridView.Visible = bHasGridRows;
pnlDetailsView.Visible = !bHasGridRows;
break;
case ViewMode.GridView:
pnlGridView.Visible = true;
pnlDetailsView.Visible = false;
break;
case ViewMode.DetailsView:
pnlGridView.Visible = false;
pnlDetailsView.Visible = true;
break;
}
lbtnReturnToOrdersList.Visible = bHasGridRows;
}
/// <summary>
/// Clears out the binding of the old data
/// </summary>
protected void ClearDataViews()
{
gvOrders.DataSource = null;
gvOrders.DataBind();
dvOrders.DataSource = null;
dvOrders.DataBind();
}
/// <summary>
/// Binds the gridview/detailsview controls - this overload will display the records in a gridview
/// </summary>
protected void BindDataViews()
{
BindDataViews(0);
}
/// <summary>
/// Binds the gridview/detailsview controls - if primarykey is specified, the details view is used
/// </summary>
/// <param name="_OrderID"></param>
protected void BindDataViews(int _OrderID)
{
CIF.Business.Northwind.Orders _Orders = new CIF.Business.Northwind.Orders();
DataTable dtOrders = null;
if (_OrderID > 0)
{
dtOrders = _Orders.GetDataTable("OrderID", _OrderID.ToString());
dvOrders.DataSource = dtOrders;
dvOrders.DataBind();
SetBehavior(ViewMode.DetailsView);
}
else
{
dtOrders = _Orders.GetDataTable();
if (dtOrders.Rows.Count > 0)
{
DataView dv = dtOrders.DefaultView;
if ((SortExpression != string.Empty) && (SortDirection != string.Empty))
dv.Sort = SortExpression + " " + SortDirection;
gvOrders.DataSource = dv;
gvOrders.DataBind();
}
else
{
if (AllowRecordInserting == true)
{
dvOrders.DataSource = dtOrders;
dvOrders.DataBind();
}
else
{
gvOrders.DataSource = null;
gvOrders.DataBind();
}
}
SetBehavior();
}
}
/// <summary>
/// Display the insert/cancel controls appropriately according to the boolean
/// </summary>
/// <param name="bShowControls"></param>
protected void ShowFooterInsertControls(bool bShowControls)
{
lbtnInsertOrders.Visible = bShowControls;
lbtnCancelInsertOrders.Visible = bShowControls;
gvOrders.ShowFooter = bShowControls;
lbtnAddNewOrders.Visible = (bShowControls == false);
BindDataViews();
}
/// <summary>
/// Returns the primarykey value for the specified gridrow in the gridview
/// </summary>
/// <param name="row"></param>
/// <returns></returns>
private int GetGridViewRowOrderID(GridViewRow row)
{
int _OrderID = 0;
Label _ctl = (Label)row.FindControl("lblOrderID");
if (_ctl == null)
{
throw new Exception("GetOrderID: could not find OrderID control!");
}
_OrderID = Convert.ToInt32(_ctl.Text);
return _OrderID;
}
/// <summary>
/// Returns the string value for the specified textbox control in the specified gridrow in the gridview
/// </summary>
/// <param name="row"></param>
/// <param name="sControlName"></param>
/// <returns></returns>
private string GetGridViewRowTextValue(GridViewRow row, string sControlName)
{
string sFieldValue = string.Empty;
TextBox _ctl = (TextBox)row.FindControl(sControlName);
if (_ctl == null)
{
throw new Exception("GetGridViewRowTextValue: could not find " + sControlName + " control!");
}
sFieldValue = _ctl.Text.Trim();
return sFieldValue;
}
/// <summary>
/// Returns the bool value for the specified checkbox control in the specified gridrow in the gridview
/// </summary>
/// <param name="sControlName"></param>
/// <returns></returns>
private bool GetGridViewRowCheckBoxValue(GridViewRow row, string sControlName)
{
bool bFieldValue = false;
CheckBox _ctl = (CheckBox)row.FindControl(sControlName);
if (_ctl == null)
{
throw new Exception("GetGridViewRowCheckBoxValue: could not find " + sControlName + " control!");
}
bFieldValue = _ctl.Checked;
return bFieldValue;
}
/// <summary>
/// Returns the string value for the specified dropdownlist control in the specified gridrow in the gridview
/// </summary>
/// <param name="row"></param>
/// <param name="sControlName"></param>
/// <returns></returns>
private string GetGridViewRowDropDownListValue(GridViewRow row, string sControlName)
{
string sFieldValue = string.Empty;
DropDownList _ctl = (DropDownList)row.FindControl(sControlName);
if (_ctl == null)
{
throw new Exception("GetGridViewRowDropDownListValue: could not find " + sControlName + " control!");
}
sFieldValue = _ctl.SelectedValue;
return sFieldValue;
}
/// <summary>
/// Returns the primarykey value for the current record in the detailsview
/// </summary>
/// <returns></returns>
private int GetDetailsViewOrderID()
{
int _OrderID = 0;
Label _ctl = (Label)dvOrders.FindControl("lblOrderID");
if (_ctl == null)
{
throw new Exception("GetOrderID: could not find OrderID control!");
}
_OrderID = Convert.ToInt32(_ctl.Text);
return _OrderID;
}
/// <summary>
/// Returns the string value for the specified textbox control in the detailsview
/// </summary>
/// <param name="sControlName"></param>
/// <returns></returns>
private string GetTextFieldValue(string sControlName)
{
string sFieldValue = string.Empty;
TextBox _ctl = (TextBox)dvOrders.FindControl(sControlName);
if (_ctl == null)
{
throw new Exception("GetTextFieldValue: could not find " + sControlName + " control!");
}
sFieldValue = _ctl.Text.Trim();
return sFieldValue;
}
/// <summary>
/// Returns the bool value for the specified checkbox control in the detailsview
/// </summary>
/// <param name="sControlName"></param>
/// <returns></returns>
private bool GetCheckBoxFieldValue(string sControlName)
{
bool bFieldValue = false;
CheckBox _ctl = (CheckBox)dvOrders.FindControl(sControlName);
if (_ctl == null)
{
throw new Exception("GetCheckBoxFieldValue: could not find " + sControlName + " control!");
}
bFieldValue = _ctl.Checked;
return bFieldValue;
}
/// <summary>
/// Returns the string value for the specified textbox control in the DetailsView
/// </summary>
/// <param name="sControlName"></param>
/// <returns></returns>
private string GetDropDownListFieldValue(string sControlName)
{
string sFieldValue = string.Empty;
DropDownList _ctl = (DropDownList)dvOrders.FindControl(sControlName);
if (_ctl == null)
{
throw new Exception("GetDropDownListFieldValue: could not find " + sControlName + " control!");
}
sFieldValue = _ctl.SelectedValue;
return sFieldValue;
}
#endregion
#region General Control Event Handlers / Members
/// <summary>
/// Generic page-load event handler
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack == false)
{
}
}
/// <summary>
/// Switch the controls into insert-record mode
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void lbtnAddNewOrders_Click(object sender, EventArgs e)
{
if (m_bAllowEditInDetailsView == true)
{
dvOrders.ChangeMode(DetailsViewMode.Insert);
dvOrders.DataSource = null;
dvOrders.DataBind();
SetBehavior(ViewMode.DetailsView);
}
else
{
ShowFooterInsertControls(true);
}
}
/// <summary>
/// Insert a new record into the database table and exit out of insert mode
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void lbtnInsertOrders_Click(object sender, EventArgs e)
{
CIF.Business.Northwind.Orders _Orders = new CIF.Business.Northwind.Orders();
CIF.Business.Northwind.OrdersItem _OrdersItem = new CIF.Business.Northwind.OrdersItem();
GridViewRow gvrInsertRow = gvOrders.FooterRow;
_OrdersItem.CustomerID = (GetGridViewRowTextValue(gvrInsertRow, "txtInsertCustomerID") != string.Empty) ? GetGridViewRowTextValue(gvrInsertRow, "txtInsertCustomerID") : "HILAA";
_OrdersItem.EmployeeID = (GetGridViewRowTextValue(gvrInsertRow, "txtInsertEmployeeID") != string.Empty) ? Convert.ToInt32(GetGridViewRowTextValue(gvrInsertRow, "txtInsertEmployeeID")) : 1;
_OrdersItem.OrderDate = (GetGridViewRowTextValue(gvrInsertRow, "txtInsertOrderDate") != string.Empty) ? Convert.ToDateTime(GetGridViewRowTextValue(gvrInsertRow, "txtInsertOrderDate")) : System.DateTime.Now;
_OrdersItem.RequiredDate = (GetGridViewRowTextValue(gvrInsertRow, "txtInsertRequiredDate") != string.Empty) ? Convert.ToDateTime(GetGridViewRowTextValue(gvrInsertRow, "txtInsertRequiredDate")) : System.DateTime.Now;
_OrdersItem.ShippedDate = (GetGridViewRowTextValue(gvrInsertRow, "txtInsertShippedDate") != string.Empty) ? Convert.ToDateTime(GetGridViewRowTextValue(gvrInsertRow, "txtInsertShippedDate")) : System.DateTime.Now;
_OrdersItem.ShipVia = (GetGridViewRowTextValue(gvrInsertRow, "txtInsertShipVia") != string.Empty) ? Convert.ToInt32(GetGridViewRowTextValue(gvrInsertRow, "txtInsertShipVia")) : 1;
_OrdersItem.ShipName = GetGridViewRowTextValue(gvrInsertRow, "txtInsertShipName");
_OrdersItem.ShipAddress = GetGridViewRowTextValue(gvrInsertRow, "txtInsertShipAddress");
_OrdersItem.ShipCity = GetGridViewRowTextValue(gvrInsertRow, "txtInsertShipCity");
_OrdersItem.ShipRegion = GetGridViewRowTextValue(gvrInsertRow, "txtInsertShipRegion");
_OrdersItem.ShipPostalCode = GetGridViewRowTextValue(gvrInsertRow, "txtInsertShipPostalCode");
_OrdersItem.ShipCountry = GetGridViewRowTextValue(gvrInsertRow, "txtInsertShipCountry");
_OrdersItem.IsNew = true;
_Orders.OrdersItem = _OrdersItem;
_Orders.Save();
ShowFooterInsertControls(false);
}
/// <summary>
/// Exit out of insert mode
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void lbtnCancelInsertOrders_Click(object sender, EventArgs e)
{
ShowFooterInsertControls(false);
}
/// <summary>
/// Switch
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void lbtnReturnToOrdersList_Click(object sender, EventArgs e)
{
BindDataViews();
SetBehavior(ViewMode.GridView);
}
#endregion
#region GridView Event Handlers / Members
/// <summary>
/// Event that occurs when a data record is bound to a row in the gridview
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void gvOrders_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType != DataControlRowType.DataRow)
return;
// don't uncomment unless needed
//int _OrderID = GetGridViewRowOrderID(e.Row);
}
/// <summary>
/// Event that occurs when a command is issued from a row in the gridview
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void gvOrders_RowCommand(object sender, GridViewCommandEventArgs e)
{
// don't uncomment unless needed
//GridViewRow _row = (GridViewRow)((Control)e.CommandSource);
//int _OrderID = GetGridViewRowOrderID(_row);
/* // route and handle the command
switch (e.CommandName.ToUpper())
{
}
*/
}
/// <summary>
/// When gridview row is selected, displays the record in the detailsview; activates editing if allowed
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void gvOrders_SelectedIndexChanged(object sender, EventArgs e)
{
if (gvOrders.SelectedIndex < 0)
return;
dvOrders.ChangeMode(DetailsViewMode.ReadOnly);
int _OrderID = GetGridViewRowOrderID(gvOrders.SelectedRow);
BindDataViews(_OrderID);
}
/// <summary>
/// Updates gridview display when user changes to another page
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void gvOrders_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
gvOrders.PageIndex = e.NewPageIndex;
BindDataViews();
}
/// <summary>
/// Cancel the edits and rebind the gridview when user cancels out of edit mode
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void gvOrders_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
gvOrders.EditIndex = -1;
BindDataViews();
}
/// <summary>
/// Set the gridview row to edit and rebind the gridview into edit mode
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void gvOrders_RowEditing(object sender, GridViewEditEventArgs e)
{
gvOrders.EditIndex = e.NewEditIndex;
BindDataViews();
}
/// <summary>
/// Delete the record specified in the gridview and rebind
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void gvOrders_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
CIF.Business.Northwind.Orders _Orders = new CIF.Business.Northwind.Orders();
GridViewRow gvrEditRow = gvOrders.Rows[e.RowIndex];
int _OrderID = GetGridViewRowOrderID(gvrEditRow);
_Orders.Delete(_OrderID);
BindDataViews();
}
/// <summary>
/// Update the record according to the gridview's edit controls for the currently selected row
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void gvOrders_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
CIF.Business.Northwind.Orders _Orders = new CIF.Business.Northwind.Orders();
CIF.Business.Northwind.OrdersItem _OrdersItem = new CIF.Business.Northwind.OrdersItem();
GridViewRow gvrEditRow = gvOrders.Rows[e.RowIndex];
_OrdersItem.OrderID = GetGridViewRowOrderID(gvrEditRow);
_OrdersItem.CustomerID = (GetGridViewRowTextValue(gvrEditRow, "txtEditCustomerID") != string.Empty) ? GetGridViewRowTextValue(gvrEditRow, "txtEditCustomerID") : "HILAA";
_OrdersItem.EmployeeID = (GetGridViewRowTextValue(gvrEditRow, "txtEditEmployeeID") != string.Empty) ? Convert.ToInt32(GetGridViewRowTextValue(gvrEditRow, "txtEditEmployeeID")) : 1;
_OrdersItem.OrderDate = (GetGridViewRowTextValue(gvrEditRow, "txtEditOrderDate") != string.Empty) ? Convert.ToDateTime(GetGridViewRowTextValue(gvrEditRow, "txtEditOrderDate")) : System.DateTime.Now;
_OrdersItem.RequiredDate = (GetGridViewRowTextValue(gvrEditRow, "txtEditRequiredDate") != string.Empty) ? Convert.ToDateTime(GetGridViewRowTextValue(gvrEditRow, "txtEditRequiredDate")) : System.DateTime.Now;
_OrdersItem.ShippedDate = (GetGridViewRowTextValue(gvrEditRow, "txtEditShippedDate") != string.Empty) ? Convert.ToDateTime(GetGridViewRowTextValue(gvrEditRow, "txtEditShippedDate")) : System.DateTime.Now;
_OrdersItem.ShipVia = (GetGridViewRowTextValue(gvrEditRow, "txtEditShipVia") != string.Empty) ? Convert.ToInt32(GetGridViewRowTextValue(gvrEditRow, "txtEditShipVia")) : 1;
_OrdersItem.ShipName = GetGridViewRowTextValue(gvrEditRow, "txtEditShipName");
_OrdersItem.ShipAddress = GetGridViewRowTextValue(gvrEditRow, "txtEditShipAddress");
_OrdersItem.ShipCity = GetGridViewRowTextValue(gvrEditRow, "txtEditShipCity");
_OrdersItem.ShipRegion = GetGridViewRowTextValue(gvrEditRow, "txtEditShipRegion");
_OrdersItem.ShipPostalCode = GetGridViewRowTextValue(gvrEditRow, "txtEditShipPostalCode");
_OrdersItem.ShipCountry = GetGridViewRowTextValue(gvrEditRow, "txtEditShipCountry");
_OrdersItem.IsNew = false;
_Orders.OrdersItem = _OrdersItem;
_Orders.Save();
gvOrders.EditIndex = -1;
BindDataViews();
}
/// <summary>
/// Sort / rebind the gridview according to the column of the gridview that was click
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void gvOrders_Sorting(object sender, GridViewSortEventArgs e)
{
if (SortExpression != e.SortExpression)
{
SortExpression = e.SortExpression;
SortDirection = "ASC";
}
else
{
if (SortDirection == "ASC")
{
SortDirection = "DESC";
}
else
{
SortDirection = "ASC";
}
}
gvOrders.PageIndex = 0;
BindDataViews();
}
#endregion
#region DetailsView Event Handlers / Members
/// <summary>
/// Deletes the record currently in the detailsview
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void dvOrders_ItemDeleting(object sender, DetailsViewDeleteEventArgs e)
{
CIF.Business.Northwind.Orders _Orders = new CIF.Business.Northwind.Orders();
int _OrderID = GetDetailsViewOrderID();
_Orders.Delete(_OrderID);
BindDataViews();
SetBehavior(ViewMode.GridView);
}
/// <summary>
/// Inserts a new record based upon the values in the detailsview controls
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void dvOrders_ItemInserting(object sender, DetailsViewInsertEventArgs e)
{
CIF.Business.Northwind.Orders _Orders = new CIF.Business.Northwind.Orders();
CIF.Business.Northwind.OrdersItem _OrdersItem = new CIF.Business.Northwind.OrdersItem();
_OrdersItem.CustomerID = (GetTextFieldValue("txtInsertCustomerID") != string.Empty) ? GetTextFieldValue("txtInsertCustomerID") : "HILAA";
_OrdersItem.EmployeeID = (GetTextFieldValue("txtInsertEmployeeID") != string.Empty) ? Convert.ToInt32(GetTextFieldValue("txtInsertEmployeeID")) : 1;
_OrdersItem.OrderDate = (GetTextFieldValue("txtInsertOrderDate") != string.Empty) ? Convert.ToDateTime(GetTextFieldValue("txtInsertOrderDate")) : System.DateTime.Now;
_OrdersItem.RequiredDate = (GetTextFieldValue("txtInsertRequiredDate") != string.Empty) ? Convert.ToDateTime(GetTextFieldValue("txtInsertRequiredDate")) : System.DateTime.Now;
_OrdersItem.ShippedDate = (GetTextFieldValue("txtInsertShippedDate") != string.Empty) ? Convert.ToDateTime(GetTextFieldValue("txtInsertShippedDate")) : System.DateTime.Now;
_OrdersItem.ShipVia = (GetTextFieldValue("txtInsertShipVia") != string.Empty) ? Convert.ToInt32(GetTextFieldValue("txtInsertShipVia")) : 1;
_OrdersItem.ShipName = GetTextFieldValue("txtInsertShipName");
_OrdersItem.ShipAddress = GetTextFieldValue("txtInsertShipAddress");
_OrdersItem.ShipCity = GetTextFieldValue("txtInsertShipCity");
_OrdersItem.ShipRegion = GetTextFieldValue("txtInsertShipRegion");
_OrdersItem.ShipPostalCode = GetTextFieldValue("txtInsertShipPostalCode");
_OrdersItem.ShipCountry = GetTextFieldValue("txtInsertShipCountry");
_OrdersItem.IsNew = true;
_Orders.OrdersItem = _OrdersItem;
_Orders.Save();
BindDataViews();
SetBehavior(ViewMode.GridView);
}
/// <summary>
/// Updates an existing record based upon the values in the detailsview controls
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void dvOrders_ItemUpdating(object sender, DetailsViewUpdateEventArgs e)
{
CIF.Business.Northwind.Orders _Orders = new CIF.Business.Northwind.Orders();
CIF.Business.Northwind.OrdersItem _OrdersItem = new CIF.Business.Northwind.OrdersItem();
_OrdersItem.OrderID = GetDetailsViewOrderID();
_OrdersItem.CustomerID = (GetTextFieldValue("txtEditCustomerID") != string.Empty) ? GetTextFieldValue("txtEditCustomerID") : "HILAA";
_OrdersItem.EmployeeID = (GetTextFieldValue("txtEditEmployeeID") != string.Empty) ? Convert.ToInt32(GetTextFieldValue("txtEditEmployeeID")) : 1;
_OrdersItem.OrderDate = (GetTextFieldValue("txtEditOrderDate") != string.Empty) ? Convert.ToDateTime(GetTextFieldValue("txtEditOrderDate")) : System.DateTime.Now;
_OrdersItem.RequiredDate = (GetTextFieldValue("txtEditRequiredDate") != string.Empty) ? Convert.ToDateTime(GetTextFieldValue("txtEditRequiredDate")) : System.DateTime.Now;
_OrdersItem.ShippedDate = (GetTextFieldValue("txtEditShippedDate") != string.Empty) ? Convert.ToDateTime(GetTextFieldValue("txtEditShippedDate")) : System.DateTime.Now;
_OrdersItem.ShipVia = (GetTextFieldValue("txtEditShipVia") != string.Empty) ? Convert.ToInt32(GetTextFieldValue("txtEditShipVia")) : 1;
_OrdersItem.ShipName = GetTextFieldValue("txtEditShipName");
_OrdersItem.ShipAddress = GetTextFieldValue("txtEditShipAddress");
_OrdersItem.ShipCity = GetTextFieldValue("txtEditShipCity");
_OrdersItem.ShipRegion = GetTextFieldValue("txtEditShipRegion");
_OrdersItem.ShipPostalCode = GetTextFieldValue("txtEditShipPostalCode");
_OrdersItem.ShipCountry = GetTextFieldValue("txtEditShipCountry");
_OrdersItem.IsNew = false;
_Orders.OrdersItem = _OrdersItem;
_Orders.Save();
BindDataViews();
SetBehavior(ViewMode.GridView);
}
/// <summary>
/// Toggles the view and binding behavior when the detailsview mode changes
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void dvOrders_ModeChanging(object sender, DetailsViewModeEventArgs e)
{
if (e.CancelingEdit == false)
{
dvOrders.ChangeMode(e.NewMode);
int _OrderID = GetGridViewRowOrderID(gvOrders.SelectedRow);
BindDataViews(_OrderID);
}
else
{
SetBehavior(ViewMode.GridView);
}
}
/// <summary>
/// Databind event for the record being bound to the FormView control
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void dvOrders_DataBound(object sender, EventArgs e)
{
if (dvOrders.DataItem == null)
return;
}
#endregion
}
}