Beispiel #1
0
        private void CreateAccountCard_ItemClick(Object sender, ItemClickEventArgs e)
        {
            try
            {
                IReferenceListService ReferenceListService = Context.GetService <IReferenceListService>();
                ReferenceList         RefList = Context.GetObject <ReferenceList>(Control_Links.ReferenceListID);
                if (RefList.References.Any(r => r.CardType.Equals(RefAccountCard.ID)))
                {
                    CardScript.CardFrame.CardHost.ShowCardModal(RefList.References.First(r => r.CardType.Equals(RefAccountCard.ID)).Card, ActivateMode.Edit);
                }

                if (Table_Service.RowCount > 0)
                {
                    throw new MyException(1);
                }

                if (!CardScript.SaveCard())
                {
                    throw new MyException(0);
                }

                /* Формирование задания на отгрузку */
                CardData AccountData = Context.CreateCard(RefAccountCard.ID);
                AccountData.BeginUpdate();

                RowData     MainInfoRow = AccountData.Sections[RefAccountCard.MainInfo.ID].FirstRow;
                SectionData Service     = AccountData.Sections[RefAccountCard.Service.ID];

                MainInfoRow.SetGuid(RefAccountCard.MainInfo.RegisterId, Context.GetCurrentUser());
                MainInfoRow.SetGuid(RefAccountCard.MainInfo.ContractSubjectId, AccountCard.Item_Subject_Service.ToGuid());
                MainInfoRow.SetGuid(RefAccountCard.MainInfo.ClientId, GetControlValue(RefApplicationCard.MainInfo.Client).ToGuid());


                Guid?RefListId = MainInfoRow.GetGuid(RefAccountCard.MainInfo.LinkListId);
                RefList = RefListId.HasValue ? Context.GetObject <ReferenceList>(RefListId.Value) : ReferenceListService.CreateReferenceList();

                if (!RefList.References.Any(RefRef => RefRef.Card.Equals(CardScript.CardData.Id)))
                {
                    ReferenceListService.CreateReference(RefList, null, CardScript.CardData.Id, RefApplicationCard.ID, false);
                    MainInfoRow.SetGuid(RefAccountCard.MainInfo.LinkListId, Context.GetObjectRef <ReferenceList>(RefList).Id);
                }

                RefList.References.First(RefRef => RefRef.Card.Equals(CardScript.CardData.Id)).LinkDescription = DateTime.Now.ToString("Создано dd.MM.yyyy HH:mm");
                Context.SaveObject(RefList);

                for (Int32 i = 0; i < Table_Service.RowCount; i++)
                {
                    BaseCardProperty Row        = Table_Service[i];
                    RowData          ServiceRow = Service.Rows.AddNew();
                    ServiceRow.SetGuid(RefAccountCard.Service.Id, Row[RefApplicationCard.Service.Id].ToGuid());
                    ServiceRow.SetGuid(RefAccountCard.Service.DeviceId, Row[RefApplicationCard.Service.DeviceID].ToGuid());
                    ServiceRow.SetBoolean(RefAccountCard.Service.AC, (Boolean)Row[RefApplicationCard.Service.Verify]);
                    ServiceRow.SetBoolean(RefAccountCard.Service.Verify, (Boolean)Row[RefApplicationCard.Service.Verify]);
                    ServiceRow.SetBoolean(RefAccountCard.Service.Repair, (Boolean)Row[RefApplicationCard.Service.Repair]);
                    ServiceRow.SetBoolean(RefAccountCard.Service.Calibrate, (Boolean)Row[RefApplicationCard.Service.Calibrate]);
                    ServiceRow.SetBoolean(RefAccountCard.Service.Delivery, false);
                    ServiceRow.SetInt32(RefAccountCard.Service.Count, 1);
                    ServiceRow.SetInt32(RefAccountCard.Service.Shipped, 0);
                    ServiceRow.SetInt32(RefAccountCard.Service.ToShip, 1);
                    ServiceRow.SetString(RefAccountCard.Service.ACList, Row[RefApplicationCard.Service.ACList]);
                    ServiceRow.SetString(RefAccountCard.Service.PackedListData, Row[RefApplicationCard.Service.PackedListData]);
                    ServiceRow.SetGuid(RefAccountCard.Service.PackedListId, Row[RefApplicationCard.Service.PackedListID].ToGuid());
                    ServiceRow.SetBoolean(RefAccountCard.Service.Warranty, (Boolean)Row[RefApplicationCard.Service.WarrantyServices]);
                }

                AccountData.EndUpdate();

                if (CardScript.CardFrame.CardHost.ShowCardModal(AccountData.Id, ActivateMode.Edit, ActivateFlags.New))
                {
                    Control_Links.AddRef(AccountData.Id, DateTime.Now.ToString("Создано dd.MM.yyyy HH:mm"), true, false);
                    MyHelper.SaveCard(CardScript);
                }
                else
                {
                    AccountData.ForceUnlock();
                    CardScript.Session.CardManager.DeleteCard(AccountData.Id, true);
                }
            }
            catch (MyException Ex)
            {
                switch (Ex.ErrorCode)
                {
                case 1: MyMessageBox.Show("Таблица «Сервисное обслуживание» не заполнена!", "Предупреждение", MessageBoxButtons.OK, MessageBoxIcon.Warning); break;
                }
            }
            catch (Exception Ex) { CallError(Ex); }
        }
Beispiel #2
0
        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); }
        }