Esempio n. 1
0
        public DealInfo GetDealInfo(string recordNumber)
        {
            DealInfo dealInfo = new DealInfo();

            try
            {
                Deal deal = new DCDManager().GetDealByRecordNumber(recordNumber);

                dealInfo = new DealInfo
                {
                    DealDate     = deal.Created,
                    ID           = deal.RecordId.ToString(),
                    LastUpdated  = deal.LastModified,
                    Name         = deal.Title,
                    RecordNumber = deal.RecordNumber,
                    Url          = string.Format(Sitecore.Configuration.Settings.GetSetting("DCD.OldDealsURL"), recordNumber)
                };
            }
            catch (Exception ex)
            {
                Sitecore.Diagnostics.Log.Error("GetDealInfo API error:", ex, "LogFileAppender");
            }

            return(dealInfo);
        }
Esempio n. 2
0
        protected override void Render(HtmlTextWriter writer)
        {
            string type   = Request["type"];
            string number = Request["number"];

            if (!string.IsNullOrEmpty(type) && !string.IsNullOrEmpty(number))
            {
                if (type == "deal")
                {
                    Deal deal = new DCDManager().GetDealByRecordNumber(number);
                    if (deal != null)
                    {
                        Response.ContentType = "application/xml";
                        writer.Write(buildXml(deal));
                    }
                }
                if (type == "company")
                {
                    Company company = new DCDManager().GetCompanyByRecordNumber(number);
                    if (company != null)
                    {
                        Response.ContentType = "application/xml";
                        writer.Write(buildXml(company));
                    }
                }
            }
            else
            {
                base.Render(writer);
            }
        }
Esempio n. 3
0
        public override string GetLink(string linkId)
        {
            var  finder = new DCDManager();
            Deal deal   = finder.GetDealByRecordNumber(linkId);

            if (deal == null)
            {
                return(string.Empty);
            }

            return(string.Format("{1}/{0}", deal.RecordNumber, BaseUrl));
        }
Esempio n. 4
0
        public override string GetLinkText(string linkId)
        {
            var  finder = new DCDManager();
            Deal deal   = finder.GetDealByRecordNumber(linkId);

            if (deal == null)
            {
                return(string.Empty);
            }

            return(deal.Title);
        }
Esempio n. 5
0
        public override string GetLink(string linkId)
        {
            var  finder = new DCDManager();
            Drug drug   = finder.GetDrugByRecordNumber(linkId);

            if (drug == null)
            {
                return(string.Empty);
            }

            return(string.Format("{1}/d/{0}", drug.RecordNumber, BaseUrl));
        }
Esempio n. 6
0
        public override string GetLink(string linkId)
        {
            var finder  = new DCDManager();
            var company = finder.GetCompanyByRecordNumber(linkId);

            if (company == null)
            {
                return(string.Empty);
            }

            return(company.RecordNumber);
        }
Esempio n. 7
0
        public List <CompanyWrapper> GetAllCompanies()
        {
            List <CompanyWrapper> lstDbCompanies = null;

            try
            {
                List <Company> tempLstComp = new DCDManager().GetAllCompanies();

                lstDbCompanies = tempLstComp.Select(comp => new CompanyWrapper {
                    Parent = null, RecordID = comp.RecordId, RecordNumber = comp.RecordNumber, RelatedCompanies = new List <CompanyWrapper>(), Title = comp.Title,
                }).ToList();
            }
            catch (Exception ex)
            {
                Sitecore.Diagnostics.Log.Error("GetAllCompanies API error:", ex, "LogFileAppender");
            }

            return(lstDbCompanies);
        }
Esempio n. 8
0
        private IEnumerable <CompanyWrapper> GetWithRelated()
        {
            DCDManager dcdMgr = new DCDManager();

            // build a dictionary of all of the companies, key is the company id
            Dictionary <int, Company> allCompanies = dcdMgr.GetAllCompanies().ToDictionary(x => x.RecordId, x => x);

            // pull down a list of all related companies
            RelatedCompany[] allRelatedCompanies = dcdMgr.GetAllRelatedCompanies().ToArray();

            // our results dictionary, key is the company id
            Dictionary <int, CompanyWrapper> results = new Dictionary <int, CompanyWrapper>();

            // keep track of where a company is when it's inserted into "RelatedCompanies" so we don't have to dig through every companies
            // RelatedCompanies to try to find a company.
            Dictionary <int, List <CompanyWrapper> > pointers = new Dictionary <int, List <CompanyWrapper> >();

            // gather all of the "Root Companies" because there are a ton of duplicates.
            RelatedCompany[] rootCompanies =
                (from i in allRelatedCompanies
                 where i.CompanyRecordId.ToString() == i.RelatedCompanyRecordNumber
                 orderby i.RelatedCompanyPath ascending
                 select i).ToArray();

            // build out the wrappers we're going to return.
            foreach (var relatedCompany in rootCompanies)
            {
                Company        currentCompany = allCompanies[relatedCompany.CompanyRecordId];
                CompanyWrapper wrapper        = new CompanyWrapper {
                    RecordID = currentCompany.RecordId, RecordNumber = currentCompany.RecordNumber, Title = currentCompany.Title, Parent = null
                };
                results.Add(relatedCompany.CompanyRecordId, wrapper);
            }

            // iterate through all of our root companies
            foreach (var relatedCompany in rootCompanies)
            {
                // split the path by '/' to get all of the seperate results.
                string[] pieces = relatedCompany.RelatedCompanyPath.Split('/');

                // ignore paths with no slash, because they don't have parents.
                if (pieces.Length == 1)
                {
                    continue;
                }

                // join all of the pieces except for the last piece to give us the parent of the current item
                string parent = string.Join("/", pieces.Take(pieces.Length - 1).ToArray());

                // get the parent from our root companies
                RelatedCompany parentCompany = rootCompanies.FirstOrDefault(x => x.RelatedCompanyPath == parent);

                // check to make sure it's legit and isn't itself for some reason.
                if (parentCompany == null || parentCompany.CompanyRecordId == relatedCompany.CompanyRecordId)
                {
                    continue;
                }

                // get the parent from the "results" dictionary
                CompanyWrapper parentWrapper = Get(results, pointers, parentCompany.CompanyRecordId, false);

                // check to make sure it exists.
                if (parentWrapper == null)
                {
                    continue;
                }

                // get the current item from the results collection and delete it from wherever it is.
                CompanyWrapper current = Get(results, pointers, relatedCompany.CompanyRecordId, true);

                if (current == null)
                {
                    continue;
                }

                // keep track of where we're putting it.
                pointers[current.RecordID] = parentWrapper.RelatedCompanies;

                if (parentWrapper.RelatedCompanies == null)
                {
                    parentWrapper.RelatedCompanies = new List <CompanyWrapper>();
                }

                // add it to it's parent.
                parentWrapper.RelatedCompanies.Add(current);
            }

            // just select the values (the CompanyWrappers)
            List <CompanyWrapper> returnWrappers = results.Select(x => x.Value).ToList();

            // recursively sort all of the results
            Sort(returnWrappers);

            return(returnWrappers);
        }
Esempio n. 9
0
        protected void Page_Load(object sender, EventArgs e)
        {
            startDate     = Request[startDateParam];
            endDate       = Request[endDateParam];
            sortType      = Request[sortParam];
            sortDirection = Request[sortDirectionParam];
            report        = Request[reportParam];
            backUrl       = Request[backParam];
            DCDContext dc = new DCDContext();

            if (!IsPostBack)
            {
                DCDManager dcdMgr = new DCDManager();
                //if there is a report parameter, show just that import
                if (!string.IsNullOrEmpty(report))
                {
                    ImportLog import = dcdMgr.GetImportLogById(int.Parse(report));
                    if (import != null)
                    {
                        litSingleImportTitle.Text = "Import: " + import.Id + ", " + import.FileName + "(" + import.ImportStart.ToShortDateString() + " " + import.ImportStart.ToShortTimeString() + ")";
                        phImports.Visible         = false;
                        phSingleImport.Visible    = true;
                        if (!string.IsNullOrEmpty(backUrl))
                        {
                            hlBack.NavigateUrl = backUrl;
                        }
                        else
                        {
                            hlBack.Visible = false;
                        }
                        DataTable results = new DataTable();
                        results.Columns.Add("Type");
                        results.Columns.Add("RecordId");
                        results.Columns.Add("RecordNumber");
                        results.Columns["RecordId"].DataType = typeof(int);
                        results.Columns.Add("Time");
                        results.Columns.Add("Operation");
                        results.Columns.Add("Result");
                        results.Columns.Add("Notes");
                        results.Columns["Time"].DataType = typeof(DateTime);
                        List <IDCDRecordImportLog> records = dcdMgr.GetRecordsForImport(int.Parse(report));
                        foreach (IDCDRecordImportLog log in records)
                        {
                            DataRow row = results.NewRow();
                            if (log is DealRecordImportLog)
                            {
                                row["Type"] = "Deal";

                                Deal record = dcdMgr.GetDealByRecordId(log.RecordId.Value);
                                if (record != null)
                                {
                                    row["RecordNumber"] = record.RecordNumber;
                                }
                            }
                            else if (log is CompanyRecordImportLog)
                            {
                                row["Type"] = "Company";
                                Company record = dcdMgr.GetCompanyByRecordId(log.RecordId.Value);
                                if (record != null)
                                {
                                    row["RecordNumber"] = record.RecordNumber;
                                }
                            }
                            else if (log is DrugRecordImportLog)
                            {
                                row["Type"] = "Drug";
                                Drug record = dcdMgr.GetDrugByRecordId(log.RecordId.Value);
                                if (record != null)
                                {
                                    row["RecordNumber"] = record.RecordNumber;
                                }
                            }
                            row["RecordId"]  = log.RecordId;
                            row["Time"]      = log.TimeStamp.ToShortDateString() + " " + log.TimeStamp.ToShortTimeString();
                            row["Operation"] = log.Operation;
                            row["Result"]    = log.Result;
                            row["Notes"]     = log.Notes;
                            results.Rows.Add(row);
                        }

                        //set default sort
                        if (string.IsNullOrEmpty(sortType))
                        {
                            sortType = "Time";
                        }
                        if (string.IsNullOrEmpty(sortDirection))
                        {
                            sortDirection = "desc";
                        }

                        DataView view = new DataView(results);

                        view.Sort = sortType + " " + sortDirection;
                        dgSingleImport.ShowHeader = true;
                        dgSingleImport.DataSource = view;
                        dgSingleImport.DataBind();
                    }
                }
                else
                {
                    if (string.IsNullOrEmpty(startDate) || string.IsNullOrEmpty(endDate))
                    {
                        txtDateEnd.Text   = DateTime.Today.ToShortDateString();
                        txtDateStart.Text = DateTime.Today.Subtract(new TimeSpan(7, 0, 0, 0)).ToShortDateString();
                        return;
                    }
                    else
                    {
                        txtDateStart.Text = startDate;
                        txtDateEnd.Text   = endDate;
                    }
                    DateTime start;
                    DateTime end;
                    if (!DateTime.TryParse(startDate, out start))
                    {
                        dgResults.Visible = false;
                        return;
                    }
                    if (!DateTime.TryParse(endDate, out end))
                    {
                        dgResults.Visible = false;
                        return;
                    }
                    List <ImportLog> logs = dcdMgr.GetImports(start, end);

                    DataTable results = new DataTable();
                    results.Columns.Add("Id");
                    results.Columns["Id"].DataType = typeof(int);
                    results.Columns.Add("Start Date");
                    results.Columns.Add("End Date");
                    results.Columns.Add("File Name");
                    results.Columns.Add("Result");
                    results.Columns.Add("Total");
                    results.Columns.Add("Succeeded");
                    results.Columns.Add("Skipped");
                    results.Columns.Add("Failed");
                    results.Columns["Start Date"].DataType = typeof(DateTime);
                    results.Columns["End Date"].DataType   = typeof(DateTime);
                    results.Columns["Total"].DataType      = typeof(int);
                    results.Columns["Succeeded"].DataType  = typeof(int);
                    results.Columns["Skipped"].DataType    = typeof(int);
                    results.Columns["Failed"].DataType     = typeof(int);
                    foreach (ImportLog log in logs)
                    {
                        DataRow row = results.NewRow();
                        row["Id"]         = log.Id;
                        row["Start Date"] = log.ImportStart.ToShortDateString() + " " + log.ImportStart.ToShortTimeString();
                        row["End Date"]   = log.ImportEnd.ToShortDateString() + " " + log.ImportEnd.ToShortTimeString();
                        row["File Name"]  = log.FileName;
                        row["Result"]     = log.Result;
                        row["Total"]      = dcdMgr.GetTotalRecords(log);
                        row["Succeeded"]  = dcdMgr.GetTotalSuccess(log);
                        row["Skipped"]    = dcdMgr.GetTotalSkipped(log);
                        row["Failed"]     = dcdMgr.GetTotalFailed(log);
                        results.Rows.Add(row);
                    }

                    //set default sort
                    if (string.IsNullOrEmpty(sortType))
                    {
                        sortType = "Start Date";
                    }
                    if (string.IsNullOrEmpty(sortDirection))
                    {
                        sortDirection = "desc";
                    }

                    DataView view = new DataView(results);

                    view.Sort            = sortType + " " + sortDirection;
                    dgResults.ShowHeader = true;
                    dgResults.DataSource = view;
                    dgResults.DataBind();
                }
            }
        }