/// <summary> /// Обновляет строки таблицы "Дополнительные комплектующие" из-за изменения комплектации. /// </summary> /// <param name="RowId">Идентификатор родительской строки.</param> /// <param name="Rows">Строки таблицы комплектующих.</param> private void UpdateACRows(Guid RowId, List <SKB.PaymentAndShipment.Forms.AccountCard.SaleCompleteRow> Rows) { BaseCardProperty Row; for (Int32 i = 0; i < Table_AddComplete.RowCount; i++) { Row = Table_AddComplete[i]; if (Row[RefApplicationCard.AddComplete.ParentTableRowId].ToGuid().Equals(RowId) && !Rows.Any(r => r.Name == Row[RefApplicationCard.AddComplete.Name].ToString())) { Table_AddComplete.RemoveRow(CardScript.BaseObject, i--); } } for (Int32 i = 0; i < Rows.Count; i++) { Boolean Flag = true; for (Int32 j = 0; j < Table_AddComplete.RowCount; j++) { Row = Table_AddComplete[j]; if (Row[RefApplicationCard.AddComplete.ParentTableRowId].ToGuid().Equals(RowId) && Rows[i].Name == Row[RefApplicationCard.AddComplete.Name].ToString()) { Row[RefApplicationCard.AddComplete.Count] = Rows[i].Count; Table_AddComplete.RefreshRow(Table_AddComplete.RowCount - 1); Flag = false; } } if (Flag) { Table_AddComplete.AddRow(CardScript.BaseObject); Row = Table_AddComplete[Table_AddComplete.RowCount - 1]; Row[RefApplicationCard.AddComplete.ParentTableRowId] = RowId; Row[RefApplicationCard.AddComplete.Id] = Rows[i].Id; Row[RefApplicationCard.AddComplete.Name] = Rows[i].Name; Row[RefApplicationCard.AddComplete.Code] = Rows[i].Code; Row[RefApplicationCard.AddComplete.Count] = Rows[i].Count; Row[RefApplicationCard.AddComplete.Ordered] = Rows[i].Ordered; Row[RefApplicationCard.AddComplete.Comment] = Rows[i].Comment; Table_AddComplete.RefreshRow(Table_AddComplete.RowCount - 1); } } }
private void CardControl_Saving(Object sender, CancelEventArgs e) { try { /* Переформирование файлов */ for (Int32 i = 0; i < Table_Service.RowCount; i++) { BaseCardProperty Row = Table_Service[i]; ServiceTableChange Change = Dic_Changes.Find(Row[RefApplicationCard.Service.Id].ToGuid()); if (Change.FileIsChanged || Row[RefApplicationCard.Service.PackedListID].ToGuid().IsEmpty()) { Guid FileId = Row[RefApplicationCard.Service.PackedListID].ToGuid(); AccountCard.FillPackFile(Context, UniversalCard.GetItemName(Row[RefApplicationCard.Service.DeviceID].ToGuid()), Row[RefApplicationCard.Service.PackedListData] as String, ref FileId); Row[RefApplicationCard.Service.PackedListID] = FileId; Table_Service.RefreshRow(i); } if (Change.DeviceNumberId.IsChanged) { if (!Change.DeviceNumberId.OldValue.IsEmpty()) { UniversalCard.GetItemRow(Change.DeviceNumberId.OldValue).SetDeviceState(DeviceState.Operating); } if (!Change.DeviceNumberId.NewValue.IsEmpty()) { UniversalCard.GetItemRow(Change.DeviceNumberId.NewValue).SetDeviceState(DeviceState.OnTheWay); } } if (Change.Sensors.IsChanged) { if (!String.IsNullOrEmpty(Change.Sensors.OldValue)) { foreach (String Sensor in Change.Sensors.OldValue.Split(';')) { UniversalCard.GetSensorRow(Sensor).SetDeviceState(DeviceState.Operating); } } if (!String.IsNullOrEmpty(Change.Sensors.NewValue)) { foreach (String Sensor in Change.Sensors.NewValue.Split(';')) { UniversalCard.GetSensorRow(Sensor).SetDeviceState(DeviceState.OnTheWay); } } } } /* Синхронизация */ if (Dic_Changes.IsChanged()) { ReferenceList RefList = Context.GetObject <ReferenceList>(GetControlValue(RefApplicationCard.MainInfo.Links).ToGuid()); List <CardData> AccountCards = new List <CardData>(); /* Получение карточек */ foreach (ReferenceListReference Link in RefList.References) { if (Link.CardType.Equals(RefAccountCard.ID)) { CardData AccountCard = CardScript.Session.CardManager.GetCardData(Link.Card); CardLock CardLock = CardScript.GetCardLock(AccountCard); if (!CardLock.IsFree) { throw new MyException("Договор/счет «" + CardLock.CardDescription + "» заблокирован " + (CardLock.IsMine ? "вами!" : "пользователем «" + CardLock.AccountName + "»!")); } AccountCards.Add(AccountCard); } } for (Int32 i = 0; i < AccountCards.Count; i++) { RefList = Context.GetObject <ReferenceList>(AccountCards[i].Sections[RefAccountCard.MainInfo.ID].FirstRow.GetGuid(RefAccountCard.MainInfo.LinkListId)); List <CardData> ShipmentTasks = new List <CardData>(), CompleteTasks = new List <CardData>(); /* Получение карточек */ foreach (ReferenceListReference Link in RefList.References) { if (Link.CardType.Equals(RefShipmentCard.ID)) { CardData ShipmentTask = CardScript.Session.CardManager.GetCardData(Link.Card); CardLock CardLock = CardScript.GetCardLock(ShipmentTask); if (!CardLock.IsFree) { throw new MyException("Задание на отгрузку «" + CardLock.CardDescription + "» заблокировано " + (CardLock.IsMine ? "вами!" : "пользователем «" + CardLock.AccountName + "»!")); } ShipmentTasks.Add(ShipmentTask); CardData CompleteTask = CardScript.Session.CardManager.GetCardData(ShipmentTask.Sections[RefShipmentCard.MainInfo.ID].FirstRow.GetGuid(RefShipmentCard.MainInfo.CompleteTaskId).ToGuid()); CardLock = CardScript.GetCardLock(CompleteTask); if (!CardLock.IsFree) { throw new MyException("Задание на комплектацию «" + CardLock.CardDescription + "» заблокировано " + (CardLock.IsMine ? "вами!" : "пользователем «" + CardLock.AccountName + "»!")); } CompleteTasks.Add(CompleteTask); } } if (AccountCards[i].InUpdate) { AccountCards[i].CancelUpdate(); } RowDataCollection AccountServiceRows = AccountCards[i].Sections[RefAccountCard.Service.ID].Rows; RowDataCollection AccountAddCompleteRows = AccountCards[i].Sections[RefAccountCard.AddComplete.ID].Rows; for (Int32 j = 0; j < Table_Service.RowCount; j++) { BaseCardProperty Row = Table_Service[i]; ServiceTableChange Change = Dic_Changes.Find(Row[RefApplicationCard.Service.Id].ToGuid()); RowData ServiceRow = AccountServiceRows.Find(RefAccountCard.Service.Id, Change.RowId); if (Change.IsChanged && !ServiceRow.IsNull()) { if (Change.Warranty.IsChanged) { ServiceRow.SetBoolean(RefAccountCard.Service.Warranty, Change.Warranty.NewValue); } if (Change.DeviceId.IsChanged) { ServiceRow.SetGuid(RefAccountCard.Service.DeviceId, Change.DeviceId.NewValue); } if (Change.AC.IsChanged) { ServiceRow.SetBoolean(RefAccountCard.Service.AC, Change.AC.NewValue); } if (Change.FileIsChanged) { ServiceRow.SetString(RefAccountCard.Service.ACList, Row[RefApplicationCard.Service.ACList] as String); ServiceRow.SetString(RefAccountCard.Service.PackedListData, Row[RefApplicationCard.Service.PackedListData] as String); ServiceRow.SetGuid(RefAccountCard.Service.PackedListId, Row[RefApplicationCard.Service.PackedListData].ToGuid()); RowDataCollection AddCompleteRows = AccountAddCompleteRows.Filter("@" + RefAccountCard.AddComplete.ParentTableRowId + " = '" + Change.RowId.ToString().ToUpper() + "'"); List <String> AccountComlete = AddCompleteRows.Select(r => r.GetString(RefAccountCard.AddComplete.Name)).ToList(); List <String> ApplicationComlete = new List <String>(); for (Int32 k = 0; k < Table_AddComplete.RowCount; k++) { if (Table_AddComplete[k][RefApplicationCard.AddComplete.ParentTableRowId].ToGuid().Equals(Change.RowId)) { ApplicationComlete.Add(Table_AddComplete[k][RefApplicationCard.AddComplete.Name] as String); } } for (Int32 k = 0; k < AddCompleteRows.Count; k++) { if (!ApplicationComlete.Contains(AddCompleteRows[k].GetString(RefAccountCard.AddComplete.Name))) { AccountCards[i].Sections[RefAccountCard.AddComplete.ID].DeleteRow(AddCompleteRows[k].Id); } } for (Int32 k = 0; k < Table_AddComplete.RowCount; k++) { if (Table_AddComplete[k][RefApplicationCard.AddComplete.ParentTableRowId].ToGuid().Equals(Change.RowId)) { RowData AddCompleteRow = AddCompleteRows.Find(RefAccountCard.AddComplete.Name, Table_AddComplete[k][RefApplicationCard.AddComplete.Name] as String); if (AddCompleteRow.IsNull()) { AddCompleteRow = AccountCards[i].Sections[RefAccountCard.AddComplete.ID].Rows.AddNew(); AddCompleteRow.SetInt32(RefAccountCard.AddComplete.Ordered, 0); } AddCompleteRow.SetInt32(RefAccountCard.AddComplete.Count, (Int32?)Table_AddComplete[k][RefApplicationCard.AddComplete.Count]); AddCompleteRow.SetGuid(RefAccountCard.AddComplete.Id, Table_AddComplete[k][RefApplicationCard.AddComplete.Id].ToGuid()); AddCompleteRow.SetString(RefAccountCard.AddComplete.Name, Table_AddComplete[k][RefApplicationCard.AddComplete.Name] as String); AddCompleteRow.SetString(RefAccountCard.AddComplete.Code, Table_AddComplete[k][RefApplicationCard.AddComplete.Code] as String); } } } } } for (Int32 j = 0; j < ShipmentTasks.Count; j++) { if (ShipmentTasks[j].LockStatus == LockStatus.Free && CompleteTasks[j].LockStatus == LockStatus.Free) { if (ShipmentTasks[j].InUpdate) { ShipmentTasks[j].CancelUpdate(); } if (CompleteTasks[j].InUpdate) { CompleteTasks[j].CancelUpdate(); } RowDataCollection ShipmentDevicesRows = ShipmentTasks[j].Sections[RefShipmentCard.Devices.ID].Rows; RowDataCollection CompleteDevicesRows = CompleteTasks[j].Sections[RefCompleteCard.Devices.ID].Rows; foreach (RowData DevicesRow in ShipmentDevicesRows) { ServiceTableChange Change = Dic_Changes.Find(DevicesRow.GetGuid(RefShipmentCard.Devices.AccountCardRowId).ToGuid()); if (!Change.IsNull() && Change.IsChanged) { RowDataCollection CompleteRows = CompleteDevicesRows.Filter("@" + RefCompleteCard.Devices.ShipmentTaskRowId + " = '" + DevicesRow.GetGuid(RefShipmentCard.Devices.Id).ToString().ToUpper() + "'"); /* Изменение связных полей */ if (Change.Warranty.IsChanged) { DevicesRow.SetBoolean(RefShipmentCard.Devices.Warranty, Change.Warranty.NewValue); foreach (RowData CompleteRow in CompleteRows) { CompleteRow.SetBoolean(RefCompleteCard.Devices.Warranty, Change.Warranty.NewValue); } } if (Change.AC.IsChanged) { DevicesRow.SetBoolean(RefShipmentCard.Devices.AC, Change.AC.NewValue); foreach (RowData CompleteRow in CompleteRows) { CompleteRow.SetBoolean(RefCompleteCard.Devices.AC, Change.AC.NewValue); } } if (Change.DeviceId.IsChanged) { DevicesRow.SetGuid(RefShipmentCard.Devices.DeviceId, Change.DeviceId.NewValue); foreach (RowData CompleteRow in CompleteRows) { CompleteRow.SetGuid(RefCompleteCard.Devices.DeviceId, Change.DeviceId.NewValue); } } if (Change.FileIsChanged) { DevicesRow.SetBoolean(RefShipmentCard.Devices.IsChanged, Change.FileIsChanged); for (Int32 k = 0; k < Table_Service.RowCount; k++) { if (Table_Service[k][RefApplicationCard.Service.Id].ToGuid().Equals(Change.RowId)) { DevicesRow.SetGuid(RefShipmentCard.Devices.TemplatePackListId, Table_Service[k][RefApplicationCard.Service.PackedListID].ToGuid()); } } } /* Очистка связных полей */ if (Change.DeviceId.IsChanged || Change.AC.IsChanged) { DevicesRow.SetString(RefShipmentCard.Devices.DeviceNumbers, null); DevicesRow.SetString(RefShipmentCard.Devices.PartyNumbers, null); DevicesRow.SetString(RefShipmentCard.Devices.Coupons, null); foreach (RowData CompleteRow in CompleteRows) { try { Guid DeviceNumberId = CompleteRow.GetObject(RefCompleteCard.Devices.DeviceNumberId).ToGuid(); /* Очистка приборов */ if (!DeviceNumberId.IsEmpty()) { try { UniversalCard.GetItemRow(DeviceNumberId).UpdateDeviceInformation(UniversalCard, CompleteRow.GetBoolean(RefCompleteCard.Devices.AS)); } catch (MyException Ex) { switch (Ex.ErrorCode) { case -1: WriteLog("Ошибка: предвиденное исключение" + "\r\n" + Ex.Message + "\r\n" + Ex.StackTrace); WriteLog("Ошибка: предвиденное исключение" + "\r\n" + Ex.InnerException.Message + "\r\n" + Ex.InnerException.StackTrace); break; case 0: WriteLog("Ошибка: предвиденное исключение" + "\r\n" + Ex.Message + "\r\n" + Ex.StackTrace); break; case 1: String[] ss = Ex.Message.Split('\t'); WriteLog("Ошибка: предвиденное исключение" + "\r\n" + (ss.Length >= 2 ? "В карточке " + ss[1] + " отсутствует поле: " + ss[0] : Ex.Message) + "\r\n" + Ex.StackTrace); WriteLog("Ошибка: предвиденное исключение" + "\r\n" + Ex.InnerException.Message + "\r\n" + Ex.InnerException.StackTrace); break; } } } CompleteRow.SetGuid(RefCompleteCard.Devices.DeviceNumberId, Guid.Empty); CompleteRow.SetString(RefCompleteCard.Devices.DeviceNumber, null); CompleteRow.SetGuid(RefCompleteCard.Devices.CouponId, Guid.Empty); } catch (Exception Ex) { WriteLog("Ошибка: непредвиденное исключение" + "\r\n" + Ex.Message + "\r\n" + Ex.StackTrace); } } } } } } } } } } catch (ArgumentNullException Ex) { MyMessageBox.Show("Поле \"" + Ex.ParamName + "\" обязательно к заполнению!", "Предупреждение", MessageBoxButtons.OK, MessageBoxIcon.Warning); e.Cancel = true; } catch (MyException Ex) { MyMessageBox.Show(Ex.Message + Environment.NewLine + "Синхронизация связных карточек не произойдет.", "Предупреждение", MessageBoxButtons.OK, MessageBoxIcon.Warning); e.Cancel = true; } catch (Exception Ex) { CallError(Ex); } }