00001: Imports Microsoft.VisualBasic
00002: 
00003: 'Этот класс - коллекция типа ArrayList из элементов WorkingTovar - которую отобрал юзер в корзину
00004: 'Каждый элемент этой коллекции хранит Датасет с данными, вычитанными из SQL-сервера и ряд дополнительных признаков
00005: 'На эту коллекцию напрямую можно сделать привязку GridView (как на ObjectDataSource)
00006: Public Class WorkingTovarList
00007:     Inherits System.Collections.Generic.List(Of WorkingTovar)
00008: 
00009:     'добавление товара на рабочий стол без дублирования
00010:     Public Sub TovarAdd(ByVal NewTovarName As String, ByVal NewTovarValue As String, ByVal NewTovarValuePath As String)
00011:         Dim One As New WorkingTovar, Saved As WorkingTovar
00012:         One.TovarName = NewTovarName
00013:         One.TovarValue = NewTovarValue
00014:         One.TovarValuePath = NewTovarValuePath
00015:         For Each Saved In Me
00016:             If Saved.TovarName = NewTovarName And Saved.TovarValue = NewTovarValue Then Exit Sub
00017:         Next
00018:         Me.Add(One)
00019:     End Sub
00020: 
00021:     'Запрошено удаление - только отметка
00022:     Public Sub TovarDel(ByVal TovarValue As String)
00023:         Dim One As WorkingTovar
00024:         For Each One In Me
00025:             If One.TovarValue = TovarValue Then
00026:                 One.chTovarDelete = True
00027:                 Exit Sub
00028:             End If
00029:         Next
00030:     End Sub
00031: 
00032:     'Запрошена подробная информация
00033:     Public Sub TovarDet(ByVal TovarValue As String)
00034:         Dim One As WorkingTovar
00035:         For Each One In Me
00036:             If One.TovarValue = TovarValue Then
00037:                 One.chTovarDetails = True
00038:                 Exit Sub
00039:             End If
00040:         Next
00041:     End Sub
00042: 
00043:     'очистка всех отмеченных к удалению товаров
00044:     Public Sub TovarClear()
00045:         Dim One As WorkingTovar
00046:         While True
00047:             For Each One In Me
00048:                 If One.chTovarDelete Then
00049:                     One.chTovarDetails = True
00050:                     Me.Remove(One)
00051:                     GoTo NextOne
00052:                 End If
00053:             Next
00054:             Exit Sub 'удалять больше нечего
00055: NextOne:
00056:         End While
00057:     End Sub
00058: 
00059:     'пока так не требуется
00060:     Public Event TovarDeleted(ByVal TovarValue As String)
00061:     'товар удален
00062:     Public Sub TovarDelete(ByVal TovarValue As String)
00063:         Dim One As WorkingTovar
00064:         For Each One In Me
00065:             If One.TovarValue = TovarValue Then
00066:                 One.chTovarDelete = True
00067:                 Me.Remove(One)
00068:                 RaiseEvent TovarDeleted(TovarValue)
00069:                 Exit Sub
00070:             End If
00071:         Next
00072:     End Sub
00073: 
00074:     'вообще-то корректное конструирование XML делается методами XmlTextWriter
00075:     Public Function ToXMLstring() As String
00076:         Dim OneNode As WorkingTovar
00077:         For Each OneNode In Me
00078:             ToXMLstring &= " <WorkNodes TovarValue=""" & OneNode.TovarValue & """ "
00079:             ToXMLstring &= " Delete=""" & OneNode.chTovarDelete & """ "
00080:             ToXMLstring &= " Details=""" & OneNode.chTovarDetails & """ "
00081:             ToXMLstring &= " />"
00082:         Next
00083:     End Function
00084: 
00085: End Class
00086: 
00087: 'этот класс элементарный фрагмент
00088: Public Class WorkingTovar
00089:     Private SaveTovarName As String
00090:     Private SaveTovarValue As String
00091:     Private SaveTovarValuePath As String
00092:     Private SaveTovarDelete As Boolean = False
00093:     Private SaveTovarDetails As Boolean = False
00094:     Private SaveTovarKorsina As Boolean = False
00095:     Private SaveTovarForum As Boolean = False
00096:     Private SaveTovarDriver As Boolean = False
00097:     Private SaveTovarSkidka As Boolean = False
00098:     Private HaveData As Boolean = False
00099:     Private KolZakaz As Integer = 1
00100:     Private CostR As Decimal
00101:     Private CostU As Decimal
00102:     Private PricePos As Integer
00103: 
00104: 
00105:     Private DS As New MyPriceDS
00106:     Private MyPriceTA As New MyPriceDSTableAdapters.MyPriceTableAdapter
00107:     Private MyBlockTA As New MyPriceDSTableAdapters.MyBlockTableAdapter
00108:     Private MyBlockListTA As New MyPriceDSTableAdapters.MyBlockListTableAdapter
00109:     Private MyValueTA As New MyPriceDSTableAdapters.MyValueTableAdapter
00110:     Private MyValueListTA As New MyPriceDSTableAdapters.MyValueListTableAdapter
00111:     Private MyFieldTA As New MyPriceDSTableAdapters.MyFieldsTableAdapter
00112:     Private MyFieldListTA As New MyPriceDSTableAdapters.MyFieldsListTableAdapter
00113: 
00114:     Public ReadOnly Property PriceDS() As MyPriceDS
00115:         Get
00116:             PriceDS = DS
00117:         End Get
00118:     End Property
00119: 
00120:     Public Sub New()
00121:         MyPriceTA.ClearBeforeFill = False
00122:         MyBlockTA.ClearBeforeFill = False
00123:         MyBlockListTA.ClearBeforeFill = False
00124:         MyValueTA.ClearBeforeFill = False
00125:         MyValueListTA.ClearBeforeFill = False
00126:         MyFieldTA.ClearBeforeFill = False
00127:         MyFieldListTA.ClearBeforeFill = False
00128:     End Sub
00129: 
00130:     Public Property TovarName() As String
00131:         Get
00132:             TovarName = SaveTovarName
00133:         End Get
00134:         Set(ByVal value As String)
00135:             SaveTovarName = value
00136:         End Set
00137:     End Property
00138:     Public Property TovarValue() As String
00139:         Get
00140:             TovarValue = SaveTovarValue
00141:         End Get
00142:         Set(ByVal value As String)
00143:             SaveTovarValue = value
00144:         End Set
00145:     End Property
00146:     Public Property TovarValuePath() As String
00147:         Get
00148:             TovarValuePath = SaveTovarValuePath
00149:         End Get
00150:         Set(ByVal value As String)
00151:             SaveTovarValuePath = value
00152:         End Set
00153:     End Property
00154:     Public Property chTovarDelete() As Boolean
00155:         Get
00156:             chTovarDelete = SaveTovarDelete
00157:         End Get
00158:         Set(ByVal value As Boolean)
00159:             SaveTovarDelete = value
00160:         End Set
00161:     End Property
00162:     Public Property chTovarDetails() As Boolean
00163:         Get
00164:             chTovarDetails = SaveTovarDetails
00165:         End Get
00166:         Set(ByVal value As Boolean)
00167:             SaveTovarDetails = value
00168:         End Set
00169:     End Property
00170:     Public Property chTovarKorsina() As Boolean
00171:         Get
00172:             chTovarKorsina = SaveTovarKorsina
00173:         End Get
00174:         Set(ByVal value As Boolean)
00175:             SaveTovarKorsina = value
00176:         End Set
00177:     End Property
00178:     Public Property chTovarForum() As Boolean
00179:         Get
00180:             chTovarForum = SaveTovarForum
00181:         End Get
00182:         Set(ByVal value As Boolean)
00183:             SaveTovarForum = value
00184:         End Set
00185:     End Property
00186:     Public Property chTovarDriver() As Boolean
00187:         Get
00188:             chTovarDriver = SaveTovarDriver
00189:         End Get
00190:         Set(ByVal value As Boolean)
00191:             SaveTovarDriver = value
00192:         End Set
00193:     End Property
00194:     Public Property chTovarSkidka() As Boolean
00195:         Get
00196:             chTovarSkidka = SaveTovarSkidka
00197:         End Get
00198:         Set(ByVal value As Boolean)
00199:             SaveTovarSkidka = value
00200:         End Set
00201:     End Property
00202:     Public ReadOnly Property IsHaveData() As Boolean
00203:         Get
00204:             IsHaveData = HaveData
00205:         End Get
00206:     End Property
00207:     Public ReadOnly Property UsdCost() As Decimal
00208:         Get
00209:             UsdCost = CostU
00210:         End Get
00211:     End Property
00212:     Public ReadOnly Property PricePosition() As Integer
00213:         Get
00214:             PricePosition = PricePos
00215:         End Get
00216:     End Property
00217:     Public Property Kol() As Integer
00218:         Get
00219:             Kol = KolZakaz
00220:         End Get
00221:         Set(ByVal value As Integer)
00222:             KolZakaz = value
00223:         End Set
00224:     End Property
00225:     Public Property RubCost() As Decimal
00226:         Get
00227:             RubCost = CostR
00228:         End Get
00229:         Set(ByVal value As Decimal)
00230:             CostR = value
00231:         End Set
00232:     End Property
00233: 
00234: 
00235:     'считываем все для этого текущего элемента коллекции из SQL в DS
00236:     Public Sub ReadFromSQL()
00237:         Dim A() As String
00238:         A = Me.TovarValue.Split(CChar("="))
00239:         PricePos = CType(A(1), Integer)
00240:         Call Common.ErrorMessage("ReadFromSQL", CStr(PricePos))
00241:         With DS
00242:             .Clear()
00243:             MyPriceTA.Fill(._MyPrice, PricePos)
00244:             CostU = CDec(._MyPrice.Rows(0).Item("MyCost"))
00245:             MyValueListTA.Fill(.MyValueList, ._MyPrice(._MyPrice.Rows.Count - 1).i)
00246:             MyFieldListTA.Fill(.MyFieldsList, ._MyPrice(._MyPrice.Rows.Count - 1).i)
00247:             MyBlockListTA.Fill(.MyBlockList, ._MyPrice(._MyPrice.Rows.Count - 1).i)
00248:             For j As Integer = 0 To .MyBlockList.Count - 1
00249:                 Dim iToBlock As Integer = .MyBlockList(j).ToBlock
00250:                 For k As Integer = 0 To .MyBlock.Count - 1
00251:                     If .MyBlock(k).i = iToBlock Then GoTo NotFill_MyBlock
00252:                 Next
00253:                 MyBlockTA.Fill(.MyBlock, iToBlock)
00254: NotFill_MyBlock:
00255:             Next
00256:             For l As Integer = 0 To .MyFieldsList.Count - 1
00257:                 Dim iToFields As Integer = .MyFieldsList(l).ToFields
00258:                 For m As Integer = 0 To .MyFields.Count - 1
00259:                     If .MyFields(m).i = iToFields Then GoTo NotFill_MyFields
00260:                 Next
00261:                 MyFieldTA.Fill(.MyFields, iToFields)
00262: NotFill_MyFields:
00263:             Next
00264:             For o As Integer = 0 To .MyValueList.Count - 1
00265:                 Dim iToValue As Integer = .MyValueList(o).ToValue
00266:                 For p As Integer = 0 To .MyValue.Count - 1
00267:                     If .MyValue(p).i = .MyValueList(o).ToValue Then GoTo NotFill_MyValue
00268:                 Next
00269:                 MyValueTA.Fill(.MyValue, iToValue)
00270: NotFill_MyValue:
00271:             Next
00272:             'контрольная проверка целостности данных в DS, 
00273:             'заполняли:
00274:             ' MyPrice->MyBlockList->MyBlock
00275:             ' MyPrice->MyValueList->MyValue
00276:             ' MyPrice->MyFieldsList->MyFileld
00277:             'проверяем
00278:             'MyValueList.ToFields->MyFields.i
00279:             'MyFiledlist.ToBlock->MyBlock.i
00280:             For r As Integer = 0 To .MyValueList.Count - 1
00281:                 For q As Integer = 0 To .MyFields.Count - 1
00282:                     If .MyValueList(r).ToFields = .MyFields(q).i Then GoTo NotErr1
00283:                 Next
00284:             Next
00285:             GoTo ErrorJoin
00286: NotErr1:
00287:             For x As Integer = 0 To .MyFieldsList.Count - 1
00288:                 For y As Integer = 0 To .MyBlock.Count - 1
00289:                     If .MyFieldsList(x).ToBlock = .MyBlock(y).i Then GoTo NotErr2
00290:                 Next
00291:             Next
00292:             GoTo ErrorJoin
00293: NotErr2:
00294:             HaveData = True
00295:             Exit Sub
00296: ErrorJoin:
00297:             Dim Strim2 As New System.IO.MemoryStream
00298:             .WriteXml(Strim2)
00299:             Strim2.Position = 0
00300:             Dim RDR2 As New System.IO.StreamReader(Strim2, System.Text.Encoding.UTF8)
00301:             Dim Str2 As String = RDR2.ReadToEnd
00302:             RDR2.Close()
00303:             If CBool(System.Configuration.ConfigurationManager.AppSettings("TracePage1")) Then
00304:                 Call Common.ErrorMessage("ErrorJoin", Str2)
00305:             End If
00306:         End With
00307:     End Sub
00308: 
00309: End Class


Comments ( )
Link to this page: //www.vb-net.com/asp2/2/3.htm
< THANKS ME>