private void addNewTarget_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (openFileDialog1.ShowDialog(this) == DialogResult.OK)
            {
                _waitForm.Show();
                _waitForm.Caption = "正在计算特征值...";

                var img = OpenCvSharp.IplImage.FromFile(openFileDialog1.FileName);
                var fs  = new FaceProcessingWrapper.FaceSpecification();
                var suc = _faceComparer.CalcFeature(img, fs);
                _waitForm.Hide();
                if (!suc)
                {
                    _messageBoxService.ShowError("人像不满足比对要求,请重新选择人像。");
                    return;
                }

                var target = new TargetPerson(_uow);
                target.EyeBrowShape  = fs.EyebrowShape;
                target.EyebrowRatio  = fs.EyebrowRatio;
                target.FeaturePoints = fs.Features;
                var path = System.IO.Path.Combine(Properties.Settings.Default.OutputPath,
                                                  @"TargetFeature\" + Guid.NewGuid() + ".txt");
                var dir = Path.GetDirectoryName(path);
                if (!Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }
                target.FeatureFilePath = path;
                var imgPath = path.Replace(".txt", ".jpg");
                img.SaveImage(imgPath);
                target.ImagePath = imgPath;

                var item = AddGalleryItem(img.ToBitmap());
                item.Tag = target;
                _isDirty = true;
            }
        }
        /// <summary>
        /// Binds the grid.
        /// </summary>
        private void BindGrid()
        {
            phSummary.Controls.Clear();
            rFilter.Visible = true;
            gList.Visible   = true;

            bool canAddEditDelete = IsUserAuthorized(Authorization.EDIT);

            gList.Actions.ShowAdd = canAddEditDelete;
            gList.IsDeleteEnabled = canAddEditDelete;

            var rockContext = new RockContext();
            var benevolenceRequestService = new BenevolenceRequestService(rockContext);

            var benevolenceRequests = benevolenceRequestService
                                      .Queryable("BenevolenceResults,RequestedByPersonAlias,RequestedByPersonAlias.Person,CaseWorkerPersonAlias,CaseWorkerPersonAlias.Person").AsNoTracking();

            var hideGridColumns       = GetAttributeValue(AttributeKey.HideColumnsAttributeKey)?.Split(',')?.Select(v => v.ToUpper());
            var benevolenceTypeFilter = GetAttributeValue(AttributeKey.FilterBenevolenceTypesAttributeKey)
                                        ?.Split(',')
                                        ?.Where(v => v.IsNotNullOrWhiteSpace())
                                        ?.Select(v => new Guid(v));

            // Filter by Start Date
            DateTime?startDate = drpDate.LowerValue;

            if (startDate != null)
            {
                benevolenceRequests = benevolenceRequests.Where(b => b.RequestDateTime >= startDate);
            }

            // Filter by End Date
            DateTime?endDate = drpDate.UpperValue;

            if (endDate != null)
            {
                benevolenceRequests = benevolenceRequests.Where(b => b.RequestDateTime <= endDate);
            }

            // Filter by Campus
            if (cpCampus.SelectedCampusId.HasValue)
            {
                benevolenceRequests = benevolenceRequests.Where(b => b.CampusId == cpCampus.SelectedCampusId);
            }

            if (TargetPerson != null)
            {
                // show benevolence request for the target person and also for their family members
                var qryFamilyMembers = TargetPerson.GetFamilyMembers(true, rockContext);
                benevolenceRequests = benevolenceRequests.Where(a => a.RequestedByPersonAliasId.HasValue && qryFamilyMembers.Any(b => b.PersonId == a.RequestedByPersonAlias.PersonId));
            }
            else
            {
                // Filter by First Name
                string firstName = tbFirstName.Text;
                if (!string.IsNullOrWhiteSpace(firstName))
                {
                    benevolenceRequests = benevolenceRequests.Where(b => b.FirstName.StartsWith(firstName));
                }

                // Filter by Last Name
                string lastName = tbLastName.Text;
                if (!string.IsNullOrWhiteSpace(lastName))
                {
                    benevolenceRequests = benevolenceRequests.Where(b => b.LastName.StartsWith(lastName));
                }
            }

            // Filter by Government Id
            string governmentId = tbGovernmentId.Text;

            if (!string.IsNullOrWhiteSpace(governmentId))
            {
                benevolenceRequests = benevolenceRequests.Where(b => b.GovernmentId.StartsWith(governmentId));
            }

            // Filter by Case Worker
            int?caseWorkerPersonAliasId = ddlCaseWorker.SelectedItem.Value.AsIntegerOrNull();

            if (caseWorkerPersonAliasId != null)
            {
                benevolenceRequests = benevolenceRequests.Where(b => b.CaseWorkerPersonAliasId == caseWorkerPersonAliasId);
            }

            // Filter by Result
            int?resultTypeValueId = dvpResult.SelectedItem.Value.AsIntegerOrNull();

            if (resultTypeValueId != null)
            {
                benevolenceRequests = benevolenceRequests.Where(b => b.BenevolenceResults.Where(r => r.ResultTypeValueId == resultTypeValueId).Count() > 0);
            }

            // Filter by Request Status
            int?requestStatusValueId = dvpStatus.SelectedItem.Value.AsIntegerOrNull();

            if (requestStatusValueId != null)
            {
                benevolenceRequests = benevolenceRequests.Where(b => b.RequestStatusValueId == requestStatusValueId);
            }

            // Filter by Benevolence Types
            var benevolenceTypeIds = cblBenevolenceType.SelectedValues.Where(v => v.ToIntSafe() > 0).Select(v => v.ToIntSafe());

            if (benevolenceTypeIds?.Count() > 0)
            {
                benevolenceRequests = benevolenceRequests.Where(b => benevolenceTypeIds.Contains(b.BenevolenceTypeId));
            }

            if (benevolenceTypeFilter?.Count() > 0)
            {
                benevolenceRequests = benevolenceRequests.Where(b => benevolenceTypeFilter.Contains(b.BenevolenceType.Guid));
            }

            SortProperty sortProperty = gList.SortProperty;

            if (sortProperty != null)
            {
                if (sortProperty.Property == "TotalAmount")
                {
                    if (sortProperty.Direction == SortDirection.Descending)
                    {
                        benevolenceRequests = benevolenceRequests.OrderByDescending(a => a.BenevolenceResults.Sum(b => b.Amount));
                    }
                    else
                    {
                        benevolenceRequests = benevolenceRequests.OrderBy(a => a.BenevolenceResults.Sum(b => b.Amount));
                    }
                }
            }
            else
            {
                benevolenceRequests = benevolenceRequests.OrderByDescending(a => a.RequestDateTime).ThenByDescending(a => a.Id);
            }

            // Filter query by any configured attribute filters

            if (AvailableAttributes != null && AvailableAttributes.Any())
            {
                foreach (var attribute in AvailableAttributes)
                {
                    var filterControl = phAttributeFilters.FindControl("filter_" + attribute.Id.ToString());
                    benevolenceRequests = attribute.FieldType.Field.ApplyAttributeQueryFilter(benevolenceRequests, filterControl, attribute, benevolenceRequestService, Rock.Reporting.FilterMode.SimpleFilter);
                }
            }

            var personContext = this.ContextEntity <Person>();

            if (personContext != null)
            {
                benevolenceRequests = benevolenceRequests.Where(a => a.RequestedByPersonAlias.PersonId == personContext.Id);
            }

            if (sortProperty != null)
            {
                gList.DataSource = benevolenceRequests.Sort(sortProperty).ToList();
            }
            else
            {
                gList.DataSource = benevolenceRequests.OrderByDescending(p => p.CreatedDateTime).ThenByDescending(p => p.Id).ToList();
            }

            // Hide the campus column if the campus filter is not visible.
            gList.ColumnsOfType <RockBoundField>().First(c => c.DataField == "Campus.Name").Visible = cpCampus.Visible;

            gList.EntityTypeId = EntityTypeCache.Get <BenevolenceRequest>().Id;
            gList.DataBind();

            // Hide columns and specific fields if the hide column attributes are set on the block.
            if (hideGridColumns?.Count() > 0)
            {
                foreach (DataControlField controlField in gList.Columns)
                {
                    controlField.Visible = !hideGridColumns.Contains(controlField.HeaderText.ToUpper());
                }

                pnlSummary.Visible = !hideGridColumns.Contains("TOTAL RESULTS");
            }

            // Hide the campus column if the campus filter is not visible.
            gList.ColumnsOfType <RockBoundField>().First(c => c.DataField == "Campus.Name").Visible = cpCampus.Visible;

            // Builds the Totals section
            var definedTypeCache = DefinedTypeCache.Get(new Guid(Rock.SystemGuid.DefinedType.BENEVOLENCE_RESULT_TYPE));
            Dictionary <string, decimal> resultTotals = new Dictionary <string, decimal>();
            decimal grandTotal = 0;

            foreach (BenevolenceRequest request in benevolenceRequests)
            {
                foreach (BenevolenceResult result in request.BenevolenceResults)
                {
                    if (result.Amount != null)
                    {
                        if (resultTotals.ContainsKey(result.ResultTypeValue.Value))
                        {
                            resultTotals[result.ResultTypeValue.Value] += result.Amount.Value;
                        }
                        else
                        {
                            resultTotals.Add(result.ResultTypeValue.Value, result.Amount.Value);
                        }

                        grandTotal += result.Amount.Value;
                    }
                }
            }

            foreach (KeyValuePair <string, decimal> keyValuePair in resultTotals)
            {
                phSummary.Controls.Add(new LiteralControl(string.Format("<div class='row'><div class='col-xs-8'>{0}: </div><div class='col-xs-4 text-right'>{1}</div></div>", keyValuePair.Key, keyValuePair.Value.FormatAsCurrency())));
            }

            phSummary.Controls.Add(new LiteralControl(string.Format("<div class='row'><div class='col-xs-8'><b>Total: </div><div class='col-xs-4 text-right'>{0}</b></div></div>", grandTotal.FormatAsCurrency())));
        }
 public override PlatformResult <TargetPerson> UpdateTargetPerson(TargetPerson person)
 {
     throw new NotImplementedException();
 }
        /// <summary>
        /// Binds the grid.
        /// </summary>
        private void BindGrid()
        {
            phSummary.Controls.Clear();
            rFilter.Visible = true;
            gList.Visible   = true;
            RockContext rockContext = new RockContext();
            BenevolenceRequestService benevolenceRequestService = new BenevolenceRequestService(rockContext);
            var qry = benevolenceRequestService.Queryable("BenevolenceResults,RequestedByPersonAlias,RequestedByPersonAlias.Person,CaseWorkerPersonAlias,CaseWorkerPersonAlias.Person").AsNoTracking();

            // Filter by Start Date
            DateTime?startDate = drpDate.LowerValue;

            if (startDate != null)
            {
                qry = qry.Where(b => b.RequestDateTime >= startDate);
            }

            // Filter by End Date
            DateTime?endDate = drpDate.UpperValue;

            if (endDate != null)
            {
                qry = qry.Where(b => b.RequestDateTime <= endDate);
            }

            // Filter by Campus
            if (cpCampus.SelectedCampusId.HasValue)
            {
                qry = qry.Where(b => b.CampusId == cpCampus.SelectedCampusId);
            }

            if (TargetPerson != null)
            {
                // show benevolence request for the target person and also for their family members
                var qryFamilyMembers = TargetPerson.GetFamilyMembers(true, rockContext);
                qry = qry.Where(a => a.RequestedByPersonAliasId.HasValue && qryFamilyMembers.Any(b => b.PersonId == a.RequestedByPersonAlias.PersonId));
            }
            else
            {
                // Filter by First Name
                string firstName = tbFirstName.Text;
                if (!string.IsNullOrWhiteSpace(firstName))
                {
                    qry = qry.Where(b => b.FirstName.StartsWith(firstName));
                }

                // Filter by Last Name
                string lastName = tbLastName.Text;
                if (!string.IsNullOrWhiteSpace(lastName))
                {
                    qry = qry.Where(b => b.LastName.StartsWith(lastName));
                }
            }

            // Filter by Government Id
            string governmentId = tbGovernmentId.Text;

            if (!string.IsNullOrWhiteSpace(governmentId))
            {
                qry = qry.Where(b => b.GovernmentId.StartsWith(governmentId));
            }

            // Filter by Case Worker
            int?caseWorkerPersonAliasId = ddlCaseWorker.SelectedItem.Value.AsIntegerOrNull();

            if (caseWorkerPersonAliasId != null)
            {
                qry = qry.Where(b => b.CaseWorkerPersonAliasId == caseWorkerPersonAliasId);
            }

            // Filter by Result
            int?resultTypeValueId = dvpResult.SelectedItem.Value.AsIntegerOrNull();

            if (resultTypeValueId != null)
            {
                qry = qry.Where(b => b.BenevolenceResults.Where(r => r.ResultTypeValueId == resultTypeValueId).Count() > 0);
            }

            // Filter by Request Status
            int?requestStatusValueId = dvpStatus.SelectedItem.Value.AsIntegerOrNull();

            if (requestStatusValueId != null)
            {
                qry = qry.Where(b => b.RequestStatusValueId == requestStatusValueId);
            }

            SortProperty sortProperty = gList.SortProperty;

            if (sortProperty != null)
            {
                if (sortProperty.Property == "TotalAmount")
                {
                    if (sortProperty.Direction == SortDirection.Descending)
                    {
                        qry = qry.OrderByDescending(a => a.BenevolenceResults.Sum(b => b.Amount));
                    }
                    else
                    {
                        qry = qry.OrderBy(a => a.BenevolenceResults.Sum(b => b.Amount));
                    }
                }
                else
                {
                    qry = qry.Sort(sortProperty);
                }
            }
            else
            {
                qry = qry.OrderByDescending(a => a.RequestDateTime).ThenByDescending(a => a.Id);
            }

            // Filter query by any configured attribute filters
            if (AvailableAttributes != null && AvailableAttributes.Any())
            {
                foreach (var attribute in AvailableAttributes)
                {
                    var filterControl = phAttributeFilters.FindControl("filter_" + attribute.Id.ToString());
                    qry = attribute.FieldType.Field.ApplyAttributeQueryFilter(qry, filterControl, attribute, benevolenceRequestService, Rock.Reporting.FilterMode.SimpleFilter);
                }
            }

            var list = qry.ToList();

            gList.DataSource = list;
            gList.DataBind();

            // Builds the Totals section
            var definedTypeCache = DefinedTypeCache.Get(new Guid(Rock.SystemGuid.DefinedType.BENEVOLENCE_RESULT_TYPE));
            Dictionary <string, decimal> resultTotals = new Dictionary <string, decimal>();
            decimal grandTotal = 0;

            foreach (BenevolenceRequest request in list)
            {
                foreach (BenevolenceResult result in request.BenevolenceResults)
                {
                    if (result.Amount != null)
                    {
                        if (resultTotals.ContainsKey(result.ResultTypeValue.Value))
                        {
                            resultTotals[result.ResultTypeValue.Value] += result.Amount.Value;
                        }
                        else
                        {
                            resultTotals.Add(result.ResultTypeValue.Value, result.Amount.Value);
                        }

                        grandTotal += result.Amount.Value;
                    }
                }
            }

            foreach (KeyValuePair <string, decimal> keyValuePair in resultTotals)
            {
                phSummary.Controls.Add(new LiteralControl(string.Format("<div class='row'><div class='col-xs-8'>{0}: </div><div class='col-xs-4 text-right'>{1}{2:#,##0.00}</div></div>", keyValuePair.Key, GlobalAttributesCache.Value("CurrencySymbol"), keyValuePair.Value)));
            }

            phSummary.Controls.Add(new LiteralControl(string.Format("<div class='row'><div class='col-xs-8'><b>Total: </div><div class='col-xs-4 text-right'>{0}{1:#,##0.00}</b></div></div>", GlobalAttributesCache.Value("CurrencySymbol"), grandTotal)));
        }
Esempio n. 5
0
 public abstract PlatformResult <TargetPerson> DeleteTargetPerson(TargetPerson person);
Esempio n. 6
0
 public abstract PlatformResult <TargetPerson> AddTargetPerson(TargetPerson person);