Hi, i looked into the samples in doing this but here are some issues,
A) my custom controls have dropdownboxes that populated on the page load of the control. However this method causes the Invalid attempt to call FieldCount when reader is closed error, when adding a new record. How do i correct this that i dont get that error and i get the control loaded with data as i invoke it
B) i noticed that when using the custom control way, the control would cover the grid even with the Edit Mode set to EditForms, is there a way it can behave like the autogenerated editforms?
Thanks!
A) my custom controls have dropdownboxes that populated on the page load of the control. However this method causes the Invalid attempt to call FieldCount when reader is closed error, when adding a new record. How do i correct this that i dont get that error and i get the control loaded with data as i invoke it
B) i noticed that when using the custom control way, the control would cover the grid even with the Edit Mode set to EditForms, is there a way it can behave like the autogenerated editforms?
Thanks!
1 Answer, 1 is accepted
0

Elliott
Top achievements
Rank 2
answered on 12 May 2011, 01:24 PM
Hi Steven
I use web controls for adding/editing a lot - to allow for entry of long character data (descriptions, company names, etc.)
I can't answer B) because I let it popup but never have encountered A) - could you include your code?
I've included a simple application
I use web controls for adding/editing a lot - to allow for entry of long character data (descriptions, company names, etc.)
I can't answer B) because I let it popup but never have encountered A) - could you include your code?
I've included a simple application
<%@ Control Language="VB" AutoEventWireup="false" CodeFile="Stores.ascx.vb" Inherits="Stores" %>
<
link
href
=
"Sandbox.css"
rel
=
"Stylesheet"
/>
<
table
border
=
"1"
cellpadding
=
"1"
cellspacing
=
"1"
class
=
"peachy_background"
width
=
"400px"
>
<
tr
>
<
td
class
=
"user_control_label"
>
<
asp:Label
ID
=
"lblAddUpdate"
Text
=
"Add Store"
runat
=
"server"
/>
</
td
>
<
td
>
<
asp:HiddenField
ID
=
"hdnStoreNumber"
runat
=
"server"
/>
</
td
>
</
tr
>
<
tr
>
<
td
class
=
"user_control_label"
>Store Number</
td
>
<
td
>
<
telerik:RadNumericTextBox
ID
=
"rntbStoreNumber"
MinValue
=
"1"
DataType
=
"System.Int64"
Text='<%# DataBinder.Eval( Container, "DataItem.StoreNumber" ) %>' CssClass="user_control_textbox" Width="100px" runat="server">
<
NumberFormat
DecimalDigits
=
"0"
GroupSeparator
=
""
/>
</
telerik:RadNumericTextBox
>
<
asp:RequiredFieldValidator
ID
=
"rfvStoreNumber"
ControlToValidate
=
"rntbStoreNumber"
ErrorMessage
=
"#"
CssClass
=
"red_for_error"
runat
=
"server"
/>
<
asp:CustomValidator
ID
=
"cvStoreNumber"
ControlToValidate
=
"rntbStoreNumber"
ErrorMessage
=
"*"
OnServerValidate
=
"cvStoreNumber_OnServerValidate"
CssClass
=
"red_for_error"
runat
=
"server"
/>
</
td
>
</
tr
>
<
tr
>
<
td
class
=
"user_control_label"
>Password</
td
>
<
td
class
=
"user_control_textbox"
>
<
telerik:RadTextBox
ID
=
"rtbPWD"
runat
=
"server"
>
</
telerik:RadTextBox
>
</
td
>
</
tr
>
<
tr
>
<
td
class
=
"user_control_label"
>Store Name</
td
>
<
td
class
=
"user_control_textbox"
>
<
telerik:RadTextBox
ID
=
"rtbStoreName"
Text='<%# DataBinder.Eval( Container, "DataItem.StoreName" ) %>' Width="200px" runat="server">
</
telerik:RadTextBox
>
</
td
>
</
tr
>
<
tr
>
<
td
class
=
"user_control_label"
>ChainID</
td
>
<
td
class
=
"user_control_textbox"
>
<
telerik:RadTextBox
ID
=
"rtbChainID"
Text='<%# DataBinder.Eval( Container, "DataItem.ChainID" ) %>' Width="200px" runat="server">
</
telerik:RadTextBox
>
</
td
>
</
tr
>
<
tr
>
<
td
class
=
"user_control_label"
>Consolidated</
td
>
<
td
class
=
"user_control_checkbox"
>
<
asp:CheckBox
ID
=
"chkConsolidateFlag"
Checked
=
"False"
runat
=
"server"
/>
</
td
>
</
tr
>
<
tr
>
<
td
class
=
"user_control_label"
>Full Service</
td
>
<
td
class
=
"user_control_checkbox"
>
<
asp:CheckBox
ID
=
"chkFullServ"
Checked
=
"False"
runat
=
"server"
/>
</
td
>
</
tr
>
<
tr
>
<
td
class
=
"user_control_label"
>Parent Store</
td
>
<
td
>
<
telerik:RadNumericTextBox
ID
=
"rntbParentStore"
DataType
=
"System.Int64"
Text='<%# DataBinder.Eval( Container, "DataItem.ParentStore" ) %>' CssClass="user_control_testbox" Width="100px" runat="server">
<
NumberFormat
DecimalDigits
=
"0"
GroupSeparator
=
""
/>
</
telerik:RadNumericTextBox
>
<
asp:CustomValidator
ID
=
"cvParentStore"
ControlToValidate
=
"rntbParentStore"
ErrorMessage
=
"*"
OnServerValidate
=
"cvParentStore_OnServerValidate"
CssClass
=
"red_for_error"
runat
=
"server"
/>
</
td
>
</
tr
>
<
tr
>
<
td
class
=
"user_control_label"
>BFD</
td
>
<
td
class
=
"user_control_checkbox"
>
<
asp:CheckBox
ID
=
"chkBFD"
Checked
=
"False"
runat
=
"server"
/>
</
td
>
</
tr
>
<
tr
>
<
td
colspan
=
"2"
>
<
asp:ValidationSummary
ID
=
"vsCustomer"
runat
=
"server"
/>
</
td
>
</
tr
>
<
tr
>
<
td
>
<
asp:Button
ID
=
"btnCancel"
Text
=
"Cancel"
CommandName
=
"Cancel"
CausesValidation
=
"False"
runat
=
"server"
/>
</
td
>
<
td
align
=
"right"
>
<
asp:Button
ID
=
"btnUpdate"
Text
=
"Update"
CommandName
=
"Update"
Visible='<%# Not (TypeOf DataItem Is Telerik.Web.UI.GridInsertionObject) %>' runat="server" />
<
asp:Button
ID
=
"btnInsert"
Text
=
"Insert"
CommandName
=
"PerformInsert"
Visible='<%# (TypeOf DataItem Is Telerik.Web.UI.GridInsertionObject) %>' runat="server" />
</
td
>
</
tr
>
</
table
>
Imports
Telerik.Web.UI
Imports
System.Data
Partial
Class
Stores
Inherits
System.Web.UI.UserControl
Private
blnInsertEdit
As
Boolean
=
True
Private
_dataItem
As
Object
Private
_validationPerformed
As
Nullable(Of
Boolean
)
Public
Property
DataItem()
As
Object
Get
Return
Me
._dataItem
End
Get
Set
(
ByVal
value
As
Object
)
Me
._dataItem = value
End
Set
End
Property
Protected
Sub
Page_DataBinding(
ByVal
sender
As
Object
,
ByVal
e
As
System.EventArgs)
Handles
Me
.DataBinding
Dim
dItem
As
Object
= DataItem
Dim
drView
As
DataRowView =
Nothing
Dim
blnConsolidateFlag, blnFullServ, blnBFD
As
Boolean
blnConsolidateFlag =
False
blnFullServ =
False
blnBFD =
False
If
TypeOf
dItem
Is
DataRowView
Then
blnInsertEdit =
False
drView =
DirectCast
(dItem, DataRowView)
blnConsolidateFlag = drView.Item(
"ConsolidateFlag"
)
chkConsolidateFlag.Checked = blnConsolidateFlag
blnFullServ = drView.Item(
"FullServ"
)
chkFullServ.Checked = blnFullServ
blnBFD = drView.Item(
"BFD"
)
chkBFD.Checked = blnBFD
rntbStoreNumber.
ReadOnly
=
True
End
If
If
TypeOf
dItem
Is
GridInsertionObject
Then
blnInsertEdit =
True
Else
lblAddUpdate.Text = lblAddUpdate.Text.Replace(
"Add"
,
"Update"
)
End
If
End
Sub
Protected
Sub
btnUpdate_Click(
ByVal
sender
As
Object
,
ByVal
e
As
System.EventArgs)
Handles
btnUpdate.Click
Dim
StoreNumber, ParentStore
As
Int64
Dim
StoreName, PWD, ChainID
As
String
Dim
ConsolidateFlag, FullServ, BFD
As
Boolean
Dim
ws
As
CommonFunctions
If
Page.IsValid
Then
Else
ValidationError.Display(
"Invalid fields marked with #"
)
Exit
Sub
End
If
StoreNumber = rntbStoreNumber.Value
StoreName = rtbStoreName.Text
PWD = rtbPWD.Text
ChainID = rtbChainID.Text
ConsolidateFlag = chkConsolidateFlag.Checked
FullServ = chkFullServ.Checked
ParentStore = rntbParentStore.Value
BFD = chkBFD.Checked
ws =
New
CommonFunctions
ws.UpdateStore(StoreNumber, StoreName, PWD, ChainID, ConsolidateFlag, _
FullServ, ParentStore, BFD)
ws =
Nothing
End
Sub
Protected
Sub
btnInsert_Click(
ByVal
sender
As
Object
,
ByVal
e
As
System.EventArgs)
Handles
btnInsert.Click
Dim
StoreNumber, ParentStore
As
Int64
Dim
StoreName, PWD, ChainID
As
String
Dim
ConsolidateFlag, FullServ, BFD
As
Boolean
Dim
ws
As
CommonFunctions
If
Page.IsValid
Then
Else
ValidationError.Display(
"Invalid fields marked with #"
)
Exit
Sub
End
If
StoreNumber = rntbStoreNumber.Value
StoreName = rtbStoreName.Text
PWD = rtbPWD.Text
ChainID = rtbChainID.Text
ConsolidateFlag = chkConsolidateFlag.Checked
FullServ = chkFullServ.Checked
ParentStore = rntbParentStore.Value
BFD = chkBFD.Checked
ws =
New
CommonFunctions
ws.InsertStore(StoreNumber, StoreName, PWD, ChainID, ConsolidateFlag, _
FullServ, ParentStore, BFD)
ws =
Nothing
End
Sub
Protected
Sub
cvStoreNumber_OnServerValidate(
ByVal
sender
As
Object
,
ByVal
e
As
ServerValidateEventArgs)
Dim
StoreNumber
As
Int64 = 0
Dim
blnIsValid
As
Boolean
Dim
ws
As
CommonFunctions =
Nothing
If
btnUpdate.Visible =
True
Then
Exit
Sub
End
If
If
_validationPerformed.HasValue
Then
e.IsValid = _validationPerformed
Exit
Sub
End
If
StoreNumber = rntbStoreNumber.Value
ws =
New
CommonFunctions
blnIsValid = ws.CheckStoreNumber(StoreNumber)
If
blnInsertEdit
AndAlso
blnIsValid
Then
ValidationError.Display(
"duplicate store number"
)
e.IsValid =
False
End
If
_validationPerformed = e.IsValid
End
Sub
Protected
Sub
cvParentStore_OnServerValidate(
ByVal
sender
As
Object
,
ByVal
e
As
ServerValidateEventArgs)
Dim
ParentStore
As
Int64 = 0
Dim
blnIsValid
As
Boolean
Dim
ws
As
CommonFunctions =
Nothing
If
_validationPerformed.HasValue
Then
e.IsValid = _validationPerformed
Exit
Sub
End
If
ParentStore = rntbParentStore.Value
If
ParentStore = 0
Then
blnIsValid =
True
Else
ws =
New
CommonFunctions
blnIsValid = ws.CheckParentStore(ParentStore)
End
If
If
blnIsValid
Then
Else
ValidationError.Display(
"invalid parent store"
)
e.IsValid =
False
End
If
_validationPerformed = e.IsValid
End
Sub
End
Class
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Stores.aspx.vb" Inherits="Stores" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<
html
xmlns
=
"http://www.w3.org/1999/xhtml"
>
<
head
runat
=
"server"
>
<
title
>Store Maintenance</
title
>
<
link
href
=
"Sandbox.css"
type
=
"text/css"
/>
</
head
>
<
body
>
<
telerik:RadCodeBlock
ID
=
"rcBlock"
runat
=
"server"
>
<
script
type
=
"text/javascript"
>
function ConfirmDelete() {
if (confirm("Are you sure you want to delete this Store?") == true)
return true;
else
return false;
}
</
script
>
</
telerik:RadCodeBlock
>
<
form
id
=
"frmStoreMaintenance"
method
=
"post"
runat
=
"server"
>
<
telerik:RadScriptManager
ID
=
"rsManager"
runat
=
"server"
/>
<
table
border
=
"0"
cellpadding
=
"2"
cellspacing
=
"2"
>
<
tr
>
<
td
> </
td
>
<
td
align
=
"right"
>
<
asp:Button
ID
=
"cmdPrint"
Text
=
"Print"
Visible
=
"false"
runat
=
"server"
/>
</
td
>
</
tr
>
<
tr
>
<
td
colspan
=
"2"
>
<
telerik:RadGrid
ID
=
"gvStores"
runat
=
"server"
>
<
GroupingSettings
CaseSensitive
=
"false"
/>
<
MasterTableView
DataKeyNames
=
"StoreNumber"
AutoGenerateColumns
=
"false"
AllowSorting
=
"true"
AllowPaging
=
"true"
AllowFilteringByColumn
=
"true"
CommandItemDisplay
=
"Top"
EditMode
=
"PopUp"
>
<
CommandItemSettings
AddNewRecordText
=
"Add A Store"
/>
<
Columns
>
<
telerik:GridBoundColumn
UniqueName
=
"StoreNumber"
DataField
=
"StoreNumber"
HeaderText
=
"StoreNumber"
ReadOnly
=
"true"
/>
<
telerik:GridBoundColumn
UniqueName
=
"PWD"
DataField
=
"PWD"
HeaderText
=
"Password"
ItemStyle-Width
=
"50"
AllowFiltering
=
"False"
/>
<
telerik:GridBoundColumn
UniqueName
=
"StoreName"
DataField
=
"StoreName"
HeaderText
=
"Store Name"
ItemStyle-Width
=
"320"
/>
<
telerik:GridBoundColumn
UniqueName
=
"ChainID"
DataField
=
"ChainID"
HeaderText
=
"ChainID"
ItemStyle-Width
=
"50"
/>
<
telerik:GridCheckBoxColumn
UniqueName
=
"ConsolidateFlag"
DataField
=
"ConsolidateFlag"
HeaderText
=
"Consolid"
ItemStyle-Width
=
"40"
/>
<
telerik:GridCheckBoxColumn
UniqueName
=
"FullServ"
DataField
=
"FullServ"
HeaderText
=
"Full Serv"
ItemStyle-Width
=
"40"
/>
<
telerik:GridBoundColumn
UniqueName
=
"ParentStore"
DataField
=
"ParentStore"
HeaderText
=
"Parent Store"
ItemStyle-Width
=
"50"
/>
<
telerik:GridCheckBoxColumn
UniqueName
=
"BFD"
DataField
=
"BFD"
HeaderText
=
"BFD"
ItemStyle-Width
=
"40"
/>
<
telerik:GridEditCommandColumn
EditText
=
"Edit"
/>
<
telerik:GridButtonColumn
UniqueName
=
"DeleteColumn"
CommandName
=
"Delete"
Text
=
"Delete"
/>
</
Columns
>
<
EditFormSettings
UserControlName
=
"Stores.ascx"
EditFormType
=
"WebUserControl"
>
</
EditFormSettings
>
</
MasterTableView
>
</
telerik:RadGrid
>
</
td
>
</
tr
>
</
table
>
</
form
>
</
body
>
</
html
>
Imports
Telerik.Web.UI
Imports
System.Data
Partial
Class
Stores
Inherits
System.Web.UI.Page
Protected
Sub
gvStores_NeedDataSource(
ByVal
source
As
Object
,
ByVal
e
As
Telerik.Web.UI.GridNeedDataSourceEventArgs)
Handles
gvStores.NeedDataSource
Dim
ds
As
DataSet =
Nothing
Dim
dt
As
DataTable =
Nothing
Dim
ws
As
New
CommonFunctions
ds = ws.GetStores
If
ds.Tables.Count > 0
Then
dt = ds.Tables(0)
End
If
gvStores.DataSource = dt
End
Sub
Protected
Sub
gvStores_ItemDataBound(
ByVal
source
As
Object
,
ByVal
e
As
Telerik.Web.UI.GridItemEventArgs)
Handles
gvStores.ItemDataBound
Dim
gdItem
As
GridDataItem =
Nothing
Dim
btnDelete
As
LinkButton =
Nothing
Dim
TableName
As
String
=
String
.Empty
TableName = e.Item.OwnerTableView.Name
If
TypeOf
e.Item
Is
GridDataItem
Then
gdItem =
DirectCast
(e.Item, GridDataItem)
btnDelete =
DirectCast
(gdItem.Cells(11).Controls(0), LinkButton)
If
btnDelete
Is
Nothing
Then
Else
btnDelete.Attributes.Add(
"onclick"
,
"return ConfirmDelete();"
)
End
If
End
If
End
Sub
Protected
Sub
gvStores_ItemCommand(
ByVal
source
As
Object
,
ByVal
e
As
Telerik.Web.UI.GridCommandEventArgs)
Handles
gvStores.ItemCommand
Dim
gdItem
As
GridDataItem =
Nothing
Dim
gefItem
As
GridEditFormItem =
Nothing
' Dim TableName As String = String.Empty
' TableName = e.Item.OwnerTableView.Name
' updates done in code-behind of user control
Select
Case
e.CommandName
Case
"PerformInsert"
' gdItem = DirectCast(e.Item, GridDataItem)
' InsertBooth(gdItem)
Case
"Edit"
' gdItem = DirectCast(e.Item, GridDataItem)
Case
"Update"
' gdItem = DirectCast(e.Item, GridDataItem)
' UpdateBooth(gdItem)
Case
"Delete"
gdItem =
DirectCast
(e.Item, GridDataItem)
DeleteStores(gdItem)
End
Select
End
Sub
Private
Sub
DeleteStores(
ByVal
gdItem
As
GridDataItem)
Dim
StoreNumber
As
Int64
Dim
ws
As
CommonFunctions
StoreNumber =
CInt
(gdItem.OwnerTableView.DataKeyValues(gdItem.ItemIndex)(
"StoreNumber"
))
ws =
New
CommonFunctions
ws.DeleteStore(StoreNumber)
End
Sub
Protected
Sub
cmdPrint_Click(
ByVal
sender
As
Object
,
ByVal
e
As
System.EventArgs)
Handles
cmdPrint.Click
' Response.Redirect("AllReports.aspx")
End
Sub
End
Class
Imports
Microsoft.VisualBasic
Public
Class
ValidationError
Implements
IValidator
Dim
m_IsValid
As
Boolean
Dim
m_ErrorMessage
As
String
Public
Sub
New
(
ByVal
message
As
String
)
m_ErrorMessage = message
m_IsValid =
False
End
Sub
Public
Property
ErrorMessage()
As
String
Implements
System.Web.UI.IValidator.ErrorMessage
Get
Return
m_ErrorMessage
End
Get
Set
(
ByVal
value
As
String
)
m_ErrorMessage = value
End
Set
End
Property
Public
Property
IsValid()
As
Boolean
Implements
System.Web.UI.IValidator.IsValid
Get
Return
m_IsValid
End
Get
Set
(
ByVal
value
As
Boolean
)
m_IsValid = value
End
Set
End
Property
Public
Sub
Validate()
Implements
System.Web.UI.IValidator.Validate
' no action required
End
Sub
Public
Shared
Sub
Display(
ByVal
message
As
String
)
Dim
currentPage
As
Page =
CType
(HttpContext.Current.Handler, Page)
currentPage.Validators.Add(
New
ValidationError(message))
End
Sub
End
Class
Imports
System.Data
Imports
System.Net.Mail
Imports
System.IO
Imports
System.Xml
Imports
System.Data.SqlClient
Imports
Microsoft.VisualBasic
Imports
System.Diagnostics
Imports
System.Reflection
Public
Class
CommonFunctions
' Use the below Connection for Production
Dim
strConn
As
String
=
"Data Source=00.111.44.22;Initial Catalog=orders_bozzutos_com;User ID=db_orders_bozzutos_com;password=5heBuxud"
' Dim ordersConn As String = "Data Source=localhost;Initial Catalog=korders_bozzutos_com;User ID=db_korders_bozzutos_com;password=brA4uchu"
' Use the below Connection for Development
' Dim strConn As String = "Data Source=(local);Initial Catalog=OrderSystem;User ID=sa;password=;"
''Dim strConn As String = "Data Source=WS920065A\SQL2005;Initial Catalog=OrderSystem;User ID=sa;password=d1g1tal;"
' Dim ordersConn As String = "Data Source=WS920065A\SQL2005;Initial Catalog=bozz_Brunswick;User ID=sa;password=d1g1tal;"
Const
ERROR_EMAILBOX
As
String
=
"consultant@client.com"
Const
HELPDESK
As
String
=
"helpdesk@clientapp.com"
Public
Sub
InsertStore(
ByVal
StoreNumber
As
Int64,
ByVal
StoreName
As
String
, _
ByVal
PWD
As
String
,
ByVal
ChainID
As
String
,
ByVal
ConsolidateFlag
As
Boolean
, _
ByVal
FullServ
As
Boolean
,
ByVal
ParentStore
As
Int64,
ByVal
BFD
As
Boolean
)
Dim
conn
As
SqlConnection =
Nothing
Dim
cmd
As
SqlCommand =
Nothing
Dim
paramStores
As
SqlParameter =
Nothing
conn =
New
SqlConnection(strConn)
cmd =
New
SqlCommand(
"insert_store"
, conn)
cmd.CommandType = CommandType.StoredProcedure
paramStores =
New
SqlParameter(
"@StoreNumber"
, SqlDbType.BigInt)
paramStores.Value = StoreNumber
cmd.Parameters.Add(paramStores)
paramStores =
New
SqlParameter(
"@StoreName"
, SqlDbType.VarChar, 50)
paramStores.Value = StoreName
cmd.Parameters.Add(paramStores)
paramStores =
New
SqlParameter(
"@PWD"
, SqlDbType.VarChar, 30)
paramStores.Value = PWD
cmd.Parameters.Add(paramStores)
paramStores =
New
SqlParameter(
"@ChainID"
, SqlDbType.VarChar, 50)
paramStores.Value = ChainID
cmd.Parameters.Add(paramStores)
paramStores =
New
SqlParameter(
"@ConsolidateFlag"
, SqlDbType.Int)
paramStores.Value = IIf(ConsolidateFlag, 1, 0)
cmd.Parameters.Add(paramStores)
paramStores =
New
SqlParameter(
"@FullServ"
, SqlDbType.Int)
paramStores.Value = IIf(FullServ, 1, 0)
cmd.Parameters.Add(paramStores)
paramStores =
New
SqlParameter(
"@ParentStore"
, SqlDbType.BigInt)
paramStores.Value = ParentStore
cmd.Parameters.Add(paramStores)
paramStores =
New
SqlParameter(
"@BFD"
, SqlDbType.Int)
paramStores.Value = IIf(BFD, 1, 0)
cmd.Parameters.Add(paramStores)
Try
conn.Open()
cmd.ExecuteNonQuery()
Catch
ex
As
Exception
SendErrorEmail(ex.Message)
Finally
conn.Close()
cmd =
Nothing
conn =
Nothing
End
Try
End
Sub
Public
Sub
DeleteStore(
ByVal
StoreNumber
As
Int64)
Dim
conn
As
SqlConnection =
Nothing
Dim
cmd
As
SqlCommand =
Nothing
Dim
paramStores
As
SqlParameter =
Nothing
conn =
New
SqlConnection(strConn)
cmd =
New
SqlCommand(
"delete_store"
, conn)
cmd.CommandType = CommandType.StoredProcedure
paramStores =
New
SqlParameter(
"@StoreNumber"
, SqlDbType.BigInt)
paramStores.Value = StoreNumber
cmd.Parameters.Add(paramStores)
Try
conn.Open()
cmd.ExecuteNonQuery()
Catch
ex
As
Exception
SendErrorEmail(ex.Message)
Finally
conn.Close()
cmd =
Nothing
conn =
Nothing
End
Try
End
Sub
Public
Sub
UpdateStore(
ByVal
StoreNumber
As
Int64,
ByVal
StoreName
As
String
, _
ByVal
PWD
As
String
,
ByVal
ChainID
As
String
,
ByVal
ConsolidateFlag
As
Boolean
, _
ByVal
FullServ
As
Boolean
,
ByVal
ParentStore
As
Int64,
ByVal
BFD
As
Boolean
)
Dim
conn
As
SqlConnection =
Nothing
Dim
cmd
As
SqlCommand =
Nothing
Dim
paramStores
As
SqlParameter =
Nothing
conn =
New
SqlConnection(strConn)
cmd =
New
SqlCommand(
"update_store"
, conn)
cmd.CommandType = CommandType.StoredProcedure
paramStores =
New
SqlParameter(
"@StoreNumber"
, SqlDbType.BigInt)
paramStores.Value = StoreNumber
cmd.Parameters.Add(paramStores)
paramStores =
New
SqlParameter(
"@StoreName"
, SqlDbType.VarChar, 50)
paramStores.Value = StoreName
cmd.Parameters.Add(paramStores)
paramStores =
New
SqlParameter(
"@PWD"
, SqlDbType.VarChar, 30)
paramStores.Value = PWD
cmd.Parameters.Add(paramStores)
paramStores =
New
SqlParameter(
"@ChainID"
, SqlDbType.VarChar, 50)
paramStores.Value = ChainID
cmd.Parameters.Add(paramStores)
paramStores =
New
SqlParameter(
"@ConsolidateFlag"
, SqlDbType.Int)
paramStores.Value = IIf(ConsolidateFlag, 1, 0)
cmd.Parameters.Add(paramStores)
paramStores =
New
SqlParameter(
"@FullServ"
, SqlDbType.Int)
paramStores.Value = IIf(FullServ, 1, 0)
cmd.Parameters.Add(paramStores)
paramStores =
New
SqlParameter(
"@ParentStore"
, SqlDbType.BigInt)
paramStores.Value = ParentStore
cmd.Parameters.Add(paramStores)
paramStores =
New
SqlParameter(
"@BFD"
, SqlDbType.Int)
paramStores.Value = IIf(BFD, 1, 0)
cmd.Parameters.Add(paramStores)
Try
conn.Open()
cmd.ExecuteNonQuery()
Catch
ex
As
Exception
SendErrorEmail(ex.Message)
Finally
conn.Close()
cmd =
Nothing
conn =
Nothing
End
Try
End
Sub
Public
Function
CheckStoreNumber(
ByVal
StoreNumber
As
Int64)
As
Boolean
Dim
blnIsValid
As
Boolean
=
False
Dim
conn
As
SqlConnection =
Nothing
Dim
cmd
As
SqlCommand =
Nothing
Dim
paramStores
As
SqlParameter
conn =
New
SqlConnection(strConn)
cmd =
New
SqlCommand(
"check_store_number"
, conn)
cmd.CommandType = CommandType.StoredProcedure
paramStores =
New
SqlParameter(
"@StoreNumber"
, SqlDbType.BigInt)
paramStores.Value = StoreNumber
cmd.Parameters.Add(paramStores)
Try
conn.Open()
blnIsValid = cmd.ExecuteScalar()
Catch
ex
As
Exception
SendErrorEmail(ex.Message)
Finally
conn.Close()
cmd =
Nothing
conn =
Nothing
End
Try
Return
blnIsValid
End
Function
Public
Function
CheckParentStore(
ByVal
ParentStore
As
Int64)
As
Boolean
Dim
blnIsValid
As
Boolean
=
False
Dim
conn
As
SqlConnection =
Nothing
Dim
cmd
As
SqlCommand =
Nothing
Dim
paramStores
As
SqlParameter
conn =
New
SqlConnection(strConn)
cmd =
New
SqlCommand(
"check_parent_store"
, conn)
cmd.CommandType = CommandType.StoredProcedure
paramStores =
New
SqlParameter(
"@ParentStore"
, SqlDbType.BigInt)
paramStores.Value = ParentStore
cmd.Parameters.Add(paramStores)
Try
conn.Open()
blnIsValid = cmd.ExecuteScalar()
Catch
ex
As
Exception
SendErrorEmail(ex.Message)
Finally
conn.Close()
cmd =
Nothing
conn =
Nothing
End
Try
Return
blnIsValid
End
Function
Public
Function
GetStores()
As
DataSet
Dim
ds
As
DataSet =
Nothing
Dim
conn
As
SqlConnection =
Nothing
Dim
da
As
SqlDataAdapter =
Nothing
conn =
New
SqlConnection(strConn)
da =
New
SqlDataAdapter(
"get_stores"
, conn)
ds =
New
DataSet
' Try
da.Fill(ds,
"Stores"
)
' Catch ex As Exception
' SendErrorEmail(ex.Message)
' End Try
Return
ds
End
Function
Public
Sub
SendErrorEmail(
ByVal
strBody
As
String
)
Dim
mailClient
As
SmtpClient =
New
SmtpClient
Dim
messEmail
As
System.Net.Mail.MailMessage =
Nothing
Dim
strFromEmail, strToEmail
As
String
Dim
sTrace
As
StackTrace
Dim
sFrame
As
StackFrame
Dim
mBase
As
MethodBase
Dim
sb
As
StringBuilder =
Nothing
'Use the below Mail Server for Production
Dim
mailServerName
As
String
=
"localhost"
'Use the below Mail Server for Development
' Dim mailServerName As String = "pofficeb.bozznet.com"
strFromEmail = HELPDESK
strToEmail = ERROR_EMAILBOX
sTrace =
New
StackTrace()
sFrame = sTrace.GetFrame(1)
mBase = sFrame.GetMethod()
sb =
New
StringBuilder(
"Error in "
)
sb.Append(mBase.Name)
messEmail =
New
System.Net.Mail.MailMessage(strFromEmail, strToEmail, sb.ToString, strBody)
Try
mailClient.Host = mailServerName
mailClient.Send(messEmail)
InsertDelay(50000)
messEmail.Dispose()
Catch
ex
As
Exception
End
Try
End
Sub
Private
Sub
InsertDelay(
ByVal
iDelay
As
Integer
)
Dim
iLoop
As
Integer
For
iLoop = 1
To
iDelay
Next
End
Sub
End
Class