protected virtual TModel CreatePropertyEditSource(IEnumerable <TModel> collection) { var items = collection.ToArray(); var obj = (TModel)IoC.Instance.Resolve(typeof(TModel)); var bo = obj as WMSBusinessObject; if (bo == null) { throw new DeveloperException("TModel is not WMSBusinessObject"); } var properties = TypeDescriptor.GetProperties(typeof(TModel)).Cast <PropertyDescriptor>().ToArray(); bo.SuspendNotifications(); foreach (PropertyDescriptor p in properties) { // игнорирует вложенные коллекции if (typeof(IList).IsAssignableFrom(p.PropertyType)) { continue; } //var dist = items.Cast<WMSBusinessObject>().DistinctBy(i => i.GetProperty(p.Name)).ToArray(); var dist = BPH.GetDistinctPropertyByName(items, p.Name).Cast <WMSBusinessObject>().ToArray(); if (dist.Length == 1) { bo.SetProperty(p.Name, dist[0].GetProperty(p.Name)); } } bo.ResumeNotifications(); bo.AcceptChanges(); return(obj); }
private void ShowErrorMessage(Exception ex) { var viewService = IoC.Instance.Resolve <IViewService>(); viewService.ShowDialog("Ошибка", BPH.GetInnerException(ex), System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error, System.Windows.MessageBoxResult.OK, _fontSize); }
public bool ClosingWorking(decimal workerId, string filter, string dialogTitle, string workername, Func <DataRow[], string, string> dialogMessageHandler, Func <DateTime?> dialogWorkerDateTillHandler = null, double?fontSize = null) { //Проверяем наличие открытых выполнений работ var workings = BPH.GetOpenWorkingsByWorkerId(workerId, filter); if (workings != null && workings.Rows.Count > 0) { var wrows = workings.Rows.Cast <DataRow>().ToArray(); var message = dialogMessageHandler(wrows, workername); var vs = IoC.Instance.Resolve <IViewService>(); var dr = vs.ShowDialog(dialogTitle , message , MessageBoxButton.YesNo , MessageBoxImage.Question , MessageBoxResult.Yes , fontSize); if (dr == MessageBoxResult.No) { return(false); } //Закрываем var workingIds = wrows.Select(p => p["workingid"].To <decimal>()).ToArray(); var dateTill = dialogWorkerDateTillHandler == null ? null : dialogWorkerDateTillHandler(); using (var mgr = IoC.Instance.Resolve <IBPProcessManager>()) { mgr.CompleteWorkings(workingIds, dateTill); } } return(true); }
private static DateTime GetCorrectDate() { return(BPH.GetSystemDate()); //Убрал. иначе возникает ошибка при проверке на строне БД // убираем секунды, чтобы потом не мешали //var res = BPH.GetSystemDate(); //res = res.AddSeconds(-1 * res.Second); //return res; }
private static decimal?GetMandantCode(WMSBusinessObject entity) { // decimal? mandantCode = null; // if (entity != null) // { // //Поиск манданта // var mto = IoC.Instance.Resolve<IManagerForObject>(); // var mgrType = mto.GetManagerByTypeName(entity.GetType().Name); // var managerInstance = IoC.Instance.Resolve(mgrType, null) as IMandantHandler; // mandantCode = managerInstance == null ? null : managerInstance.GetMandantCode(entity); // } // return mandantCode; return(BPH.GetMandantId(entity)); }
private async Task <bool> GetWorkAsync(decimal workerId) { var workOperation = BillOperationCode.OP_INPUT_REG.ToString(); var workhelper = new WorkHelper(); Func <DataRow[], string, string> dialogMessageHandler = (rows, workername) => { return(string.Format(StringResources.YouHaveWorkingsMessageFormat, Environment.NewLine, string.Join(Environment.NewLine, rows.Select(p => string.Format("'{0}' ('{1}').", p["operationname"], p["workid"]))))); }; var result = workhelper.ClosingWorking(workerId: workerId, filter: null, dialogTitle: StringResources.Confirmation, workername: null, dialogMessageHandler: dialogMessageHandler); if (!result) { return(false); } //Создаем работу List <Work> workList; using (var mgr = IoC.Instance.Resolve <IBaseManager <Work> >()) { var filter = string.Format( "operationcode_r = '{1}' and workid in (select w2e.workid_r from wmswork2entity w2e where w2e.work2entityentity = 'CARGOIWB' " + "and w2e.work2entitykey in (select to_char(min(i2c.cargoiwbid_r)) from wmsiwb2cargo i2c " + "left join wmsiwbpos ip on i2c.iwbid_r = ip.iwbid_r " + "where ip.iwbposid ={0}))", _posID, workOperation); workList = mgr.GetFiltered(filter, GetModeEnum.Partial).ToList(); } if (workList.Any()) { using (var mgr = IoC.Instance.Resolve <IBaseManager <Working> >()) { var working = new Working { WORKID_R = workList.First().GetKey <decimal>(), WORKERID_R = workerId, WORKINGFROM = BPH.GetSystemDate() }; mgr.Insert(ref working); } } else { List <CargoIWB> cargoIWBList; using (var mgr = IoC.Instance.Resolve <IBaseManager <CargoIWB> >()) { cargoIWBList = mgr.GetFiltered(string.Format("cargoiwbid in (select min(i2c.cargoiwbid_r) from wmsiwb2cargo i2c join wmsiwbpos ip on ip.iwbid_r = i2c.iwbid_r where ip.iwbposid = {0} )", _posID), GetModeEnum.Partial).ToList(); } if (cargoIWBList.Any()) { var mgrBpProcessManager = IoC.Instance.Resolve <IBPProcessManager>(); Work mywork; mgrBpProcessManager.StartWorking("CARGOIWB", cargoIWBList.First().GetKey().ToString(), workOperation, workerId, cargoIWBList.First().MandantID, null, null, out mywork); } } Workings = RefreshWorking(); return(true); }
protected override void Execute(NativeActivityContext context) { // получим все параметры var teCode = TeCode.Get(context); // переведем код ТЕ в верхний регистр if (!string.IsNullOrEmpty(teCode)) { teCode = teCode.ToUpper(); } var placeCode = PlaceCode.Get(context); var isPack = IsPack.Get(context); var length = Length.Get(context); var width = Width.Get(context); var height = Height.Get(context); var tareWeight = TareWeight.Get(context); var weight = Weight.Get(context); var mandants = Mandants.Get(context); var teTypeCode = TeTypeCode.Get(context); var autoTeType = AutoTeType.Get(context); var extFilter = Filter.Get(context); _fontSize = FontSize.Get(context); var suspendNotifyCollectionChanged = SuspendNotifyCollectionChanged.Get(context); var teManager = IoC.Instance.Resolve <IBaseManager <TE> >(); try { if (suspendNotifyCollectionChanged) { teManager.SuspendNotifications(); } // если поле тип ТЕ пустое и не стоит признак пытаться определить тип ТЕ автоматически if (string.IsNullOrEmpty(teTypeCode) && !autoTeType) { throw new OperationException("Не указан тип ТЕ"); } // если поле тип ТЕ заполнено и установлен признак получения автоматически if (!string.IsNullOrEmpty(teTypeCode) && autoTeType) { throw new OperationException("Неверные настройки получения типа ТЕ"); } var uw = BeginTransactionActivity.GetUnitOfWork(context); if (uw != null) { throw new OperationException("Действие в транзакции запрещено"); } // проверим существование ТЕ if (!string.IsNullOrEmpty(teCode)) { var bpManager = IoC.Instance.Resolve <IBPProcessManager>(); var existTe = bpManager.CheckInstanceEntity("TE", teCode); if (existTe == 1) { var existTeObj = teManager.Get(teCode); if (existTeObj == null) { throw new OperationException("Нет прав на ТЕ с кодом {0}", teCode); } ExceptionResult.Set(context, null); TeCode.Set(context, teCode); OutTe.Set(context, existTeObj); Exist.Set(context, true); Result.Set(context, true); return; } } // фильтр на тип ТЕ var filter = string.Empty; // фильтр по мандантам if (!string.IsNullOrEmpty(mandants)) { filter = string.Format( "tetypecode in (select tt2m.tetypecode_r from wmstetype2mandant tt2m where tt2m.partnerid_r in ({0}))", mandants); } // фильтр по упаковкам if (isPack) { filter = string.Format( "{0}tetypecode in (select CUSTOMPARAMVAL.cpvkey from wmscustomparamvalue CUSTOMPARAMVAL where CUSTOMPARAMVAL.CPV2ENTITY = 'TETYPE' and CUSTOMPARAMVAL.CUSTOMPARAMCODE_R = 'TETypeIsPackingL2' and CUSTOMPARAMVAL.CPVVALUE is not null and CUSTOMPARAMVAL.CPVVALUE != '0')", string.IsNullOrEmpty(filter) ? string.Empty : filter + " and "); } // дополнительный фильтр по типам ТЕ if (!string.IsNullOrEmpty(extFilter)) { filter = string.Format( "{0}{1}", string.IsNullOrEmpty(filter) ? string.Empty : filter + " and ", extFilter); } // если надо определить тип ТЕ автоматически if (autoTeType) { teTypeCode = BPH.DetermineTeTypeCodeByTeCode(teCode, filter); } var teTypeObj = GetTeType(teTypeCode, filter); // если не выбрали тип ТЕ if (teTypeObj == null) { ExceptionResult.Set(context, null); TeCode.Set(context, teCode); OutTe.Set(context, null); Exist.Set(context, false); Result.Set(context, false); return; } var teObj = new TE(); teObj.SetKey(teCode); teObj.SetProperty(TE.TETypeCodePropertyName, teTypeObj.GetKey()); teObj.SetProperty(TE.CreatePlacePropertyName, placeCode); teObj.SetProperty(TE.CurrentPlacePropertyName, placeCode); teObj.SetProperty(TE.StatusCodePropertyName, TEStates.TE_FREE.ToString()); teObj.SetProperty(TE.TEPackStatusPropertyName, isPack ? TEPackStatus.TE_PKG_CREATED.ToString() : TEPackStatus.TE_PKG_NONE.ToString()); teObj.SetProperty(TE.TELengthPropertyName, length ?? teTypeObj.GetProperty(TEType.LengthPropertyName)); teObj.SetProperty(TE.TEWidthPropertyName, width ?? teTypeObj.GetProperty(TEType.WidthPropertyName)); teObj.SetProperty(TE.TEHeightPropertyName, height ?? teTypeObj.GetProperty(TEType.HeightPropertyName)); teObj.SetProperty(TE.TETareWeightPropertyName, tareWeight ?? teTypeObj.GetProperty(TEType.TareWeightPropertyName)); teObj.SetProperty(TE.TEMaxWeightPropertyName, tareWeight ?? teTypeObj.GetProperty(TEType.MaxWeightPropertyName)); teObj.SetProperty(TE.TEWeightPropertyName, weight ?? teTypeObj.GetProperty(TEType.TareWeightPropertyName)); ((ISecurityAccess)teManager).SuspendRightChecking(); teManager.Insert(ref teObj); ExceptionResult.Set(context, null); TeCode.Set(context, teCode); OutTe.Set(context, teObj); Exist.Set(context, false); Result.Set(context, true); } catch (Exception ex) { TeCode.Set(context, teCode); ExceptionResult.Set(context, ex); OutTe.Set(context, null); Exist.Set(context, false); Result.Set(context, false); } finally { if (suspendNotifyCollectionChanged) { teManager.ResumeNotifications(); } ((ISecurityAccess)teManager).ResumeRightChecking(); } }