Esempio n. 1
0
        public static void SetDefaultFormValues(IInsertLiteratureItem form, EventArgs args)
        {
            ILiteratureItem entity = form.CurrentEntity as ILiteratureItem;

            entity.AuthorDate = DateTime.Today;
        }
    protected void Save(object sender, EventArgs e)
    {
        if (SendBy.DateTimeValue < DateTime.Now.AddDays(-1))
        {
            return;
        }
        if (RequestedFor.LookupResultValue != null)
        {
            IContextService        conserv = ApplicationContext.Current.Services.Get <IContextService>(true);
            Sage.Platform.TimeZone tz      = (Sage.Platform.TimeZone)conserv.GetContext("TimeZone");

            ILitRequest    lr             = EntityFactory.Create <ILitRequest>();
            SLXUserService slxUserService = ApplicationContext.Current.Services.Get <IUserService>() as SLXUserService;
            if (slxUserService != null)
            {
                lr.RequestUser = slxUserService.GetUser();
            }
            String[] arClientData = clientdata.Value.ToString().Split('|');
            lr.RequestDate = DateTime.Now.AddMinutes(tz.BiasForGivenDate(DateTime.Now));
            lr.CoverId     = arClientData[0];
            lr.Contact     = (IContact)RequestedFor.LookupResultValue;
            lr.ContactName = lr.Contact.LastName + ", " + lr.Contact.FirstName;
            lr.Description = Description.Text;
            lr.SendDate    = SendBy.DateTimeValue;
            lr.SendVia     = SendVia.PickListValue;
            lr.Priority    = Priority.PickListValue;
            lr.Options     = PrintLiteratureList.SelectedIndex;

            lr.Save();

            Activity act = new Activity();
            act.Type         = ActivityType.atLiterature;
            act.AccountId    = lr.Contact.Account.Id.ToString();
            act.AccountName  = lr.Contact.Account.AccountName;
            act.ContactId    = lr.Contact.Id.ToString();
            act.ContactName  = lr.ContactName;
            act.PhoneNumber  = lr.Contact.WorkPhone;
            act.StartDate    = (DateTime)lr.RequestDate;
            act.Duration     = 0;
            act.Description  = lr.Description;
            act.Alarm        = false;
            act.Timeless     = true;
            act.Rollover     = false;
            act.UserId       = lr.RequestUser.Id.ToString();
            act.OriginalDate = (DateTime)lr.RequestDate;
            act.Save();

            // save litRequest item
            double totalCost = 0.0;
            string coverId   = arClientData[0];

            // get cover name
            for (int i = 1; i < arClientData.Length; i++)
            {
                string[] clientData = arClientData[i].Split('=');
                string   litItemId  = clientData[0];
                int      qty        = Int32.Parse(clientData[1]);

                // get literature item cost
                ILiteratureItem litItem = EntityFactory.GetById <ILiteratureItem>(litItemId);
                totalCost += (double)qty * (litItem.Cost.HasValue ? (double)litItem.Cost.Value : (double)0.0);

                // add the literature request item
                ILitRequestItem lrItem = EntityFactory.Create <ILitRequestItem>();
                lrItem.Qty            = qty;
                lrItem.LitRequest     = lr;
                lrItem.LiteratureItem = litItem;

                lr.LitRequestItems.Add(lrItem);
            }

            lr.TotalCost = totalCost;

            // get cover name
            string coverName = GetCoverName(coverId);
            lr.CoverName = coverName;

            lr.Save();  //must make ids match, and id prop is read only, so....

            SynchronizeLitRequestId(act.Id, lr.Id.ToString());

            // re-get entity with new activity id
            lr = EntityFactory.GetById <ILitRequest>(act.Id);

            // process the lit request if handle fulfillment locally is checked
            if (chkHandleLocal.Checked)
            {
                // show printer dialog for fulfillment
                FulfillRequestLocally(lr);

                // call business rule to update the entity properties
                lr.FulfillLitRequest();
            }
            else
            {
                Response.Redirect("Contact.aspx?entityId=" + lr.Contact.Id.ToString());
            }
        }
    }