Пример #1
0
        public MsCrmResult CancellationDenied(string QuoteNumber)
        {
            MsCrmResult   result = new MsCrmResult();
            SqlDataAccess sda    = new SqlDataAccess();

            sda.openConnection(Globals.ConnectionString);
            try
            {
                IOrganizationService service = MSCRM.AdminOrgService;
                ConditionExpression  con1    = new ConditionExpression();
                con1.AttributeName = "quotenumber";
                con1.Operator      = ConditionOperator.Equal;
                con1.Values.Add(QuoteNumber);

                ConditionExpression con2 = new ConditionExpression();
                con2.AttributeName = "statuscode";
                con2.Operator      = ConditionOperator.NotEqual;
                con2.Values.Add(7);//Düzeltilmiş olmayacak

                ConditionExpression con3 = new ConditionExpression();
                con3.AttributeName = "statuscode";
                con3.Operator      = ConditionOperator.Equal;
                con3.Values.Add(100000000);//iptal aktarıldı

                FilterExpression filter = new FilterExpression();
                filter.FilterOperator = LogicalOperator.And;
                filter.Conditions.Add(con1);
                filter.Conditions.Add(con2);
                filter.Conditions.Add(con3);

                QueryExpression Query = new QueryExpression("quote");
                Query.ColumnSet = new ColumnSet(true);
                Query.Criteria.FilterOperator = LogicalOperator.And;
                Query.Criteria.Filters.Add(filter);
                EntityCollection Result = service.RetrieveMultiple(Query);
                if (Result.Entities.Count > 0)
                {
                    if (Result.Entities[0].Attributes.Contains("new_prestatus"))
                    {
                        #region | QUERY UPDATE STATUS|
                        string sqlQuery = @"UPDATE
	                                   Quote
                                    SET
	                                   StatusCode=@StatusCode,
                                       ModifiedOn=GETUTCDATE()
                                    WHERE
	                                    QuoteId='{0}'"    ;
                        #endregion

                        sda.ExecuteNonQuery(string.Format(sqlQuery, Result.Entities[0].Id.ToString()), new SqlParameter[] { new SqlParameter("StatusCode", (int)Result.Entities[0].Attributes["new_prestatus"]) });

                        /////////////////////////////////////
                        ConditionExpression con5 = new ConditionExpression();
                        con5.AttributeName = "new_quoteid";
                        con5.Operator      = ConditionOperator.Equal;
                        con5.Values.Add(Result.Entities[0].Id);

                        ConditionExpression con4 = new ConditionExpression();
                        con4.AttributeName = "statecode";
                        con4.Operator      = ConditionOperator.Equal;
                        con4.Values.Add(0);

                        FilterExpression filter2 = new FilterExpression();
                        filter2.FilterOperator = LogicalOperator.And;
                        filter2.Conditions.Add(con5);
                        filter2.Conditions.Add(con4);

                        QueryExpression Query2 = new QueryExpression("new_salescanceldetail");
                        Query2.ColumnSet = new ColumnSet(true);
                        Query2.Criteria.FilterOperator = LogicalOperator.And;
                        Query2.Criteria.Filters.Add(filter2);
                        EntityCollection Result2 = service.RetrieveMultiple(Query2);
                        if (Result2.Entities.Count > 0)
                        {
                            Entity          r           = Result2.Entities[0];
                            SetStateRequest setStateReq = new SetStateRequest();
                            setStateReq.EntityMoniker = new EntityReference("new_salescanceldetail", r.Id);

                            setStateReq.State  = new OptionSetValue(1);
                            setStateReq.Status = new OptionSetValue(2);

                            SetStateResponse response = (SetStateResponse)service.Execute(setStateReq);
                        }

                        result.Success = true;
                        result.Message = "Satış Başarıyla İptal Edildi.";
                    }
                    else
                    {
                        result.Success = false;
                        result.Message = QuoteNumber + " Numaralı Satışın Eski Durumu Bulunamadı";
                    }
                }
                else
                {
                    result.Success = false;
                    result.Message = QuoteNumber + " Numaralı İptale Aktarılan Satış Bulunamadı";
                }
            }
            catch (Exception ex)
            {
                result.Success = false;
                result.Message = ex.Message;
            }
            return(result);
        }
Пример #2
0
        public MsCrmResult GetQuote(string QuoteNumber)
        {
            MsCrmResult result = new MsCrmResult();
            QuoteDetail qd     = new QuoteDetail();

            try
            {
                IOrganizationService service = MSCRM.GetOrgService(true);
                ConditionExpression  con1    = new ConditionExpression();
                con1.AttributeName = "quotenumber";
                con1.Operator      = ConditionOperator.Equal;
                con1.Values.Add(QuoteNumber);

                ConditionExpression con2 = new ConditionExpression();
                con2.AttributeName = "statuscode";
                con2.Operator      = ConditionOperator.NotEqual;
                con2.Values.Add(7);//Düzeltilmiş olmayacak

                FilterExpression filter = new FilterExpression();
                filter.FilterOperator = LogicalOperator.And;
                filter.Conditions.Add(con1);
                filter.Conditions.Add(con2);

                QueryExpression Query = new QueryExpression("quote");
                Query.ColumnSet = new ColumnSet(true);
                Query.Criteria.FilterOperator = LogicalOperator.And;
                Query.Criteria.Filters.Add(filter);
                EntityCollection Result = service.RetrieveMultiple(Query);
                if (Result.Entities.Count > 0)
                {
                    Entity q       = Result.Entities[0];
                    Entity product = GetProductByQuoteId(service, q.Id);
                    GetCustomerByQuote(service, q, qd);
                    qd.SalesId = Result.Entities[0].Id.ToString();
                    qd.ApartmentIdentificationNumber = product.Contains("productnumber") ? product.Attributes["productnumber"].ToString() : string.Empty;
                    qd.Block                  = product.Contains("new_blockid") ? ((EntityReference)product.Attributes["new_blockid"]).Name : string.Empty;
                    qd.ContractDate           = q.Contains("new_contractdate") ? ((DateTime)q.Attributes["new_contractdate"]).ToLocalTime() : (DateTime?)null;
                    qd.CustomerName           = q.Contains("customerid") ? ((EntityReference)q.Attributes["customerid"]).Name : string.Empty;
                    qd.HomeNumber             = product.Contains("new_homenumber") ? product.Attributes["new_homenumber"].ToString() : string.Empty;
                    qd.PerQquareMeterAmount   = product.Contains("new_persquaremeter") ? ((Money)product.Attributes["new_persquaremeter"]).Value.ToString("N2") : string.Empty;
                    qd.PrePaymentAmount       = q.Contains("new_prepaymentamount") ? ((Money)q.Attributes["new_prepaymentamount"]).Value.ToString("N2") : string.Empty;
                    qd.ProjectName            = product.Contains("new_projectid") ? ((EntityReference)product.Attributes["new_projectid"]).Name : string.Empty;
                    qd.SalesConsultant        = q.Contains("ownerid") ? ((EntityReference)q.Attributes["ownerid"]).Name : string.Empty;
                    qd.SalesConsultantEmail   = GetSalesConsultantEmail(((EntityReference)q.Attributes["ownerid"]).Id, service);
                    qd.SalesProcessDate       = q.Contains("new_salesprocessdate") ? ((DateTime)q.Attributes["new_salesprocessdate"]).ToLocalTime() : (DateTime?)null;
                    qd.TotalAmountLessFreight = q.Contains("totalamountlessfreight") ? ((Money)q.Attributes["totalamountlessfreight"]).Value.ToString("N2") : string.Empty;
                    qd.TransactionCurrency    = q.Contains("transactioncurrencyid") ? ((EntityReference)q.Attributes["transactioncurrencyid"]).Name : string.Empty;
                    qd.SalesStatus            = q.Contains("statuscode") ? GetOptionSetValue(1084, "statuscode", ((OptionSetValue)q.Attributes["statuscode"]).Value, service) : string.Empty;
                    qd.KonutStatus            = product.Contains("statuscode") ? GetOptionSetValue(1024, "statuscode", ((OptionSetValue)product.Attributes["statuscode"]).Value, service) : string.Empty;
                    qd.HouseCrmLink           = q.Contains("new_productid") ? (Globals.HouseCrmLink + ((EntityReference)q.Attributes["new_productid"]).Id.ToString()) : string.Empty;


                    ConditionExpression con3 = new ConditionExpression();
                    con3.AttributeName = "new_quoteid";
                    con3.Operator      = ConditionOperator.Equal;
                    con3.Values.Add(q.Id);

                    ConditionExpression con4 = new ConditionExpression();
                    con4.AttributeName = "statecode";
                    con4.Operator      = ConditionOperator.Equal;
                    con4.Values.Add(0);

                    FilterExpression filter2 = new FilterExpression();
                    filter2.FilterOperator = LogicalOperator.And;
                    filter2.Conditions.Add(con3);
                    filter2.Conditions.Add(con4);

                    QueryExpression Query2 = new QueryExpression("new_salescanceldetail");
                    Query2.ColumnSet = new ColumnSet(true);
                    Query2.Criteria.FilterOperator = LogicalOperator.And;
                    Query2.Criteria.Filters.Add(filter2);
                    EntityCollection Result2 = service.RetrieveMultiple(Query2);
                    if (Result2.Entities.Count > 0)
                    {
                        Entity r = Result2.Entities[0];
                        qd.CalcelReasonId         = Result2.Entities[0].Id.ToString();
                        qd.SubCanceledReason      = r.Contains("new_subcanceledreasonid") ? ((EntityReference)r.Attributes["new_subcanceledreasonid"]).Name : string.Empty;
                        qd.CanceledReason         = r.Contains("new_canceledreasonid") ? ((EntityReference)r.Attributes["new_canceledreasonid"]).Name : string.Empty;
                        qd.CanceledDate           = r.Contains("createdon") ? ((DateTime)r.Attributes["createdon"]).ToLocalTime() : (DateTime?)null;
                        qd.CanceledDescription    = r.Contains("new_canceldescription") ? r.Attributes["new_canceldescription"].ToString() : string.Empty;
                        qd.ContractAccessOffice   = r.Contains("new_contractaccessoffice") ? r.Attributes["new_contractaccessoffice"].ToString() : string.Empty;
                        qd.contractAccessDate     = r.Contains("new_contractaccessdate") ? ((DateTime)r.Attributes["new_contractaccessdate"]).ToLocalTime() : (DateTime?)null;
                        qd.WageNumber             = r.Contains("new_wagenumber") ? r.Attributes["new_wagenumber"].ToString() : string.Empty;
                        qd.ProtestDate            = r.Contains("new_protestdate") ? ((DateTime)r.Attributes["new_protestdate"]).ToLocalTime() : (DateTime?)null;
                        qd.ContractCanceledOffice = r.Contains("new_contractcanceledoffice") ? r.Attributes["new_contractcanceledoffice"].ToString() : string.Empty;
                        qd.NotaryStatus           = r.Contains("new_notarystatus") ? GetOptionsSetTextFromValue(service, "new_salescanceldetail", "new_notarystatus", ((OptionSetValue)r.Attributes["new_notarystatus"]).Value) : string.Empty;
                    }

                    result.Result  = qd;
                    result.Success = true;
                    result.Message = "Satış Detayları Başarıyla Çekildi.";
                }
                else
                {
                    result.Success = false;
                    result.Message = QuoteNumber + " Numaralı Satış Bulunamadı";
                }
            }
            catch (Exception ex)
            {
                result.Success = false;
                result.Message = ex.Message;
            }
            return(result);
        }
Пример #3
0
        public MsCrmResult CancellationConfirmed(string QuoteNumber)
        {
            MsCrmResult result = new MsCrmResult();

            try
            {
                IOrganizationService service = MSCRM.AdminOrgService;
                ConditionExpression  con1    = new ConditionExpression();
                con1.AttributeName = "quotenumber";
                con1.Operator      = ConditionOperator.Equal;
                con1.Values.Add(QuoteNumber);

                ConditionExpression con2 = new ConditionExpression();
                con2.AttributeName = "statuscode";
                con2.Operator      = ConditionOperator.NotEqual;
                con2.Values.Add(7);//Düzeltilmiş olmayacak

                ConditionExpression con3 = new ConditionExpression();
                con3.AttributeName = "statuscode";
                con3.Operator      = ConditionOperator.Equal;
                con3.Values.Add(100000000);//iptal aktarıldı

                FilterExpression filter = new FilterExpression();
                filter.FilterOperator = LogicalOperator.And;
                filter.Conditions.Add(con1);
                filter.Conditions.Add(con2);
                filter.Conditions.Add(con3);

                QueryExpression Query = new QueryExpression("quote");
                Query.ColumnSet = new ColumnSet(true);
                Query.Criteria.FilterOperator = LogicalOperator.And;
                Query.Criteria.Filters.Add(filter);
                EntityCollection Result = service.RetrieveMultiple(Query);
                if (Result.Entities.Count > 0)
                {
                    var quoteclose = new Entity("quoteclose");
                    quoteclose.Attributes.Add("quoteid", Result.Entities[0].ToEntityReference());
                    CloseQuoteRequest closeQuoteRequest = new CloseQuoteRequest()
                    {
                        QuoteClose = quoteclose,
                        Status     = new OptionSetValue(6)
                    };
                    service.Execute(closeQuoteRequest);
                    /////////////////////////////////////
                    ConditionExpression con5 = new ConditionExpression();
                    con5.AttributeName = "new_quoteid";
                    con5.Operator      = ConditionOperator.Equal;
                    con5.Values.Add(Result.Entities[0].Id);

                    ConditionExpression con4 = new ConditionExpression();
                    con4.AttributeName = "statecode";
                    con4.Operator      = ConditionOperator.Equal;
                    con4.Values.Add(0);

                    FilterExpression filter2 = new FilterExpression();
                    filter2.FilterOperator = LogicalOperator.And;
                    filter2.Conditions.Add(con5);
                    filter2.Conditions.Add(con4);

                    QueryExpression Query2 = new QueryExpression("new_salescanceldetail");
                    Query2.ColumnSet = new ColumnSet(true);
                    Query2.Criteria.FilterOperator = LogicalOperator.And;
                    Query2.Criteria.Filters.Add(filter2);
                    EntityCollection Result2 = service.RetrieveMultiple(Query2);
                    if (Result2.Entities.Count > 0)
                    {
                        Entity          r           = Result2.Entities[0];
                        SetStateRequest setStateReq = new SetStateRequest();
                        setStateReq.EntityMoniker = new EntityReference("new_salescanceldetail", r.Id);

                        setStateReq.State  = new OptionSetValue(1);
                        setStateReq.Status = new OptionSetValue(2);

                        SetStateResponse response = (SetStateResponse)service.Execute(setStateReq);
                    }

                    result.Success = true;
                    result.Message = "Satış Başarıyla İptal Edildi.";
                }
                else
                {
                    result.Success = false;
                    result.Message = QuoteNumber + " Numaralı İptale Aktarılan Satış Bulunamadı";
                }
            }
            catch (Exception ex)
            {
                result.Success = false;
                result.Message = ex.Message;
            }
            return(result);
        }