protected void cmdUpdate_Click(object sender, EventArgs e)
    {
        if (string.IsNullOrEmpty(pklTitle.PickListValue))
        {
            throw new Sage.Platform.Application.ValidationException("Status must be contain data");
        }
        else
        {
            GroupInfo groupInfo = GroupInfo.GetGroupInfo(lkpGroupName.SelectedValue);
            string WhereSQL = groupInfo.WhereSQL.Trim();
            string fromSQL = groupInfo.FromSQL.Trim();
            NHibernate.ISession session = new Sage.Platform.Orm.SessionScopeWrapper();
            string sql = string.Empty;
            if (string.IsNullOrEmpty(WhereSQL))
            {
                sql = "select distinct salesorderid from " + fromSQL;
            }
            else
            {
                sql = "select distinct salesorderid from " + fromSQL + " where " + WhereSQL + "";
            }
            System.Collections.IList test = session.CreateSQLQuery(sql).List();
            string ids = string.Empty;
            for (int i = 0; i < test.Count; ++i)
            {
                ids = "update salesorder set status='" + pklTitle.PickListValue.ToString().Trim() + "' where salesorderid='"+test[i].ToString() + "'";
                session.CreateSQLQuery(ids).ExecuteUpdate();
            }
            string alias = string.Empty;
            XmlDocument xmldoc = new XmlDocument();
            xmldoc.LoadXml(groupInfo.GroupXML);
            string selectSQL = ((XmlElement)xmldoc.GetElementsByTagName("selectsql")[0]).InnerText;
            XmlNodeList layoutNodes = xmldoc.GetElementsByTagName("layout");

            foreach (XmlElement node in layoutNodes)
            {
                XmlNodeList nAlias = node.GetElementsByTagName("caption");
                alias = nAlias[0].InnerText;
            }

            if (string.IsNullOrEmpty(WhereSQL))
            {
                sql = "Select " + selectSQL + " from " + fromSQL;
            }
            else
            {
                sql = "Select " + selectSQL + " from " + fromSQL + " where " + WhereSQL + "";
            }
            dsGroup.SelectCommand = sql;

        }
    }
        public static void OnAfterUpdateStep( ITicket ticket)
        {
            // TODO: Complete business rule implementation
               if (ticket.Area != null)
                {
                    NHibernate.ISession session = new Sage.Platform.Orm.SessionScopeWrapper();
                    string sql = "Select ownerid From ticketareaowner Where area = '"+ticket.Area+"'";
                    string fswon = session.CreateSQLQuery(sql).UniqueResult<string>();
                    string result = fswon;

                    if (!string.IsNullOrEmpty(result)){
                        ticket.AssignedTo = Sage.Platform.EntityFactory.GetRepository<Sage.Entity.Interfaces.ITicketAreaOwner>().FindFirstByProperty("Area", ticket.Area).AreaOwner;
                    }
                }
        }
        public static void OnAfterUpdateStep( ISalesOrder salesorder)
        {
            // TODO: Complete business rule implementation
                if ((salesorder.Actual==false || salesorder.Actual==null) && salesorder.Account.Status!="Active Client" && salesorder.Status=="Accepted Order"){
                    using (NHibernate.ISession session = new Sage.Platform.Orm.SessionScopeWrapper()){
                        string sql = "update Account set Status='Active Client' where AccountId='"+salesorder.Account.Id.ToString()+"'";
                        session.CreateQuery(sql)
                        .ExecuteUpdate();
                    }
                }

                if ((salesorder.Actual==false || salesorder.Actual==null) && salesorder.Account.Status!="Active Client" && salesorder.Status=="Accepted Order" && salesorder.Account.AccountConferon.Clientsince==null){
                    using (NHibernate.ISession session = new Sage.Platform.Orm.SessionScopeWrapper()){
                        string sql = "update AccountConferon set Clientsince='"+DateTime.Now+"' where AccountId='"+salesorder.Account.Id.ToString()+"'";
                        session.CreateQuery(sql)
                        .ExecuteUpdate();
                    }
                }
        }
    protected override void OnFormBound()
    {
        object sender = this;
        EventArgs e = EventArgs.Empty;
        dtsProducts.Bind();

        SystemInformation si = SystemInformationRules.GetSystemInfo();
        DelphiStreamReader stream = new DelphiStreamReader(si.Data);
        TValueType type;
        if (stream.FindProperty("MultiCurrency", out type))
        {
            if (type.Equals(TValueType.vaTrue))
            {
                //grdProducts.Columns[7].Visible = true;
            }
            else
            {
                //grdProducts.Columns[7].Visible = false;
            }
        }

        string user = BusinessRuleHelper.GetCurrentUser().Id.ToString();
        grdProducts.Columns[10].Visible = (_roleSecurityService.HasAccess("Entities/Opportunity/Edit"));
        int team =0;
            using (NHibernate.ISession session = new Sage.Platform.Orm.SessionScopeWrapper())
            {
                string sql = "select count(*) from seccodejoins sj join seccode s on s.seccodeid=sj.parentseccodeid where sj.childseccodeid in (select defaultseccodeid from usersecurity where userid='"+user.ToString()+"') and s.seccodetype='G' and s.seccodedesc='Training'";
                team = session.CreateSQLQuery(sql).UniqueResult<int>();
            }

            if (team > 0 || user.ToString().Trim() == "ADMIN")
            {
                grdProducts.Columns[12].Visible = true;
            }
            else
            {
                grdProducts.Columns[12].Visible = false;
            }
        grdProducts.Columns[13].Visible = (_roleSecurityService.HasAccess("Entities/Opportunity/Edit"));

        base.OnFormBound();
    }
    protected void grdProducts_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "Page")
            return;

        int rowIndex;
        if (Int32.TryParse(e.CommandArgument.ToString(), out rowIndex))
        {
            dtsProducts.SelectedIndex = rowIndex;
            object currentEntity = dtsProducts.Current;
            if ((currentEntity is Sage.Platform.ComponentModel.ComponentView) && !((Sage.Platform.ComponentModel.ComponentView)currentEntity).IsVirtualComponent)
                currentEntity = ((Sage.Platform.ComponentModel.ComponentView)currentEntity).Component;
            string id = String.Empty;
            //Check if this is an unpersisted entity and use its InstanceId
            if (Sage.Platform.WebPortal.PortalUtil.ObjectIsNewEntity(currentEntity))
            {
                if (grdProducts.DataKeys[0].Values.Count > 1)
                {
                    foreach (DictionaryEntry val in grdProducts.DataKeys[rowIndex].Values)
                    {
                        if (val.Key.ToString() == "InstanceId")
                        {
                            Guid instanceId = (Guid)val.Value;
                            dtsProducts.SetCurrentEntityByInstanceId(instanceId);
                            id = instanceId.ToString();
                            currentEntity = dtsProducts.Current;
                            if ((currentEntity is Sage.Platform.ComponentModel.ComponentView) && !((Sage.Platform.ComponentModel.ComponentView)currentEntity).IsVirtualComponent)
                                currentEntity = ((Sage.Platform.ComponentModel.ComponentView)currentEntity).Component;
                        }
                    }
                }
            }
            else
            {
                if (grdProducts.DataKeys[0].Values.Count > 1)
                {
                    foreach (DictionaryEntry val in grdProducts.DataKeys[rowIndex].Values)
                    {
                        if (val.Key.ToString() != "InstanceId")
                        {
                            id = val.Value.ToString();
                        }
                    }
                }
            }

            if (e.CommandName.Equals("Edit"))
            {
                if (DialogService != null)
                {
                    DialogService.SetSpecs(550, 800, "EditOpportunityProduct", HttpContext.GetLocalResourceObject(Request.Path,"EditOpportunityProduct.Title").ToString());
                    DialogService.EntityType = typeof (IOpportunityProduct);
                    DialogService.EntityID = id;
                    DialogService.ShowDialog();
                }
            }

             if (e.CommandName.Equals("CreateSO"))
            {
                if (DialogService != null)
                {

                    try
                    {

                        string productid = this.grdProducts.DataKeys[grdProducts.SelectedIndex].Values["Id"].ToString();
                        Sage.Entity.Interfaces.IOpportunityProduct opportunityproduct = Sage.Platform.EntityFactory.GetRepository<Sage.Entity.Interfaces.IOpportunityProduct>().FindFirstByProperty("Id", productid);
                        if (opportunityproduct.Status != "Execution")
                        {
                            opportunityproduct.OpportunityProductCI.Won = true;
                            opportunityproduct.CloseProbability = 100;
                            opportunityproduct.Status = "Execution";
                            opportunityproduct.ActualClose = DateTime.Now;
                        }

                        //DialogService.ShowMessage(opportunityproduct.Opportunity.Description);
                        //DialogService.SetSpecs(550, 800, "EditOpportunityProduct", HttpContext.GetLocalResourceObject(Request.Path,"EditOpportunityProduct.Title").ToString());
                        //DialogService.EntityType = typeof (IOpportunityProduct);
                        //DialogService.EntityID = id;
                        //DialogService.ShowDialog();
                        //throw new Sage.Platform.Application.ValidationException(productid);

                        using (NHibernate.ISession _session = new Sage.Platform.Orm.SessionScopeWrapper()){

                        string strSQL = "select max(documentid)+1 from salesorder where len(documentid)>5";
                        int docid = _session.CreateSQLQuery(strSQL).UniqueResult<int>();

                        //--------
                        Sage.Entity.Interfaces.ISalesOrder saleso = Sage.Platform.EntityFactory.Create<Sage.Entity.Interfaces.ISalesOrder>();
                        if (opportunityproduct.Opportunity.Account!=null) {
                        saleso.Account = opportunityproduct.Opportunity.Account;
                        }
                        if (opportunityproduct.Opportunity!=null) {
                        saleso.Opportunity = opportunityproduct.Opportunity;
                        }

                        if (opportunityproduct.ExtendedPrice!=null){
                        saleso.OrderTotal = (double)opportunityproduct.ExtendedPrice;
                        } else
                        {
                        saleso.OrderTotal = 0;
                        }

                        if (opportunityproduct.ExtendedPrice!=null){
                        saleso.Totalcommissionable = (double)opportunityproduct.ExtendedPrice;
                        } else {
                        saleso.Totalcommissionable = 0;
                        }

                        saleso.OrderType = "Regular Order";

                        saleso.DocumentId = docid.ToString();
                        saleso.Status = "Open Order";

                        saleso.UserId = opportunityproduct.Opportunity.AccountManager.Id.ToString();

                        if (opportunityproduct.Opportunity.OpportunityCIUDF.Accountmanagerid2!=null){
                        saleso.UserID2 = opportunityproduct.Opportunity.OpportunityCIUDF.Accountmanagerid2.ToString();
                        }

                        if (opportunityproduct.Opportunity.Owner!=null){
                        saleso.Owner = opportunityproduct.Opportunity.Owner;
                        }

                        saleso.Actual = false;
                        Sage.Entity.Interfaces.ISalesorderdetail sodetail = Sage.Platform.EntityFactory.Create<Sage.Entity.Interfaces.ISalesorderdetail>();
                        sodetail.SalesOrder = saleso;
                        sodetail.ProductId = opportunityproduct.Product.Id.ToString();
                        if (opportunityproduct.OpportunityProductCI.Other_fees != null || opportunityproduct.OpportunityProductCI.Other_fees > 0)
                        {

                                if (opportunityproduct.CalculatedPrice!=null){
                                    sodetail.Calcprice 		= (double)opportunityproduct.CalculatedPrice;
                                } else {
                                    sodetail.Calcprice 	= 0;
                                }

                                if (opportunityproduct.ExtendedPrice!=null){
                                    sodetail.Extendedprice 	= (double)opportunityproduct.ExtendedPrice;
                                } else {
                                    sodetail.Extendedprice = 0;
                                }

                                if (opportunityproduct.Price!=null){
                                    sodetail.Price 			= (double)opportunityproduct.Price;
                                } else {
                                    sodetail.Price = 0;
                                }

                                if (opportunityproduct.OpportunityProductCI.Commission!=null){
                                    sodetail.Commission 	= opportunityproduct.OpportunityProductCI.Commission;
                                }	else {
                                    sodetail.Commission = 0;
                                }

                                if (opportunityproduct.OpportunityProductCI.Discount!=null){
                                    sodetail.Discount 		= opportunityproduct.OpportunityProductCI.Discount;
                                } else {
                                    sodetail.Discount = 0;
                                }

                                if (opportunityproduct.OpportunityProductCI.Onsite_fees!=null){
                                    sodetail.Onsite_fees 	= (decimal) opportunityproduct.OpportunityProductCI.Onsite_fees;
                                }
                                else
                                {
                                    sodetail.Onsite_fees = 0;
                                }

                                if (opportunityproduct.OpportunityProductCI.Other_fees!=null){
                                    sodetail.Other_fees 	= (decimal) opportunityproduct.OpportunityProductCI.Other_fees;
                                }
                                else {
                                    sodetail.Other_fees = 0;
                                }

                                if (opportunityproduct.OpportunityProductCI.Num!=null){
                                sodetail.Num = opportunityproduct.OpportunityProductCI.Num;
                                }
                        }

                        saleso.OrderDate = DateTime.Now;
                        saleso.Salesorderdetails.Add(sodetail);
                        saleso.Save();
                        DialogService.ShowMessage("Sales Order Creation process was completed successfully.");
                        }
                    }
                    catch (Exception) {
                        //Response.Redirect(Request.Url.ToString());
                        throw new Sage.Platform.Application.ValidationException("Creation Process not completed. Please Check that this opportunity have a Primary Contact Related.");
                    }
                }
            }

            if (e.CommandName.Equals("Delete"))
            {
                Sage.Entity.Interfaces.IOpportunity mainentity = this.BindingSource.Current as Sage.Entity.Interfaces.IOpportunity;
                if (mainentity != null)
                {
                    IOpportunityProduct childEntity = null;
                    if((currentEntity != null) && (currentEntity is IOpportunityProduct))
                    {
                        childEntity = (IOpportunityProduct)currentEntity;
                    }
                    else if (id != null)
                    {
                        childEntity = Sage.Platform.EntityFactory.GetById<IOpportunityProduct>(id);
                    }
                    if (childEntity != null)
                    {
                        mainentity.Products.Remove(childEntity);
                        if ((childEntity.PersistentState & Sage.Platform.Orm.Interfaces.PersistentState.New) <= 0)
                        {
                            childEntity.Delete();
                        }

                        if (mainentity.Products.Count != 0)
                        {
                            double salesPotential = 0;
                            foreach (IOpportunityProduct oppProduct in mainentity.Products)
                            {
                                if (oppProduct.Sort > rowIndex + 1)
                                {
                                    oppProduct.Sort--;
                                }
                                salesPotential = salesPotential + (double)oppProduct.ExtendedPrice.Value;
                            }
                            mainentity.SalesPotential = salesPotential;

                            // this save prevented the user from deleting rows in the products grid.  The first delete
                            // would work fine, but then the save caused the application to lose track of the entity
                            // object so the object information didn't match the information shown on the page.

                            //mainentity.Save();
                        }
                    }
                }
            }
        }
        grdProducts_refresh();
    }
    /// <summary>
    /// Handles the Click event of the btnOK control.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
    protected void btnOK_OnClick(object sender, EventArgs e)
    {
        bool success = false;
        UpdatePropertyMappings(SessionMergeArguments.MergeProvider.MergeMaps);

        string recordOverWrite = Request.Form["rdoRecordOverwrite"];
        if (recordOverWrite != null)
        {
            SessionMergeArguments.MergeProvider.RecordOverwrite = recordOverWrite.Equals("SourceWins")
                                                                      ? MergeOverwrite.sourceWins
                                                                      : MergeOverwrite.targetWins;
        }

        Type type = SessionMergeArguments.MergeProvider.Target.EntityType;
        if (type.Equals(typeof (IAccount)))
        {
            IAccount account = (IAccount) SessionMergeArguments.MergeProvider.Target.EntityData;
            success = account.MergeAccount(SessionMergeArguments.MergeProvider);
        }
        else if (type.Equals(typeof (IContact)))
        {
            IContact contact = (IContact) SessionMergeArguments.MergeProvider.Target.EntityData;
            success = contact.MergeContact(SessionMergeArguments.MergeProvider);
        }
        if (success)
        {
            using (ISession session = new Sage.Platform.Orm.SessionScopeWrapper(true))
            {
                string entityId = SessionMergeArguments.MergeProvider.Source.EntityId;
                IPersistentEntity source = Sage.Platform.EntityFactory.GetById(type, entityId) as IPersistentEntity;
                source.Delete();
                EntityService.RemoveEntityHistory(type, source);
                Response.Redirect(String.Format("{0}.aspx", GetEntityName(type)));
            }
        }
    }
    /// <summary>
    /// Handles the Click event of the btnOK control.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
    protected void btnOK_OnClick(object sender, EventArgs e)
    {
        UpdatePropertyMappings(SessionMergeArguments.MergeProvider.MergeMaps);
        string recordOverWrite = Request.Form["rdoRecordOverwrite"];
        if (recordOverWrite != null)
        {
            SessionMergeArguments.MergeProvider.RecordOverwrite = recordOverWrite.Equals("SourceWins")
                                                                      ? MergeOverwrite.sourceWins
                                                                      : MergeOverwrite.targetWins;
        }

        if (Sage.SalesLogix.BusinessRules.BusinessRuleHelper.MergeRecords(SessionMergeArguments))
        {
            using (ISession session = new Sage.Platform.Orm.SessionScopeWrapper(true))
            {
                Type type = SessionMergeArguments.MergeProvider.Target.EntityType;
                string entityId = SessionMergeArguments.MergeProvider.Source.EntityId;
                IPersistentEntity source = Sage.Platform.EntityFactory.GetById(type, entityId) as IPersistentEntity;
                source.Delete();
                EntityService.RemoveEntityHistory(type, source);
                Response.Redirect(String.Format("{0}.aspx", GetEntityName(type)));
            }
        }
    }
    /// <summary>
    /// Handles the OnClick event of the btnNext control.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
    protected void btnNext_OnClick(object sender, EventArgs e)
    {
        if (DialogService.DialogParameters.ContainsKey("mergeArguments"))
        {
            UpdatePropertyMappings(SessionMergeArguments.MergeProvider.MergeMaps);
            string recordOverWrite = Request.Form["rdoRecordOverwrite"];
            if (recordOverWrite != null)
            {
                SessionMergeArguments.MergeProvider.RecordOverwrite = recordOverWrite.Equals("SourceWins")
                                                                          ? MergeOverwrite.sourceWins
                                                                          : MergeOverwrite.targetWins;
            }

            if (SessionMergeArguments.SourceEntityType == typeof (ILead))
            {
                using (ISession session = new Sage.Platform.Orm.SessionScopeWrapper(true))
                {
                    Type type = SessionMergeArguments.MergeProvider.Source.EntityType;
                    string entityId = SessionMergeArguments.MergeProvider.Source.EntityId;
                    IPersistentEntity source = Sage.Platform.EntityFactory.GetById(type, entityId) as IPersistentEntity;
                    if (source != null)
                    {
                        source.Delete();
                        EntityService.RemoveEntityHistory(type, source);
                    }
                    Response.Redirect(String.Format("{0}.aspx", GetEntityName(SessionMergeArguments.MergeProvider.Target.EntityType)));
                }
            }
            else
            {
                ShowDialog("MergeAddress", GetLocalResourceObject("LinkAddress.Caption").ToString(), 600, 1200);
            }
        }
        else
        {
            UpdatePropertyMappings((IEnumerable<MergePropertyMap>)IntegrationManager.MergePropertyMaps);
            ShowDialog("MergeChildren", GetLocalResourceObject("LinkAddress.Caption").ToString(), 600, 1200);
        }
    }
Example #9
0
    protected void Page_Load(object sender, EventArgs e)
    {
        string vlabelSOGrid = "";
        string pSalesOrderId = Request.QueryString["entityId"];//(string)((WebPortalPage)Page).;
        NHibernate.ISession session = new Sage.Platform.Orm.SessionScopeWrapper();
        string sql = string.Empty;

        Sage.Entity.Interfaces.ISalesOrder saleso = Sage.Platform.EntityFactory.GetById<Sage.Entity.Interfaces.ISalesOrder>(pSalesOrderId);

        bool vtype = saleso.Actual.Value;

        if (vtype == true)
        {
            lblSalesOrderType.Text = "Actual Sales Order";
            lblTotRevenuelbl.Text  = "Total Actual Revenue";
            vlabelSOGrid = "Revenue";
        }
        else
        {
            lblSalesOrderType.Text = "Anticipated Sales Order";
            lblTotRevenuelbl.Text = "Total Anticipated Revenue";
            vlabelSOGrid = "Revenue";
        }

        //Meeting Id
        lblEventId.Text = saleso.Opportunity.OpportunityCIUDF.Meeting_Id.ToString();

        //Sales Order No
        lblSalesOrderNo.Text = saleso.DocumentId.ToString();

        //Event Name
        lblEventName.Text = saleso.Opportunity.Description.ToString();

        //Bill To Account
        if (saleso.Billtoaccount != null)
        {
            sql = "Select Account from Account where AccountID ='" + saleso.Billtoaccount.ToString() + "'";
            string vBillToAccount = session.CreateSQLQuery(sql).UniqueResult<string>();
            lblBillToAccount.Text = vBillToAccount;
        }
        else
        {
            lblBillToAccount.Text = "";
        }

        //Po No
        if (!string.IsNullOrEmpty(saleso.CustomerPurchaseOrderNumber))
        {
            lblPoNo.Text = saleso.CustomerPurchaseOrderNumber.ToString();
        }
        else
        {
            lblPoNo.Text = "";
        }
        //Project ID
        if (string.IsNullOrEmpty(saleso.OriginaldocumentId))
        {
            lblProjectId.Text = "";
        }
        else
        {
          lblProjectId.Text = saleso.OriginaldocumentId.ToString();
        }

        //Account Name
        lblAccountName.Text = saleso.Account.ToString();

        //Account Status
        lblAccountStatus.Text = saleso.Account.Status.ToString();

        //Main Arrival
        if (saleso.Opportunity.OpportunityCIUDF.Main_arrival_Date == null)
        {
            lblMainArrival.Text = "";
        }
        else
        {
            DateTime vMainArrival = saleso.Opportunity.OpportunityCIUDF.Main_arrival_Date.Value;
            lblMainArrival.Text = vMainArrival.ToShortDateString();
        }

        //Main Departure

        if (saleso.Opportunity.OpportunityCIUDF.Main_departure_Date == null)
        {
            lblMainDeparture.Text = "";
        }
        else
        {
            DateTime vMainDeparture = saleso.Opportunity.OpportunityCIUDF.Main_departure_Date.Value;
            lblMainDeparture.Text = vMainDeparture.ToShortDateString();
        }

         //Client Account Section
        //Cust NO
        sql = "Select AccountingSystemId from AccountingInfo where AccountID ='" + saleso.Account.Id.ToString() + "'";
        string vCustNoCA = session.CreateSQLQuery(sql).UniqueResult<string>();
        lblCustNoCA.Text = vCustNoCA;

        //Name
        sql = "Select Account from Account where AccountID  ='" + saleso.Account.Id.ToString() + "'";
        string vNameCA = session.CreateSQLQuery(sql).UniqueResult<string>();
        lblNameCA.Text = vNameCA;

        //Address
        sql = "Select Address1 from Address where EntityId ='" + saleso.Account.Id.ToString() + "'";
        string vAddressCA = session.CreateSQLQuery(sql).UniqueResult<string>();
        lblAddressCA.Text = vAddressCA;

        sql = "Select Address2 from Address where EntityId ='" + saleso.Account.Id.ToString() + "'";
        string vAddress2CA = session.CreateSQLQuery(sql).UniqueResult<string>();
        lblAddress2CA.Text = vAddress2CA;

        sql = "Select Address3 from Address where EntityId ='" + saleso.Account.Id.ToString() + "'";
        string vAddress3CA = session.CreateSQLQuery(sql).UniqueResult<string>();
        lblAddress3CA.Text = vAddress3CA;

        sql = "Select State from Address where EntityId ='" + saleso.Account.Id.ToString() + "'";
        string vAddress4CA = session.CreateSQLQuery(sql).UniqueResult<string>();
        lblAddress4CA.Text = vAddress4CA;

        sql = "Select ', '+PostalCode from Address where EntityId ='" + saleso.Account.Id.ToString() + "'";
        string vAddress5CA = session.CreateSQLQuery(sql).UniqueResult<string>();
        lblAddress5CA.Text = vAddress5CA;

        //Phone
        sql = "Select MainPhone from Account where AccountID ='" + saleso.Account.Id.ToString() + "'";
        string vPhoneCA = session.CreateSQLQuery(sql).UniqueResult<string>();
        lblPhoneCA.Text = vPhoneCA;

        //Fax
        sql = "Select Fax from Account where AccountID ='" + saleso.Account.Id.ToString() + "'";
        string vFaxCA = session.CreateSQLQuery(sql).UniqueResult<string>();
        lblFaxCA.Text = vFaxCA;

        if (saleso.Billtocontact != null)
        {
            //Contact
            sql = "Select FirstName+' '+lastname from Contact where ContactID ='" + saleso.Billtocontact.ToString() + "'";
            string vContactCA = session.CreateSQLQuery(sql).UniqueResult<string>();
            lblContactCA.Text = vContactCA;

            //Bill to Account Section
            //Cust NO
            sql = "Select AccountingSystemId from AccountingInfo where AccountID ='" + saleso.Billtoaccount.ToString() + "'";
            string vCustNoBA = session.CreateSQLQuery(sql).UniqueResult<string>();
            lblCustNoBA.Text = vCustNoBA;

            //Name
            sql = "Select Account from Account where AccountID  ='" + saleso.Billtoaccount.ToString() + "'";
            string vNameBA = session.CreateSQLQuery(sql).UniqueResult<string>();
            lblNameBA.Text = vNameBA;

            //Address
            sql = "Select Address1 from Address where EntityId ='" + saleso.Billtoaccount.ToString() + "'";
            string vAddressBA = session.CreateSQLQuery(sql).UniqueResult<string>();
            lblAddressBA.Text = vAddressBA;

            sql = "Select Address2 from Address where EntityId ='" + saleso.Account.Id.ToString() + "'";
            string vAddress2BA = session.CreateSQLQuery(sql).UniqueResult<string>();
            lblAddress2BA.Text = vAddress2BA;

            sql = "Select Address3 from Address where EntityId ='" + saleso.Billtoaccount.ToString() + "'";
            string vAddress3BA = session.CreateSQLQuery(sql).UniqueResult<string>();
            lblAddress3BA.Text = vAddress3BA;

            sql = "Select State from Address where EntityId ='" + saleso.Billtoaccount.ToString() + "'";
            string vAddress4BA = session.CreateSQLQuery(sql).UniqueResult<string>();
            lblAddress4BA.Text = vAddress4BA;

            sql = "Select ', '+PostalCode from Address where EntityId ='" + saleso.Billtoaccount.ToString() + "'";
            string vAddress5BA = session.CreateSQLQuery(sql).UniqueResult<string>();
            lblAddress5BA.Text = vAddress5BA;

            //Contact
            sql = "Select FirstName+' '+lastname from Contact where ContactID  ='" + saleso.Billtocontact.ToString() + "'";
            string vContactBA = session.CreateSQLQuery(sql).UniqueResult<string>();
            lblContactBA.Text = vContactBA;
        }
        else
        {
            lblContactCA.Text = "";
            lblCustNoBA.Text = "";
            lblNameBA.Text = "";
            lblAddressBA.Text = "";
            lblAddress2BA.Text = "";
            lblAddress3BA.Text = "";
            lblAddress4BA.Text = "";
            lblAddress5BA.Text = "";
            lblContactBA.Text = "";
        }
        //Phone

        if (saleso.Billtoaccount != null)
        {
            sql = "Select MainPhone from Account where AccountID ='" + saleso.Billtoaccount.ToString() + "'";
            string vPhoneBA = session.CreateSQLQuery(sql).UniqueResult<string>();
            lblPhoneBA.Text = vPhoneBA;

            //Fax
            sql = "Select Fax from Account where AccountID ='" + saleso.Billtoaccount.ToString() + "'";
            string vFaxBA = session.CreateSQLQuery(sql).UniqueResult<string>();
            lblFaxBA.Text = vFaxBA;
        }
        else
        {
            lblPhoneBA.Text = "";
            lblFaxBA.Text = "";
        }

        //Sales Order Section
        //Account Owner
        lblAccountOwner.Text = saleso.Account.AccountManager.ToString();

        //Order Owner
        lblOrderOwner.Text = saleso.Opportunity.AccountManager.ToString();

        if (saleso.SalesCommission != null)
        {
            lblOrderOwnerComm.Text = saleso.SalesCommission.ToString();
            lblRoomComm.Text = saleso.SalesCommission.ToString();
        }
        else
        {
            lblOrderOwnerComm.Text = "";
            lblRoomComm.Text = "";
        }

        //Sec Owner
        if (saleso.UserID2 != null)
        {
            sql = "Select username from UserInfo where UserId ='" + saleso.UserID2.ToString() + "'";
            string vSecOwner = session.CreateSQLQuery(sql).UniqueResult<string>();
            lblSecOwner.Text = vSecOwner;
        }
        else {
            lblSecOwner.Text = "";
        }

        if (saleso.Salescommission2 != null){
        lblSecOwnerComm.Text  = saleso.Salescommission2.ToString();
        } else
        {
            lblSecOwnerComm.Text  = "";
        }

        //Addtl Owner
        if (saleso.UserID3 != null)
        {
            sql = "Select username from UserInfo where UserId ='" + saleso.UserID3.ToString() + "'";
            string vAddlOwner = session.CreateSQLQuery(sql).UniqueResult<string>();
            lblAddlOwner.Text = vAddlOwner;
        }
        else
        {
            lblAddlOwner.Text = "";
        }

        //Mem
        if (saleso.MEM != null)
        {
            lblMem.Text = saleso.MEM.ToString();
        }
        else
        {
            lblMem.Text = "";
        }

        //Market
        if (saleso.Account.AccountConferon.Market != null)
        {
            lblMarket.Text = saleso.Account.AccountConferon.Market.ToString();
        }
        else
        {
            lblMarket.Text = "";
        }

        //Comments
        if (saleso.Comments != null)
        {
            lblComments.Text = saleso.Comments.ToString();
        }
        else
        {
            lblComments.Text = "";
        }

        //Domains
        if (saleso.Opportunity.Owner.OwnerDescription != null)
        {
            lblDomain.Text = saleso.Opportunity.Owner.OwnerDescription.ToString();
        }
        else
        {
            lblDomain.Text = "";
        }

        //Drop Off%
        if (saleso.Discount != null)
        {
            lblDropOff.Text = saleso.Discount.ToString();
        }
        else
        {
            lblDropOff.Text = "";
        }

        //Compare Date

        //Total Revenue
        if (saleso.OrderTotal != null)
        {
            lblTotRevenue.Text = string.Format("{0:C}",saleso.OrderTotal);
        }
        else {
            lblTotRevenue.Text = "0.00";
        }

        //Detail grid
        dsDetail.ProviderName = "System.Data.OleDb";
        dsDetail.ConnectionString = ApplicationContext.Current.Services.Get<IDataService>().GetConnectionString();

        dsDetail.SelectCommand = "select p.name Service,s.Num Quantity,'$'+CONVERT(VARCHAR,CONVERT(MONEY,s.rate),1) Rate,'$'+CONVERT(VARCHAR,CONVERT(MONEY,s.extendedprice),1) " + vlabelSOGrid + " from salesorderdetail s,product p where s.productid = p.productid and s.salesorderid = '" + saleso.Id.ToString() + "'";

        //Roomblock Section
        sql = "select count(*) from salesorderdetail s,product p where s.productid = p.productid and name = 'Hotel Commissions' and s.salesorderid  ='" + saleso.Id.ToString() + "'";
        int vcount = session.CreateSQLQuery(sql).UniqueResult<int>();

        if (vcount>0){  //Exists Hotel Commissions
            lblRoomBMessage.Text  = "Roomblock";
            lblConcessions.Text = "Concessions:";

            if (saleso.Concessions.Con1 != null)
            {
                lblCon.Text = saleso.Concessions.Con1.ToString();
            }
            else
            {
                lblCon.Text = "";
            }

            if (saleso.Concessions.Con2 != null)
            {
                lblCon0.Text = saleso.Concessions.Con2.ToString();
            }
            else
            {
                lblCon0.Text = "";
            }

            if (saleso.Concessions.Con3 != null)
            {
                lblCon1.Text = saleso.Concessions.Con3.ToString();
            }
            else
            {
                lblCon1.Text = "";
            }

            if (saleso.Concessions.Con4 != null)
            {
                lblCon2.Text = saleso.Concessions.Con4.ToString();
            }
            else
            {
                lblCon2.Text = "";
            }

            if (saleso.Concessions.Con5 != null)
            {
                lblCon3.Text = saleso.Concessions.Con5.ToString();
            }
            else
            {
                lblCon3.Text = "";
            }

            if (saleso.Concessions.Con6 != null)
            {
                lblCon4.Text = saleso.Concessions.Con6.ToString();
            }
            else
            {
                lblCon4.Text = "";
            }

            if (saleso.Concessions.Con7 != null)
            {
                lblCon5.Text = saleso.Concessions.Con7.ToString();
            }
            else
            {
                lblCon5.Text = "";
            }

            if (saleso.Concessions.Con8 != null)
            {
                lblCon6.Text = saleso.Concessions.Con8.ToString();
            }
            else
            {
                lblCon6.Text = "";
            }

            if (saleso.Concessions.Con9 != null)
            {
                lblCon7.Text = saleso.Concessions.Con9.ToString();
            }
            else
            {
                lblCon7.Text = "";
            }

            if (saleso.Concessions.Con10 != null)
            {
                lblCon8.Text = saleso.Concessions.Con10.ToString();
            }
            else
            {
                lblCon8.Text = "";
            }

            if (saleso.Concessions.Qty1 != null)
            {
                lblConQ.Text = saleso.Concessions.Qty1.ToString();
            }
            else
            {
                lblConQ.Text = "";
            }

            if (saleso.Concessions.Qty2 != null)
            {
                lblConQ0.Text = saleso.Concessions.Qty2.ToString();
            }
            else
            {
                lblConQ0.Text = "";
            }

            if (saleso.Concessions.Qty3 != null)
            {
                lblConQ1.Text = saleso.Concessions.Qty3.ToString();
            }
            else
            {
                lblConQ1.Text = "";
            }

            if (saleso.Concessions.Qty4 != null)
            {
                lblConQ2.Text = saleso.Concessions.Qty4.ToString();
            }
            else
            {
                lblConQ2.Text = "";
            }

            if (saleso.Concessions.Qty5 != null)
            {
                lblConQ3.Text = saleso.Concessions.Qty5.ToString();
            }
            else
            {
                lblConQ3.Text = "";
            }

            if (saleso.Concessions.Qty6 != null)
            {
                lblConQ4.Text = saleso.Concessions.Qty6.ToString();
            }
            else
            {
                lblConQ4.Text = "";
            }

            if (saleso.Concessions.Qty7 != null)
            {
                lblConQ5.Text = saleso.Concessions.Qty7.ToString();
            }
            else
            {
                lblConQ5.Text = "";
            }

            if (saleso.Concessions.Qty8 != null)
            {
                lblConQ6.Text = saleso.Concessions.Qty8.ToString();
            }
            else
            {
                lblConQ6.Text = "";
            }

            if (saleso.Concessions.Qty9 != null)
            {
                lblConQ7.Text = saleso.Concessions.Qty9.ToString();
            }
            else
            {
                lblConQ7.Text = "";
            }

            if (saleso.Concessions.Qty10 != null)
            {
                lblConQ8.Text = saleso.Concessions.Qty10.ToString();
            }
            else
            {
                lblConQ8.Text = "";
            }

        } else {
            lblRoomBMessage.Text = "You won't see a Room Block or Concessions unless you are entering a HOTEL COMMISSIONS type service";
            lblConcessions.Visible = false;
            lblConQ.Visible = false;
            lblConQ0.Visible = false;
            lblConQ1.Visible = false;
            lblConQ2.Visible = false;
            lblConQ3.Visible = false;
            lblConQ4.Visible = false;
            lblConQ5.Visible = false;
            lblConQ6.Visible = false;
            lblConQ7.Visible = false;
            lblConQ8.Visible = false;
            lblCon.Visible = false;
            lblCon0.Visible = false;
            lblCon1.Visible = false;
            lblCon2.Visible = false;
            lblCon3.Visible = false;
            lblCon4.Visible = false;
            lblCon5.Visible = false;
            lblCon6.Visible = false;
            lblCon7.Visible = false;
            lblCon8.Visible = false;
        }
    }
    /// <summary>
    /// Handles the Click event of the btnOK control.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
    protected void btnOK_OnClick(object sender, EventArgs e)
    {
        bool success = false;
        UpdatePropertyMappings(SessionMergeArguments.MergeProvider.MergeMaps);

        string recordOverWrite = Request.Form["rdoRecordOverwrite"];
        if (recordOverWrite != null)
        {
            SessionMergeArguments.MergeProvider.RecordOverwrite = recordOverWrite.Equals("SourceWins")
                                                                      ? MergeOverwrite.sourceWins
                                                                      : MergeOverwrite.targetWins;
        }

        Type type = SessionMergeArguments.MergeProvider.Target.EntityType;
        if (type.Equals(typeof (IAccount)))
        {
            IAccount account = (IAccount) SessionMergeArguments.MergeProvider.Target.EntityData;
            success = account.MergeAccount(SessionMergeArguments.MergeProvider);
        }
        else if (type.Equals(typeof (IContact)))
        {
            IContact contact = (IContact) SessionMergeArguments.MergeProvider.Target.EntityData;
            success = contact.MergeContact(SessionMergeArguments.MergeProvider);
        }
        else if (type.Equals(typeof(ILead)))
        {
            ILead lead = (ILead)SessionMergeArguments.MergeProvider.Target.EntityData;
            success = lead.MergeLead(SessionMergeArguments.MergeProvider);
        }
        if (success)
        {
            using (ISession session = new Sage.Platform.Orm.SessionScopeWrapper(true))
            {
                string entityId = SessionMergeArguments.MergeProvider.Source.EntityId;
                IPersistentEntity source = Sage.Platform.EntityFactory.GetById(type, entityId) as IPersistentEntity;
                source.Delete();
                EntityService.RemoveEntityHistory(type, source);
                //Response.Redirect(String.Format("{0}.aspx", GetEntityName(type)));  \\ Commented out by ssommerfeldt
                ScriptManager.RegisterStartupScript(this, GetType(), "refresh", "window.setTimeout('window.location.reload(true);',50);", true);
            }
        }
    }
    protected void lkpGroupName_TextChanged(object sender, EventArgs e)
    {
        GroupInfo groupInfo = GroupInfo.GetGroupInfo(lkpGroupName.SelectedValue);
        string WhereSQL = groupInfo.WhereSQL.Trim();
        string fromSQL = groupInfo.FromSQL.Trim();
        NHibernate.ISession session = new Sage.Platform.Orm.SessionScopeWrapper();
        string sql = string.Empty;
        if (string.IsNullOrEmpty(WhereSQL)){
            sql = "Select count(*) from "+fromSQL;}
        else {
            sql = "Select count(*) from "+fromSQL+" where " + WhereSQL + "";
        }
        int fswon = session.CreateSQLQuery(sql).UniqueResult<int>();
        txtNoSO.Text = fswon.ToString();

        pklTitle.PickListValue = string.Empty;

        string alias = string.Empty;
        XmlDocument xmldoc = new XmlDocument();
        xmldoc.LoadXml(groupInfo.GroupXML);
        string selectSQL = ((XmlElement)xmldoc.GetElementsByTagName("selectsql")[0]).InnerText;
        XmlNodeList layoutNodes = xmldoc.GetElementsByTagName("layout");

            foreach (XmlElement node in layoutNodes)
        {
            XmlNodeList nAlias = node.GetElementsByTagName("caption");
            alias = nAlias[0].InnerText;
        }

            if (string.IsNullOrEmpty(WhereSQL))
            {
                sql = "Select "+selectSQL+" from " + fromSQL;
            }
            else
            {
                sql = "Select " + selectSQL + " from " + fromSQL + " where " + WhereSQL + "";
            }
            dsGroup.SelectCommand = sql;
    }
Example #12
0
    /// <summary>
    /// Handles the Click event of the btnOK control.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
    protected void btnOK_OnClick(object sender, EventArgs e)
    {
        bool success = false;
        UpdatePropertyMappings(SessionMergeArguments.MergeProvider.MergeMaps);

        string recordOverWrite = Request.Form["rdoRecordOverwrite"];
        if (recordOverWrite != null)
        {
            SessionMergeArguments.MergeProvider.RecordOverwrite = recordOverWrite.Equals("SourceWins")
                                                                      ? MergeOverwrite.sourceWins
                                                                      : MergeOverwrite.targetWins;
        }

        Type type = SessionMergeArguments.MergeProvider.Target.EntityType;
        if (type.Equals(typeof (IAccount)))
        {
            IAccount account = (IAccount) SessionMergeArguments.MergeProvider.Target.EntityData;
            success = account.MergeAccount(SessionMergeArguments.MergeProvider);

            //Merge the custom child records
            if(success) {
                string sourceId = ((IAccount)SessionMergeArguments.MergeProvider.Source.EntityData).Id.ToString();
                string targetId = ((IAccount)SessionMergeArguments.MergeProvider.Target.EntityData).Id.ToString();

                if(!String.IsNullOrEmpty (sourceId) && !String.IsNullOrEmpty (targetId)) {
                    //Update child records
                    string sql = String.Format("Update AccountDealerCode Set AccountId = '{0}' Where AccountId = '{1}'", targetId, sourceId);

                    Sage.Platform.Data.IDataService datasvc = Sage.Platform.Application.ApplicationContext.Current.Services.Get<Sage.Platform.Data.IDataService>();
                    using (System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection(datasvc.GetConnectionString()))
                    {
                        conn.Open();
                        using (System.Data.OleDb.OleDbCommand cmd = new System.Data.OleDb.OleDbCommand(sql, conn))
                        {
                            cmd.ExecuteNonQuery();
                        }
                    }
                }
            }

        }
        else if (type.Equals(typeof (IContact)))
        {
            IContact contact = (IContact) SessionMergeArguments.MergeProvider.Target.EntityData;
            success = contact.MergeContact(SessionMergeArguments.MergeProvider);

            //Merge the custom child records
            if(success) {
                string sourceId = ((IContact)SessionMergeArguments.MergeProvider.Source.EntityData).Id.ToString();
                string targetId = ((IContact)SessionMergeArguments.MergeProvider.Target.EntityData).Id.ToString();

                if(!String.IsNullOrEmpty (sourceId) && !String.IsNullOrEmpty (targetId)) {
                    //Update child records
                    string sql = String.Format("Update ContactRepCode Set ContactId = '{0}' Where ContactId = '{1}'", targetId, sourceId);

                    Sage.Platform.Data.IDataService datasvc = Sage.Platform.Application.ApplicationContext.Current.Services.Get<Sage.Platform.Data.IDataService>();
                    using (System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection(datasvc.GetConnectionString()))
                    {
                        conn.Open();
                        using (System.Data.OleDb.OleDbCommand cmd = new System.Data.OleDb.OleDbCommand(sql, conn))
                        {
                            cmd.ExecuteNonQuery();
                        }
                    }
                }
            }
        }
        if (success)
        {
            using (ISession session = new Sage.Platform.Orm.SessionScopeWrapper(true))
            {
                string entityId = SessionMergeArguments.MergeProvider.Source.EntityId;
                IPersistentEntity source = Sage.Platform.EntityFactory.GetById(type, entityId) as IPersistentEntity;
                source.Delete();
                EntityService.RemoveEntityHistory(type, source);
                Response.Redirect(String.Format("{0}.aspx", GetEntityName(type)));
            }
        }
    }