public virtual RelatedMessagelog CreateRelatedMessagelogFromReader(IDataReader reader)
 {
     RelatedMessagelog item = new RelatedMessagelog();
     try
     {
         if (!reader.IsDBNull(reader.GetOrdinal("RelatedMessagelogID"))) item.RelatedMessagelogID = (long)reader["RelatedMessagelogID"];
         if (!reader.IsDBNull(reader.GetOrdinal("NewsID"))) item.NewsID = (long)reader["NewsID"];
         if (!reader.IsDBNull(reader.GetOrdinal("CustomerID"))) item.CustomerID = (string)reader["CustomerID"];
     }
     catch (Exception ex)
     {
         // log this exception
         log4net.Util.LogLog.Error(ex.Message, ex);
         // wrap it and rethrow
         throw new ApplicationException(SR.DataAccessCreateRelatedMessagelogFromReaderException, ex);
     }
     return item;
 }
 public static void UpdateRelatedMessagelog(RelatedMessagelog relatedMessagelog)
 {            
     try
     {
         RelatedMessagelogDAO relatedMessagelogDAO = new RelatedMessagelogDAO();
         relatedMessagelogDAO.UpdateRelatedMessagelog(relatedMessagelog);
     }
     catch (ApplicationException)
     {
         throw;
     }
     catch (Exception ex)
     {
         // log this exception
         log4net.Util.LogLog.Error(ex.Message, ex);
         // wrap it and rethrow
         throw new ApplicationException(SR.BusinessUpdateRelatedMessagelogException, ex);
     }
 }        
        public virtual void UpdateRelatedMessagelog(RelatedMessagelog relatedMessagelog)
        {
            try
            {
                Database database = DatabaseFactory.CreateDatabase("DestinationConnection");
                DbCommand dbCommand = database.GetStoredProcCommand("spRelatedMessagelogUpdate");

                database.AddInParameter(dbCommand, "@RelatedMessagelogID", DbType.Int64, relatedMessagelog.RelatedMessagelogID);
                database.AddInParameter(dbCommand, "@NewsID", DbType.Int64, relatedMessagelog.NewsID);
                database.AddInParameter(dbCommand, "@CustomerID", DbType.AnsiString, relatedMessagelog.CustomerID);

                database.ExecuteNonQuery(dbCommand);
            }
            catch (Exception ex)
            {
                // log this exception
                log4net.Util.LogLog.Error(ex.Message, ex);
                // wrap it and rethrow
                throw new ApplicationException(SR.DataAccessUpdateRelatedMessagelogException, ex);
            }
        }
        public void SendRelatedNew(VfsCustomerService.Entities.Customer customer)
        {
            var service = new SBSGatewaySoapClient();

            if(customer.CustomerId == "094P848586") return;

            service.Endpoint.Address = new System.ServiceModel.EndpointAddress("http://Svr-06/SBSGateway/SBSGateway.asmx");
            PorscheCustomer porscheCustomer = new PorscheCustomer();
            porscheCustomer.CustomerId = customer.CustomerId;
            
            CustomerInquiryData customerData = service.CustomerInquiry
                                                           (porscheCredentials,
                                                           porscheCustomer,                                                            
                                                           GetCustomerType.None.ToString(),
                                                           CustomerStockInquiryType.Normal.ToString(),
                                                           CustomerAmountInquiryType.Full.ToString());
            if (customerData.ErrorCode != SbsErrorCode.None)
            {
                //throw new Exception(customerData.Message);
                Ultility.Info(customer.CustomerId + ": " + customerData.Message);
            }
            else
            {
                //dataGridView1.DataSource = customerData.StockItems;
                CustomerStockInquiryObject[] customerInquiryData;
                if (customerData != null)
                {
                    customerInquiryData = customerData.StockItems;
                    string content = string.Empty;
                    string contentSms = string.Empty;
                    int templateID = Convert.ToInt32(ConfigurationManager.AppSettings["RelatedMessageTemplateID"]);
                    int templateIDSms = Convert.ToInt32(ConfigurationManager.AppSettings["RelatedSmsMessageTemplateID"]);
                    int smsCount = 0;
                    int total;
                    foreach (CustomerStockInquiryObject obj in customerInquiryData)
                    {
                        stock_NewCollection stockNewsCollection = stock_NewService.Getstock_NewList(obj.StockCode, customer.CustomerId, stock_NewColumns.NewsID, "DESC", 1, 3, out total);
                        Vfs.WebCrawler.Destination.Entities.RelatedMessagelogCollection relatedMessagelogColl = new Vfs.WebCrawler.Destination.Entities.RelatedMessagelogCollection();
                        smsCount = 0;
                        foreach (stock_New stock_new in stockNewsCollection)
                        {
                            content += "<a href=\"www.vfs.com.vn/News.aspx?newsid=\"" + stock_new.NewsID.ToString() + "&group=" + SetNewsGroupName(stock_new.NewsID) + "\" >" + stock_new.NewsTitle.Normalize() + "</a> <br/>";

                            if (smsCount == 0)
                            {
                                if (contentSms == string.Empty)
                                    contentSms += "(" + Ultility.RemoveSound(stock_new.NewsTitle.Normalize()) + "-www.vfs.com.vn/News.aspx?newsid=" + stock_new.NewsID.ToString() + "&group=" + SetNewsGroupName(stock_new.NewsID) + ")";
                                else
                                    contentSms += ";(" + Ultility.RemoveSound(stock_new.NewsTitle.Normalize()) + "-www.vfs.com.vn/News.aspx?newsid=" + stock_new.NewsID.ToString() + "&group=" + SetNewsGroupName(stock_new.NewsID) + ")";
                            }
                            smsCount++;
                            Vfs.WebCrawler.Destination.Entities.RelatedMessagelog relatedMessagelog = new Vfs.WebCrawler.Destination.Entities.RelatedMessagelog();
                            relatedMessagelog.NewsID = stock_new.NewsID;
                            relatedMessagelogColl.Add(relatedMessagelog);
                        }
                        //create messsages to be sent
                        ContentTemplate contentTemplate = ContentTemplateService.GetContentTemplate(templateID);
                        ContentTemplate contentTemplateSms = ContentTemplateService.GetContentTemplate(templateIDSms);
                        VfsCustomerService.Business.ImportService.CreateMessage(customer, content, contentSms, contentTemplate, contentTemplateSms);

                        foreach (Vfs.WebCrawler.Destination.Entities.RelatedMessagelog relatedMessagelog in relatedMessagelogColl)
                        {
                            Vfs.WebCrawler.Destination.Business.RelatedMessagelogService.CreateRelatedMessagelog(relatedMessagelog);
                        }
                    }
                }
            }
        }
        public void SendRelatedNew(VfsCustomerService.Entities.Customer customer)
        {
            var service = new SBSGatewaySoapClient();

            if(customer.CustomerId == "094P848586") return;

            service.Endpoint.Address = new System.ServiceModel.EndpointAddress(endPointAddress);
            PorscheCustomer porscheCustomer = new PorscheCustomer();
            porscheCustomer.CustomerId = customer.CustomerId;
            ClientParam clientParam = new ClientParam();            

            CustomerInquiryData customerData = service.CustomerInquiry
                                                           (porscheCredentials,
                                                           porscheCustomer,                                                            
                                                           GetCustomerType.None.ToString(),
                                                           CustomerStockInquiryType.Normal.ToString(),
                                                           CustomerAmountInquiryType.Full.ToString());
            if (customerData.ErrorCode != SbsErrorCode.None)
            {
                //throw new Exception(customerData.Message);
                Ultility.Info(customer.CustomerId + ": " + customerData.Message);
            }
            else
            {
                Ultility.Info(customer.CustomerId + ": " + customer.CustomerId);
                //dataGridView1.DataSource = customerData.StockItems;
                CustomerStockInquiryObject[] customerInquiryData;
                if (customerData != null)
                {
                    stock_NewCollection stockNewsCollection = new stock_NewCollection();
                    Vfs.WebCrawler.Destination.Entities.RelatedMessagelog relatedMessagelog;
                    Vfs.WebCrawler.Destination.Entities.RelatedMessagelogCollection relatedMessagelogColl = new Vfs.WebCrawler.Destination.Entities.RelatedMessagelogCollection();
                    customerInquiryData = customerData.StockItems;
                    StringBuilder content = new StringBuilder();
                    string contentSms = string.Empty;
                   
                    int smsCount = 0;
                    int total;
                    Boolean sentYn = false;
                    smsCount = 0;
                    content.Append("<table>");
                    foreach (CustomerStockInquiryObject obj in customerInquiryData)
                    {
                        Ultility.Info(customer.CustomerId + ": " + obj.StockCode);
                        stockNewsCollection = stock_NewService.Getstock_NewList(obj.StockCode, customer.CustomerId , stock_NewColumns.NewsID, "DESC", 1, 3, out total);
                        if (stockNewsCollection.Count > 0) sentYn = true;
                      
                        foreach (stock_New stock_new in stockNewsCollection)
                        {
                            content.Append("<tr style=\"height:28px\">");
                            content.Append("<td style=\"background-color:#FFCC00;font-weight:bold;width:40px; heigh:25px; text-align:left; font:Tahoma;\">" + obj.StockCode + "</td>");
                            content.Append("<td style=\"background-color:#F5F5F5;text-align:left;font:Tahoma;\"><a style=\"cursor:pointer; text-decoration:none;font:Tahoma;color:#000000;\" href=\"http://www.vfs.com.vn/News.aspx?newsid=" + stock_new.NewsID.ToString() + "&group=" + SetNewsGroupName(stock_new.NewsID) + "\"" + ">" + (stock_new.NewsTitle.Normalize().IndexOf(':') == 3 ? stock_new.NewsTitle.Normalize().Substring(4) : stock_new.NewsTitle.Normalize().Substring(3)) + "</a></td>");
                            content.Append("</tr>");
                            if (smsCount == 0)
                            {
                                if (contentSms == string.Empty)
                                    contentSms += "(" + Ultility.RemoveSound(stock_new.NewsTitle.Normalize()) + ")";
                                else
                                    contentSms += ";(" + Ultility.RemoveSound(stock_new.NewsTitle.Normalize()) + ")";
                            }
                            smsCount++;
                            relatedMessagelog = new Vfs.WebCrawler.Destination.Entities.RelatedMessagelog();
                            relatedMessagelog.NewsID = stock_new.NewsID;
                            relatedMessagelog.CustomerID = customer.CustomerId;
                            relatedMessagelogColl.Add(relatedMessagelog);
                        }                       
                    }
                    content.Append("</table>");
                    //create messsages to be sent
                    if (sentYn)
                    {
                        ContentTemplate contentTemplate = ContentTemplateService.GetContentTemplate(templateID);
                        ContentTemplate contentTemplateSms = ContentTemplateService.GetContentTemplate(templateIDSms);                        
                        VfsCustomerService.Business.ImportService.CreateMessage(customer, content.ToString(), contentSms, contentTemplate, contentTemplateSms);

                        foreach (Vfs.WebCrawler.Destination.Entities.RelatedMessagelog relatedMsglog in relatedMessagelogColl)
                        {
                            Vfs.WebCrawler.Destination.Business.RelatedMessagelogService.CreateRelatedMessagelog(relatedMsglog);
                        }
                    }
                }            
            }
        }