public CustomerCollection FetchAll()
 {
     CustomerCollection coll = new CustomerCollection();
     Query qry = new Query(Customer.Schema);
     coll.LoadAndCloseReader(qry.ExecuteReader());
     return coll;
 }
Example #2
0
 /**
  * method btnDoCreate_Click
  * inserts a new Customer with
  * the supplied parameters.
  * Little to no validation is being done.
  * NOTE: a new Customer always get a new Contact
  * timestamped with NOW
  * and a note saying "Created"
  */
 protected void btnDoCreate_Click(object sender, EventArgs e)
 {
     Customer cu = new Customer();
     int res = cu.insertCustomer(txtCreateFirstName.Text, txtCreateLastName.Text, txtCreatePhoneNumber.Text, txtCreateEmail.Text);
     if (res == 0)
     {
         //error
         lblError.Text = cu.errorMessage;
         lblError.Visible = true;
     }
     else
     {
         CustomerCollection cc = new CustomerCollection();
         if (!cc.getAllCustomers())
         {
             //error
             lblError.Text = cc.errorMessage;
             lblError.Visible = true;
         }
         else
         {
             //clear fields after success
             txtCreateFirstName.Text = "";
             txtCreateLastName.Text = "";
             txtCreatePhoneNumber.Text = "";
             txtCreateEmail.Text = "";
             txtSearchFirstName.Text = "";
             txtSearchLastName.Text = "";
             txtSearchPhoneNumber.Text = "";
             txtSearchEmail.Text = "";
             refreshCustomerList(cc);
         }
     }
 }
 public IEnumerable<Customer> GetCustomerCollection()
 {
     var col = new CustomerCollection();
     col.Add(new Customer() { Id = 1, Name = "Tom" });
     col.Add(new Customer() { Id = 2, Name = "Jerry" });
     return col;
 }
Example #4
0
 public virtual CustomerCollection GetCustomerListReceiveMessage(CustomerColumns orderBy, string orderDirection, int page, int pageSize, out int totalRecords)
 {            
     try
     {
         Database database = DatabaseFactory.CreateDatabase("CustommerServiceConnection");
         DbCommand dbCommand = database.GetStoredProcCommand("spCustomerGetListReceiveMsg");
         
         database.AddInParameter(dbCommand, "@OrderBy", DbType.AnsiString, orderBy.ToString());
         database.AddInParameter(dbCommand, "@OrderDirection", DbType.AnsiString, orderDirection.ToString());
         database.AddInParameter(dbCommand, "@Page", DbType.Int32, page);
         database.AddInParameter(dbCommand, "@PageSize", DbType.Int32, pageSize);
         database.AddOutParameter(dbCommand, "@TotalRecords", DbType.Int32, 4);
         
         CustomerCollection customerCollection = new CustomerCollection();
         using (IDataReader reader = database.ExecuteReader(dbCommand))
         {
             while (reader.Read())
             {
                 Customer customer = CreateCustomerFromReader(reader);
                 customerCollection.Add(customer);
             }
             reader.Close();
         }
         totalRecords = (int)database.GetParameterValue(dbCommand, "@TotalRecords");
         return customerCollection;
     }
     catch (Exception ex)
     {
         // log this exception
         log4net.Util.LogLog.Error(ex.Message, ex);
         // wrap it and rethrow
         throw new ApplicationException(SR.DataAccessGetCustomerListException, ex);
     }
 }
Example #5
0
 public void GetCustomers()
 {
     var repository  = Substitute.For<ICustomerRepository>();
     var customers = new List<CustomerValue>();
     customers.Add(new CustomerValue() { CustomerID = "ABC" });
     repository.GetCustomers().Returns<IEnumerable<CustomerValue>>(customers);
     var collection = new CustomerCollection(repository);
     var values =  collection.Get();
     Assert.IsNotEmpty(values);
 }
        public CustomerCollection GetCustomers()
        {
            CustomerCollection customers = new CustomerCollection();

            using(IDataReader dr = new CustomerDataAdapter().GetCustomers())
            {
            while (dr.Read())
            {
                customers.Add(PopulateReader(dr));
            }
            dr.Close();
            }
            return customers;
        }
Example #7
0
 /**
  * method btnDoSearch_Click
  * executes a search against the Customer
  * list with the supplied parameters
  * The result is then refreshed into the repeater
  * NOTE: The search is an AND, not an OR search
  */
 protected void btnDoSearch_Click(object sender, EventArgs e)
 {
     CustomerCollection cc = new CustomerCollection();
     if (!cc.searchCustomer(txtSearchFirstName.Text, txtSearchLastName.Text, txtSearchPhoneNumber.Text, txtSearchEmail.Text))
     {
         //error
         lblError.Text = cc.errorMessage;
         lblError.Visible = true;
     }
     else
     {
         refreshCustomerList(cc);
     }
 }
        private void SimpleDataEntryWindow_Loaded(object sender, RoutedEventArgs e)
        {
            IQueryable<Customer> query = from c in db.Customers
                                         where c.City == "Seattle"
                                         orderby c.LastName, c.FirstName
                                         select c;

            this.CustomerData = new CustomerCollection(query, db);

            CollectionViewSource customerSource = (CollectionViewSource)this.FindResource("CustomerSource");
            customerSource.Source = this.CustomerData;

            this.View = (ListCollectionView)customerSource.View;
        }
Example #9
0
 /**
  * method btnContactCancel_Click
  * gets the list of rare Customers (havent been Contacted
  * in the last 6 months )
  * and fills the repeater
  */
 protected void btnNoContact_Click(object sender, EventArgs e)
 {
     CustomerCollection cc = new CustomerCollection();
     if (!cc.getRareCustomer())
     {
         //error
         lblError.Text = cc.errorMessage;
         lblError.Visible = true;
     }
     else
     {
         refreshCustomerList(cc);
     }
 }
        /// <summary>
        /// Sends a campaign to specified emails
        /// </summary>
        /// <param name="CampaignID">Campaign identifier</param>
        /// <param name="Customers">Customers</param>
        /// <returns>Total emails sent</returns>
        public static int SendCampaign(int CampaignID, CustomerCollection Customers)
        {
            int totalEmailsSent = 0;
            Campaign campaign = GetCampaignByID(CampaignID);
            if (campaign == null)
                throw new NopException("Campaign could not be loaded");
            foreach (Customer customer in Customers)
            {
                if (customer.IsGuest)
                    continue;

                string subject = MessageManager.ReplaceMessageTemplateTokens(customer, campaign.Subject);
                string body = MessageManager.ReplaceMessageTemplateTokens(customer, campaign.Body);
                MailAddress from = new MailAddress(MessageManager.AdminEmailAddress, MessageManager.AdminEmailDisplayName);
                MailAddress to = new MailAddress(customer.Email, customer.FullName);
                MessageManager.InsertQueuedEmail(3, from, to, string.Empty, string.Empty, subject, body, DateTime.Now, 0, null);
                totalEmailsSent++;
            }
            return totalEmailsSent;
        }
Example #11
0
 public static void CreateMessage(CustomerCollection data, string[] contentToBeSent, ContentTemplate contentTemplate, ref int numberCustomerSent)
 {
     int i = 0;
     foreach (Customer item in data)
     {
         //shareHolder.ShareHolderCode = items[0];
         if (item != null)
         {
             numberCustomerSent++;
             MessageContent messageContent = null;
             messageContent = new MessageContent();
             messageContent.Sender = contentTemplate.Sender;                    
             messageContent.Subject = contentTemplate.Subject;
             messageContent.BodyContentType = contentTemplate.BodyContentType;
             messageContent.BodyEncoding = contentTemplate.BodyEncoding;
             messageContent.BodyMessage = ReplaceBodyMessage(contentTemplate.BodyMessage, contentToBeSent[i++]);
             messageContent.ContentTemplateID = contentTemplate.ContentTemplateID;
             messageContent.ServiceTypeID = contentTemplate.ServiceTypeID;
             messageContent.ModifiedDate = DateTime.Now;
             messageContent.CreatedDate = DateTime.Now;
             messageContent.Status = 0;
             //in case the message is type of email check if the email address is valid
             if (messageContent.ServiceTypeID == 1)
             {
                 messageContent.Receiver = item.Email;
                 if (ValidateEmail(messageContent.Receiver) == true)
                 {
                     MessageContentService.CreateMessageContent(messageContent);
                     ContentTemplateAttachementCollection contentTemplateAttachementColl = ContentTemplateAttachementService.GetContentTemplateAttachementList(contentTemplate.ContentTemplateID, ContentTemplateAttachementColumns.ModifiedDate, "DESC");
                     foreach (ContentTemplateAttachement attachement in contentTemplateAttachementColl)
                     {
                         MessageContentAttachement messageContentAttachement = new MessageContentAttachement();
                         messageContentAttachement.AttachementDescription = attachement.AttachementDescription;
                         messageContentAttachement.AttachementDocument = attachement.AttachementDocument;
                         messageContentAttachement.MessageContentID = messageContent.MessageContentID;
                         messageContentAttachement.ModifiedDate = DateTime.Now;
                         messageContentAttachement.CreatedDate = DateTime.Now;
                         MessageContentAttachementService.CreateMessageContentAttachement(messageContentAttachement);
                     }
                 }
             }
             else
             {
                 messageContent.Receiver = item.Mobile;
                 MessageContentService.CreateMessageContent(messageContent);
                 ContentTemplateAttachementCollection contentTemplateAttachementColl = ContentTemplateAttachementService.GetContentTemplateAttachementList(contentTemplate.ContentTemplateID, ContentTemplateAttachementColumns.ModifiedDate, "DESC");
                 foreach (ContentTemplateAttachement attachement in contentTemplateAttachementColl)
                 {
                     MessageContentAttachement messageContentAttachement = new MessageContentAttachement();
                     messageContentAttachement.AttachementDescription = attachement.AttachementDescription;
                     messageContentAttachement.AttachementDocument = attachement.AttachementDocument;
                     messageContentAttachement.MessageContentID = messageContent.MessageContentID;
                     messageContentAttachement.ModifiedDate = DateTime.Now;
                     messageContentAttachement.CreatedDate = DateTime.Now;
                     MessageContentAttachementService.CreateMessageContentAttachement(messageContentAttachement);
                 }
             }
         }
     }
 }
        //get customer data filter by province that input from user
        public static CustomerCollection GetCustomerByProvince(string provinceFilter)
        {
            CustomerCollection customers;

            //connect database
            using (SqlConnection conn = new SqlConnection(connString))
            {
                string query;
                //query to retrieve ALL data from customer table
                if (provinceFilter == "ALL")
                {
                    query = @"SELECT CompanyName, City, Province, PostalCode, CreditHold
                                 From Customer
                                 ORDER BY CompanyName";
                }
                //query to retrieve data from customer table with province filter
                else
                {
                    query = @"SELECT CompanyName, City, Province, PostalCode, CreditHold
                                 From Customer
                                 WHERE Province = @province
                                 ORDER BY CompanyName";
                }
                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.CommandType = CommandType.Text;
                    cmd.CommandText = query;
                    cmd.Connection  = conn;
                    cmd.Parameters.AddWithValue("@province", provinceFilter);
                    conn.Open();
                    customers = new CustomerCollection();

                    using (SqlDataReader reader = cmd.ExecuteReader())
                    {
                        string customerName = null;
                        string city         = null;
                        string province     = null;
                        string postalCode   = null;
                        string creditHold   = null;

                        while (reader.Read())
                        {
                            //get CompanyName which can't be NULL from database setting
                            customerName = reader["CompanyName"] as string;

                            //get City
                            if (!reader.IsDBNull(1))
                            {
                                city = reader["City"] as string;
                            }
                            //get Province
                            if (!reader.IsDBNull(2))
                            {
                                province = reader["Province"] as string;
                            }
                            //get PostalCode
                            if (!reader.IsDBNull(3))
                            {
                                postalCode = reader["PostalCode"] as string;
                            }
                            //get CreditHold
                            if (!reader.IsDBNull(4))
                            {
                                bool boolCredit = (bool)reader["CreditHold"];

                                if (boolCredit == true)
                                {
                                    creditHold = "Y";
                                }
                                else
                                {
                                    creditHold = "N";
                                }
                            }
                            //Incase CreditHold is NULL
                            if (reader.IsDBNull(4))
                            {
                                creditHold = "N";
                            }
                            //Add data to customers list
                            customers.Add(new Customer(customerName, city, province, postalCode, creditHold));


                            customerName = null;
                            city         = null;
                            province     = null;
                            postalCode   = null;
                            creditHold   = null;
                        }
                    }

                    return(customers);
                }
            }
        }
Example #13
0
 /**
  * method refreshCustomerList
  * accepts a CustomerCollection and
  * refills the repeater
  */
 protected void refreshCustomerList(CustomerCollection cc)
 {
     Repeater1.DataSource = cc;
     Repeater1.DataBind();
 }
        /// <summary>
        /// Method for retrieving customers list from Database
        /// </summary>
        /// <returns>the customers</returns>
        public static CustomerCollection GetCustomers()
        {
            CustomerCollection customers;

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                string query = @"SELECT CompanyName, Address, City, Province, PostalCode, CreditHold
                             FROM Customer
                             ORDER BY CompanyName";

                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.CommandType = CommandType.Text;
                    cmd.CommandText = query;
                    cmd.Connection  = connection;

                    connection.Open();

                    customers = new CustomerCollection();

                    using (SqlDataReader reader = cmd.ExecuteReader())
                    {
                        string companyName;
                        string address    = null;
                        string city       = null;
                        string province   = null;
                        string postalCode = null;
                        bool   creditHold = false;

                        while (reader.Read())
                        {
                            companyName = reader["CompanyName"] as string;

                            if (!reader.IsDBNull(SECOND_INDEX))
                            {
                                address = reader["Address"] as string;
                            }

                            if (!reader.IsDBNull(THIRD_INDEX))
                            {
                                city = reader["City"] as string;
                            }

                            if (!reader.IsDBNull(FOURTH_INDEX))
                            {
                                province = reader["Province"] as string;
                            }

                            if (!reader.IsDBNull(FIFTH_INDEX))
                            {
                                postalCode = reader["PostalCode"] as string;
                            }

                            if (!reader.IsDBNull(SIXTH_INDEX))
                            {
                                creditHold = reader["CreditHold"] as bool? ?? false;
                            }

                            customers.Add(new Customer(companyName, address, city, province, postalCode, creditHold));

                            address    = null;
                            city       = null;
                            province   = null;
                            postalCode = null;
                            creditHold = false;
                        }
                    }
                }

                return(customers);
            }
        }
        /// <param name='value'>
        /// Required.
        /// </param>
        /// <param name='cancellationToken'>
        /// Cancellation token.
        /// </param>
        public async Task <HttpOperationResponse <object> > AddManyCustomersByValueWithOperationResponseAsync(IList <Customer> value, CancellationToken cancellationToken = default(System.Threading.CancellationToken))
        {
            // Validate
            if (value is ILazyCollection <Customer> && ((ILazyCollection <Customer>)value).IsInitialized == false || value == null)
            {
                throw new ArgumentNullException("value");
            }

            // Tracing
            bool   shouldTrace  = ServiceClientTracing.IsEnabled;
            string invocationId = null;

            if (shouldTrace)
            {
                invocationId = ServiceClientTracing.NextInvocationId.ToString();
                Dictionary <string, object> tracingParameters = new Dictionary <string, object>();
                tracingParameters.Add("value", value);
                ServiceClientTracing.Enter(invocationId, this, "AddManyCustomersByValueAsync", tracingParameters);
            }

            // Construct URL
            string url = "";

            url = url + "/AddManyCustomers";
            string baseUrl = this.Client.BaseUri.AbsoluteUri;

            // Trim '/' character from the end of baseUrl and beginning of url.
            if (baseUrl[baseUrl.Length - 1] == '/')
            {
                baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
            }
            if (url[0] == '/')
            {
                url = url.Substring(1);
            }
            url = baseUrl + "/" + url;
            url = url.Replace(" ", "%20");

            // Create HTTP transport objects
            HttpRequestMessage httpRequest = new HttpRequestMessage();

            httpRequest.Method     = HttpMethod.Post;
            httpRequest.RequestUri = new Uri(url);

            // Set Headers

            // Set Credentials
            if (this.Client.Credentials != null)
            {
                cancellationToken.ThrowIfCancellationRequested();
                await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
            }

            // Serialize Request
            string requestContent = null;
            JToken requestDoc     = CustomerCollection.SerializeJson(value, null);

            requestContent      = requestDoc.ToString(Newtonsoft.Json.Formatting.Indented);
            httpRequest.Content = new StringContent(requestContent, Encoding.UTF8);
            httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json");

            // Send Request
            if (shouldTrace)
            {
                ServiceClientTracing.SendRequest(invocationId, httpRequest);
            }
            cancellationToken.ThrowIfCancellationRequested();
            HttpResponseMessage httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);

            if (shouldTrace)
            {
                ServiceClientTracing.ReceiveResponse(invocationId, httpResponse);
            }
            HttpStatusCode statusCode = httpResponse.StatusCode;

            cancellationToken.ThrowIfCancellationRequested();
            string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);

            if (statusCode != HttpStatusCode.NoContent)
            {
                HttpOperationException <object> ex = new HttpOperationException <object>();
                ex.Request  = httpRequest;
                ex.Response = httpResponse;
                ex.Body     = null;
                if (shouldTrace)
                {
                    ServiceClientTracing.Error(invocationId, ex);
                }
                throw ex;
            }

            // Create Result
            HttpOperationResponse <object> result = new HttpOperationResponse <object>();

            result.Request  = httpRequest;
            result.Response = httpResponse;

            // Deserialize Response
            object resultModel = default(object);

            result.Body = resultModel;

            if (shouldTrace)
            {
                ServiceClientTracing.Exit(invocationId, result);
            }
            return(result);
        }
Example #16
0
        /**
         * method refreshCustomerList
         * accepts a CustomerCollection and
         * fill the repeater with it.
         * Also refresh the Dashboard stats
         * NOTE: Not very efficient
         */
        protected void refreshCustomerList(CustomerCollection cc)
        {
            Repeater1.DataSource = cc;
            Repeater1.DataBind();

            //fill Dashboard values
            CustomerCollection cc2 = new CustomerCollection();

            //Odd
            if (!cc2.getCustomersOdd())
            {
                //error
                lblError.Text = cc.errorMessage;
                lblError.Visible = true;
            }
            else
            {
                lblDBOdd.Text = cc2.Count.ToString();
            }

            //Even
            if (!cc2.getCustomerEven())
            {
                //error
                lblError.Text = cc.errorMessage;
                lblError.Visible = true;
            }
            else
            {
                lblDBEven.Text = cc2.Count.ToString();
            }

            //Family
            int famResult = cc2.getCustomerFamily();
            if (famResult == -1)
            {
                //error
                lblError.Text = cc.errorMessage;
                lblError.Visible = true;
            }
            else
            {
                lblDBFamily.Text = famResult.ToString();
            }

            //Contacts
            ContactCollection concol = new ContactCollection();
            if (! concol.getAllContactsToday())
            {
                //error
                lblError.Text = concol.errorMessage;
                lblError.Visible = true;
            }
            else
            {
                lblDBToday.Text = concol.Count.ToString();
            }
        }
Example #17
0
 static partial void OnAfterEntityCollectionToDtoCollection(EntityCollection <CustomerEntity> entities, CustomerCollection dtos);
Example #18
0
        public static void RefreshForeignKeyTest(string connectionName)
        {
            OrderItemCollection oiColl = new OrderItemCollection();

            oiColl.es.Connection.Name = "ForeignKeyTest";
            if (connectionName.Length != 0)
            {
                oiColl.es.Connection.Name = connectionName;
            }

            oiColl.Query.Where(oiColl.Query.OrderID > 11 |
                               oiColl.Query.ProductID > 9);
            oiColl.Query.Load();
            oiColl.MarkAllAsDeleted();
            oiColl.Save();

            OrderCollection oColl = new OrderCollection();

            oColl.es.Connection.Name = "ForeignKeyTest";
            if (connectionName.Length != 0)
            {
                oColl.es.Connection.Name = connectionName;
            }

            oColl.Query.Where(oColl.Query.OrderID > 11);
            oColl.Query.Load();
            oColl.MarkAllAsDeleted();
            oColl.Save();

            EmployeeTerritoryCollection etColl = new EmployeeTerritoryCollection();

            etColl.es.Connection.Name = "ForeignKeyTest";
            if (connectionName.Length != 0)
            {
                etColl.es.Connection.Name = connectionName;
            }

            etColl.Query.Where(etColl.Query.EmpID > 4 |
                               etColl.Query.TerrID > 4);
            etColl.Query.Load();
            etColl.MarkAllAsDeleted();
            etColl.Save();

            CustomerCollection cColl = new CustomerCollection();

            cColl.es.Connection.Name = "ForeignKeyTest";
            if (connectionName.Length != 0)
            {
                cColl.es.Connection.Name = connectionName;
            }

            cColl.Query.Where(cColl.Query.CustomerID > "99999" &
                              cColl.Query.CustomerSub > "001");
            cColl.Query.Load();
            cColl.MarkAllAsDeleted();
            cColl.Save();

            TerritoryExCollection tExColl = new TerritoryExCollection();

            tExColl.es.Connection.Name = "ForeignKeyTest";
            if (connectionName.Length != 0)
            {
                tExColl.es.Connection.Name = connectionName;
            }

            tExColl.Query.Where(tExColl.Query.TerritoryID > 1);
            tExColl.Query.Load();
            tExColl.MarkAllAsDeleted();
            tExColl.Save();

            TerritoryCollection tColl = new TerritoryCollection();

            tColl.es.Connection.Name = "ForeignKeyTest";
            if (connectionName.Length != 0)
            {
                tColl.es.Connection.Name = connectionName;
            }

            tColl.Query.Where(tColl.Query.TerritoryID > 5);
            tColl.Query.Load();
            tColl.MarkAllAsDeleted();
            tColl.Save();

            ReferredEmployeeCollection reColl = new ReferredEmployeeCollection();

            reColl.es.Connection.Name = "ForeignKeyTest";
            if (connectionName.Length != 0)
            {
                reColl.es.Connection.Name = connectionName;
            }

            reColl.Query.Where(reColl.Query.EmployeeID > 4 |
                               reColl.Query.ReferredID > 5);
            reColl.Query.Load();
            reColl.MarkAllAsDeleted();
            reColl.Save();

            ProductCollection pColl = new ProductCollection();

            pColl.es.Connection.Name = "ForeignKeyTest";
            if (connectionName.Length != 0)
            {
                pColl.es.Connection.Name = connectionName;
            }

            pColl.Query.Where(pColl.Query.ProductID > 10);
            pColl.Query.Load();
            pColl.MarkAllAsDeleted();
            pColl.Save();

            GroupCollection gColl = new GroupCollection();

            gColl.es.Connection.Name = "ForeignKeyTest";
            if (connectionName.Length != 0)
            {
                gColl.es.Connection.Name = connectionName;
            }

            gColl.Query.Where(gColl.Query.Id > "15001");
            gColl.Query.Load();
            gColl.MarkAllAsDeleted();
            gColl.Save();

            EmployeeCollection eColl = new EmployeeCollection();

            eColl.es.Connection.Name = "ForeignKeyTest";
            if (connectionName.Length != 0)
            {
                eColl.es.Connection.Name = connectionName;
            }

            eColl.Query.Where(eColl.Query.EmployeeID > 5);
            eColl.Query.Load();
            eColl.MarkAllAsDeleted();
            eColl.Save();

            CustomerGroupCollection cgColl = new CustomerGroupCollection();

            cgColl.es.Connection.Name = "ForeignKeyTest";
            if (connectionName.Length != 0)
            {
                cgColl.es.Connection.Name = connectionName;
            }

            cgColl.Query.Where(cgColl.Query.GroupID > "99999" |
                               cgColl.Query.GroupID < "00001");
            cgColl.Query.Load();
            cgColl.MarkAllAsDeleted();
            cgColl.Save();
        }
Example #19
0
        public static CustomerCollection GetAllCustomers()
        {
            CustomerCollection customers;

            using (SqlConnection conn = new SqlConnection(connString))
            {
                string query = string.Format("​{0} {1} {2}"
                                             , "SELECT CustomerCode, CompanyName, Address1, Address2, City, Province, PostalCode, YTDSales, CreditHold, Notes"
                                             , "FROM Customers944927"
                                             , "ORDER BY CustomerCode");



                SqlCommand cmd = new SqlCommand();
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = query;
                cmd.Connection  = conn;


                conn.Open();

                customers = new CustomerCollection();

                using (SqlDataReader reader = cmd.ExecuteReader())
                {
                    string  customerCode;
                    string  companyName;
                    string  firstAddress;
                    string  secondAddress;
                    string  city;
                    string  province;
                    string  postalCode;
                    decimal yTDSales;
                    byte    creditHold;
                    string  notes;

                    while (reader.Read())
                    {
                        customerCode = reader["CustomerCode"] as string;
                        companyName  = reader["CompanyName"] as string;
                        firstAddress = reader["Address1"] as string;

                        if (!reader.IsDBNull(3))
                        {
                            secondAddress = reader["Address2"] as string;
                        }
                        else
                        {
                            secondAddress = string.Empty;
                        }

                        if (!reader.IsDBNull(4))
                        {
                            city = reader["City"] as string;
                        }
                        else
                        {
                            city = string.Empty;
                        }

                        province = reader["Province"] as string;

                        if (!reader.IsDBNull(6))
                        {
                            postalCode = reader["PostalCode"] as string;
                        }

                        else
                        {
                            postalCode = string.Empty;
                        }
                        yTDSales = (decimal)reader["YTDSales"];

                        creditHold = (byte)reader["CreditHold"];
                        bool isCreditHeld = creditHold == 1;

                        if (!reader.IsDBNull(9))
                        {
                            notes = reader["Notes"] as string;
                        }

                        else
                        {
                            notes = string.Empty;
                        }

                        customers.Add(new Customer
                        {
                            CustomerCode  = customerCode,
                            CompanyName   = companyName,
                            FirstAddress  = firstAddress,
                            SecondAddress = secondAddress,
                            City          = city,
                            Province      = province,
                            PostalCode    = postalCode,
                            YTDSales      = yTDSales,
                            isCreditHeld  = isCreditHeld,
                            Notes         = notes
                        });
                    }
                }

                return(customers);
            }
        }
        /// <param name='start'>
        /// Required.
        /// </param>
        /// <param name='cancellationToken'>
        /// Cancellation token.
        /// </param>
        public async Task <HttpOperationResponse <IList <Customer> > > GetPageByStartWithOperationResponseAsync(int start, CancellationToken cancellationToken = default(System.Threading.CancellationToken))
        {
            // Tracing
            bool   shouldTrace  = ServiceClientTracing.IsEnabled;
            string invocationId = null;

            if (shouldTrace)
            {
                invocationId = ServiceClientTracing.NextInvocationId.ToString();
                Dictionary <string, object> tracingParameters = new Dictionary <string, object>();
                tracingParameters.Add("start", start);
                ServiceClientTracing.Enter(invocationId, this, "GetPageByStartAsync", tracingParameters);
            }

            // Construct URL
            string url = "";

            url = url + "/GetPage";
            List <string> queryParameters = new List <string>();

            queryParameters.Add("start=" + Uri.EscapeDataString(start.ToString()));
            if (queryParameters.Count > 0)
            {
                url = url + "?" + string.Join("&", queryParameters);
            }
            string baseUrl = this.Client.BaseUri.AbsoluteUri;

            // Trim '/' character from the end of baseUrl and beginning of url.
            if (baseUrl[baseUrl.Length - 1] == '/')
            {
                baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
            }
            if (url[0] == '/')
            {
                url = url.Substring(1);
            }
            url = baseUrl + "/" + url;
            url = url.Replace(" ", "%20");

            // Create HTTP transport objects
            HttpRequestMessage httpRequest = new HttpRequestMessage();

            httpRequest.Method     = HttpMethod.Get;
            httpRequest.RequestUri = new Uri(url);

            // Set Credentials
            if (this.Client.Credentials != null)
            {
                cancellationToken.ThrowIfCancellationRequested();
                await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
            }

            // Send Request
            if (shouldTrace)
            {
                ServiceClientTracing.SendRequest(invocationId, httpRequest);
            }
            cancellationToken.ThrowIfCancellationRequested();
            HttpResponseMessage httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);

            if (shouldTrace)
            {
                ServiceClientTracing.ReceiveResponse(invocationId, httpResponse);
            }
            HttpStatusCode statusCode = httpResponse.StatusCode;

            cancellationToken.ThrowIfCancellationRequested();
            string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);

            if (statusCode != HttpStatusCode.OK)
            {
                HttpOperationException <object> ex = new HttpOperationException <object>();
                ex.Request  = httpRequest;
                ex.Response = httpResponse;
                ex.Body     = null;
                if (shouldTrace)
                {
                    ServiceClientTracing.Error(invocationId, ex);
                }
                throw ex;
            }

            // Create Result
            HttpOperationResponse <IList <Customer> > result = new HttpOperationResponse <IList <Customer> >();

            result.Request  = httpRequest;
            result.Response = httpResponse;

            // Deserialize Response
            if (statusCode == HttpStatusCode.OK)
            {
                IList <Customer> resultModel = new List <Customer>();
                JToken           responseDoc = null;
                if (string.IsNullOrEmpty(responseContent) == false)
                {
                    responseDoc = JToken.Parse(responseContent);
                }
                if (responseDoc != null)
                {
                    resultModel = CustomerCollection.DeserializeJson(responseDoc);
                }
                result.Body = resultModel;
            }

            if (shouldTrace)
            {
                ServiceClientTracing.Exit(invocationId, result);
            }
            return(result);
        }
 /// <summary>
 /// Initializes a DataGridSample.
 /// </summary>
 public DataGridSample()
 {
     InitializeComponent();
     DataContext = new CustomerCollection();
 }
Example #22
0
 public CustomersCollectionPropertyDescriptor(CustomerCollection coll, int idx)
     : base("#" + idx.ToString(), null)
 {
     collection = coll;
     index      = idx;
 }
        private async void ButtonLoadCustomers_OnClick(object sender, RoutedEventArgs e)
        {
            if (!await EnsureProxy())
                return;

            var customers = await HubProxy.Invoke<CustomerCollection>("Get");
            if (customers == null)
                customers = new CustomerCollection();

            BindingOperations.EnableCollectionSynchronization(customers, _lock);
            DataGrid.ItemsSource = customers;
        }
Example #24
0
 public CustomerViewModel(CustomerCollection customers)
 {
     this.Customers = customers;
 }
Example #25
0
        public virtual CustomerCollection GetCustomerListByEmail(string email)
        {
            try
            {
                Database database = DatabaseFactory.CreateDatabase("CustommerServiceConnection");
                DbCommand dbCommand = database.GetStoredProcCommand("spCustomerGetListByEmail");

                database.AddInParameter(dbCommand, "@email", DbType.String, email);                

                CustomerCollection customerCollection = new CustomerCollection();
                using (IDataReader reader = database.ExecuteReader(dbCommand))
                {
                    while (reader.Read())
                    {
                        Customer customer = CreateCustomerFromReader(reader);
                        customerCollection.Add(customer);
                    }
                    reader.Close();
                }                
                return customerCollection;
            }
            catch (Exception ex)
            {
                // log this exception
                log4net.Util.LogLog.Error(ex.Message, ex);
                // wrap it and rethrow
                throw new ApplicationException(SR.DataAccessGetCustomerListException, ex);
            }
        }
Example #26
0
        /// <summary>
        /// Export customer list to XLS
        /// </summary>
        /// <param name="FilePath">File path to use</param>
        /// <param name="customers">Customers</param>
        public static void ExportCustomersToXLS(string FilePath, CustomerCollection customers)
        {
            using (ExcelHelper excelHelper = new ExcelHelper(FilePath))
            {
                excelHelper.HDR = "YES";
                excelHelper.IMEX = "0";
                Dictionary<string, string> tableDefinition = new Dictionary<string,string>();
                tableDefinition.Add("CustomerID", "int");
                tableDefinition.Add("CustomerGUID", "uniqueidentifier");
                tableDefinition.Add("Email", "nvarchar(255)");
                tableDefinition.Add("Username", "nvarchar(255)");
                tableDefinition.Add("PasswordHash", "nvarchar(255)");
                tableDefinition.Add("SaltKey", "nvarchar(255)");
                tableDefinition.Add("AffiliateID", "int");
                tableDefinition.Add("BillingAddressID", "int");
                tableDefinition.Add("ShippingAddressID", "int");
                tableDefinition.Add("LastPaymentMethodID", "int");
                tableDefinition.Add("LastAppliedCouponCode", "nvarchar(255)");
                tableDefinition.Add("LanguageID", "int");
                tableDefinition.Add("CurrencyID", "int");
                tableDefinition.Add("TaxDisplayTypeID", "int");
                tableDefinition.Add("IsTaxExempt", "nvarchar(5)");
                tableDefinition.Add("IsAdmin", "nvarchar(5)");
                tableDefinition.Add("IsGuest", "nvarchar(5)");
                tableDefinition.Add("IsForumModerator", "nvarchar(5)");
                tableDefinition.Add("TotalForumPosts", "int");
                tableDefinition.Add("Signature", "nvarchar(255)");
                tableDefinition.Add("AdminComment", "nvarchar(255)");
                tableDefinition.Add("Active", "nvarchar(5)");
                tableDefinition.Add("Deleted", "nvarchar(5)");
                tableDefinition.Add("RegistrationDate", "datetime");
                tableDefinition.Add("TimeZoneID", "nvarchar(200)");
                tableDefinition.Add("AvatarID", "int");
                tableDefinition.Add("Gender", "nvarchar(100)");
                tableDefinition.Add("FirstName", "nvarchar(100)");
                tableDefinition.Add("LastName", "nvarchar(100)");
                tableDefinition.Add("Company", "nvarchar(100)");
                tableDefinition.Add("StreetAddress", "nvarchar(100)");
                tableDefinition.Add("StreetAddress2", "nvarchar(100)");
                tableDefinition.Add("ZipPostalCode", "nvarchar(100)");
                tableDefinition.Add("City", "nvarchar(100)");
                tableDefinition.Add("PhoneNumber", "nvarchar(100)");
                tableDefinition.Add("FaxNumber", "nvarchar(100)");
                tableDefinition.Add("CountryID", "int");
                tableDefinition.Add("StateProvinceID", "int");
                tableDefinition.Add("ReceiveNewsletter", "nvarchar(5)");
                excelHelper.WriteTable("Customers", tableDefinition);

                foreach (Customer customer in customers)
                {
                    StringBuilder sb = new StringBuilder();
                    sb.Append("INSERT INTO [Customers] (CustomerID, CustomerGUID, Email, Username, PasswordHash, SaltKey, AffiliateID, BillingAddressID, ShippingAddressID, LastPaymentMethodID, LastAppliedCouponCode, LanguageID, CurrencyID, TaxDisplayTypeID, IsTaxExempt, IsAdmin, IsGuest, IsForumModerator, TotalForumPosts, Signature, AdminComment, Active, Deleted, RegistrationDate, TimeZoneID, AvatarID, Gender, FirstName, LastName, Company, StreetAddress, StreetAddress2, ZipPostalCode, City, PhoneNumber, FaxNumber, CountryID, StateProvinceID, ReceiveNewsletter) VALUES (");
                    sb.Append(customer.CustomerID); sb.Append(",");
                    sb.Append('"'); sb.Append(customer.CustomerGUID); sb.Append("\",");
                    sb.Append('"'); sb.Append(customer.Email.Replace('"', '\'')); sb.Append("\",");
                    sb.Append('"'); sb.Append(customer.Username); sb.Append("\",");
                    sb.Append('"'); sb.Append(customer.PasswordHash.Replace('"', '\'')); sb.Append("\",");
                    sb.Append('"'); sb.Append(customer.SaltKey.Replace('"', '\'')); sb.Append("\",");
                    sb.Append(customer.AffiliateID); sb.Append(",");
                    sb.Append(customer.BillingAddressID); sb.Append(",");
                    sb.Append(customer.ShippingAddressID); sb.Append(",");
                    sb.Append(customer.LastPaymentMethodID); sb.Append(",");
                    sb.Append('"'); sb.Append(customer.LastAppliedCouponCode.Replace('"', '\'')); sb.Append("\",");
                    sb.Append(customer.LanguageID); sb.Append(",");
                    sb.Append(customer.CurrencyID); sb.Append(",");
                    sb.Append(customer.TaxDisplayTypeID); sb.Append(',');
                    sb.Append('"'); sb.Append(customer.IsTaxExempt); sb.Append("\",");
                    sb.Append('"'); sb.Append(customer.IsAdmin); sb.Append("\",");
                    sb.Append('"'); sb.Append(customer.IsGuest); sb.Append("\",");
                    sb.Append('"'); sb.Append(customer.IsForumModerator); sb.Append("\",");
                    sb.Append(customer.TotalForumPosts); sb.Append(',');
                    sb.Append('"'); sb.Append(customer.Signature.Replace('"', '\'')); sb.Append("\",");
                    sb.Append('"'); sb.Append(customer.AdminComment.Replace('"', '\'')); sb.Append("\",");
                    sb.Append('"'); sb.Append(customer.Active); sb.Append("\",");
                    sb.Append('"'); sb.Append(customer.Deleted); sb.Append("\",");
                    sb.Append('"'); sb.Append(customer.RegistrationDate); sb.Append("\",");
                    sb.Append('"'); sb.Append(customer.TimeZoneID); sb.Append("\",");
                    sb.Append(customer.AvatarID); sb.Append(',');

                    //custom properties
                    sb.Append('"'); sb.Append(customer.Gender); sb.Append("\",");
                    sb.Append('"'); sb.Append(customer.FirstName); sb.Append("\",");
                    sb.Append('"'); sb.Append(customer.LastName); sb.Append("\",");
                    sb.Append('"'); sb.Append(customer.Company); sb.Append("\",");
                    sb.Append('"'); sb.Append(customer.StreetAddress); sb.Append("\",");
                    sb.Append('"'); sb.Append(customer.StreetAddress2); sb.Append("\",");
                    sb.Append('"'); sb.Append(customer.ZipPostalCode); sb.Append("\",");
                    sb.Append('"'); sb.Append(customer.City); sb.Append("\",");
                    sb.Append('"'); sb.Append(customer.PhoneNumber); sb.Append("\",");
                    sb.Append('"'); sb.Append(customer.FaxNumber); sb.Append("\",");
                    sb.Append(customer.CountryID); sb.Append(',');
                    sb.Append(customer.StateProvinceID); sb.Append(',');
                    sb.Append('"'); sb.Append(customer.ReceiveNewsletter); sb.Append("\"");
                    sb.Append(")");

                    excelHelper.ExecuteCommand(sb.ToString());
                }
            }
        }
 public CustomerCollection FetchByID(object CustomerID)
 {
     CustomerCollection coll = new CustomerCollection().Where("CustomerID", CustomerID).Load();
     return coll;
 }
Example #28
0
        public IEnumerable <Customer> Get()
        {
            IEnumerable <Customer> customerCollection = CustomerCollection.LoadAll();

            return(customerCollection);
        }
Example #29
0
 /**
  * method Page_Load
  * get all Customers and
  * fill the repeater
  */
 protected void Page_Load(object sender, EventArgs e)
 {
     CustomerCollection cc = new CustomerCollection();
     if (!cc.getAllCustomers())
     {
         //error
         lblError.Text = cc.errorMessage;
         lblError.Visible = true;
     }
     else
     {
         refreshCustomerList(cc);
     }
 }
 public CustomerCollection FetchByQuery(Query qry)
 {
     CustomerCollection coll = new CustomerCollection();
     coll.LoadAndCloseReader(qry.ExecuteReader());
     return coll;
 }
Example #31
0
        /// <summary>
        /// Export customer list to xml
        /// </summary>
        /// <param name="customers">Customers</param>
        /// <returns>Result in XML format</returns>
        public static string ExportCustomersToXML(CustomerCollection customers)
        {
            StringBuilder sb = new StringBuilder();
            StringWriter stringWriter = new StringWriter(sb);
            XmlWriter xmlWriter = new XmlTextWriter(stringWriter);
            xmlWriter.WriteStartDocument();
            xmlWriter.WriteStartElement("Customers");
            xmlWriter.WriteAttributeString("Version", SiteHelper.GetCurrentVersion());

            foreach (Customer customer in customers)
            {
                xmlWriter.WriteStartElement("Customer");
                xmlWriter.WriteElementString("CustomerID", null, customer.CustomerID.ToString());
                xmlWriter.WriteElementString("CustomerGUID", null, customer.CustomerGUID.ToString());
                xmlWriter.WriteElementString("Email", null, customer.Email);
                xmlWriter.WriteElementString("Username", null, customer.Username);
                xmlWriter.WriteElementString("PasswordHash", null, customer.PasswordHash);
                xmlWriter.WriteElementString("SaltKey", null, customer.SaltKey);
                xmlWriter.WriteElementString("AffiliateID", null, customer.AffiliateID.ToString());
                xmlWriter.WriteElementString("BillingAddressID", null, customer.BillingAddressID.ToString());
                xmlWriter.WriteElementString("ShippingAddressID", null, customer.ShippingAddressID.ToString());
                xmlWriter.WriteElementString("LastPaymentMethodID", null, customer.LastPaymentMethodID.ToString());
                xmlWriter.WriteElementString("LastAppliedCouponCode", null, customer.LastAppliedCouponCode);
                xmlWriter.WriteElementString("LanguageID", null, customer.LanguageID.ToString());
                xmlWriter.WriteElementString("CurrencyID", null, customer.CurrencyID.ToString());
                xmlWriter.WriteElementString("TaxDisplayTypeID", null, customer.TaxDisplayTypeID.ToString());
                xmlWriter.WriteElementString("IsTaxExempt", null, customer.IsTaxExempt.ToString());
                xmlWriter.WriteElementString("IsAdmin", null, customer.IsAdmin.ToString());
                xmlWriter.WriteElementString("IsGuest", null, customer.IsGuest.ToString());
                xmlWriter.WriteElementString("IsForumModerator", null, customer.IsForumModerator.ToString());
                xmlWriter.WriteElementString("TotalForumPosts", null, customer.TotalForumPosts.ToString());
                xmlWriter.WriteElementString("Active", null, customer.Active.ToString());
                xmlWriter.WriteElementString("Deleted", null, customer.Deleted.ToString());
                xmlWriter.WriteElementString("RegistrationDate", null, customer.RegistrationDate.ToString());
                xmlWriter.WriteElementString("TimeZoneID", null, customer.TimeZoneID);
                xmlWriter.WriteElementString("AvatarID", null, customer.AvatarID.ToString());


                xmlWriter.WriteElementString("Gender", null, customer.Gender);
                xmlWriter.WriteElementString("FirstName", null, customer.FirstName);
                xmlWriter.WriteElementString("LastName", null, customer.LastName);
                if (customer.DateOfBirth.HasValue)
                    xmlWriter.WriteElementString("DateOfBirth", null, customer.DateOfBirth.Value.ToBinary().ToString());
                xmlWriter.WriteElementString("Company", null, customer.Company);
                xmlWriter.WriteElementString("StreetAddress", null, customer.StreetAddress);
                xmlWriter.WriteElementString("StreetAddress2", null, customer.StreetAddress2);
                xmlWriter.WriteElementString("ZipPostalCode", null, customer.ZipPostalCode);
                xmlWriter.WriteElementString("City", null, customer.City);
                xmlWriter.WriteElementString("PhoneNumber", null, customer.PhoneNumber);
                xmlWriter.WriteElementString("FaxNumber", null, customer.FaxNumber);

                xmlWriter.WriteElementString("CountryID", null, customer.CountryID.ToString());
                Country country = CountryManager.GetCountryByID(customer.CountryID);
                xmlWriter.WriteElementString("Country", null, (country == null) ? string.Empty : country.Name);

                xmlWriter.WriteElementString("StateProvinceID", null, customer.StateProvinceID.ToString());
                StateProvince stateProvince = StateProvinceManager.GetStateProvinceByID(customer.StateProvinceID);
                xmlWriter.WriteElementString("StateProvince", null, (stateProvince == null) ? string.Empty : stateProvince.Name);
                xmlWriter.WriteElementString("ReceiveNewsletter", null, customer.ReceiveNewsletter.ToString());

                AddressCollection billingAddresses = customer.BillingAddresses;
                if (billingAddresses.Count > 0)
                {
                    xmlWriter.WriteStartElement("BillingAddresses");
                    foreach (Address address in billingAddresses)
                    {
                        xmlWriter.WriteStartElement("Address");
                        xmlWriter.WriteElementString("AddressID", null, address.AddressID.ToString());
                        xmlWriter.WriteElementString("FirstName", null, address.FirstName);
                        xmlWriter.WriteElementString("LastName", null, address.LastName);
                        xmlWriter.WriteElementString("PhoneNumber", null, address.PhoneNumber);
                        xmlWriter.WriteElementString("Email", null, address.Email);
                        xmlWriter.WriteElementString("FaxNumber", null, address.FaxNumber);
                        xmlWriter.WriteElementString("Company", null, address.Company);
                        xmlWriter.WriteElementString("Address1", null, address.Address1);
                        xmlWriter.WriteElementString("Address2", null, address.Address2);
                        xmlWriter.WriteElementString("City", null, address.City);
                        xmlWriter.WriteElementString("StateProvinceID", null, address.StateProvinceID.ToString());
                        xmlWriter.WriteElementString("StateProvince", null, (address.StateProvince == null) ? string.Empty : address.StateProvince.Name);
                        xmlWriter.WriteElementString("ZipPostalCode", null, address.ZipPostalCode);
                        xmlWriter.WriteElementString("CountryID", null, address.CountryID.ToString());
                        xmlWriter.WriteElementString("Country", null, (address.Country == null) ? string.Empty : address.Country.Name);
                        xmlWriter.WriteElementString("CreatedOn", null, address.CreatedOn.ToString());
                        xmlWriter.WriteElementString("UpdatedOn", null, address.UpdatedOn.ToString());
                        xmlWriter.WriteEndElement();
                    }
                    xmlWriter.WriteEndElement();
                }

                AddressCollection shippingAddresses = customer.ShippingAddresses;
                if (shippingAddresses.Count > 0)
                {
                    xmlWriter.WriteStartElement("ShippingAddresses");
                    foreach (Address address in shippingAddresses)
                    {
                        xmlWriter.WriteStartElement("Address");
                        xmlWriter.WriteElementString("AddressID", null, address.AddressID.ToString());
                        xmlWriter.WriteElementString("FirstName", null, address.FirstName);
                        xmlWriter.WriteElementString("LastName", null, address.LastName);
                        xmlWriter.WriteElementString("PhoneNumber", null, address.PhoneNumber);
                        xmlWriter.WriteElementString("Email", null, address.Email);
                        xmlWriter.WriteElementString("FaxNumber", null, address.FaxNumber);
                        xmlWriter.WriteElementString("Company", null, address.Company);
                        xmlWriter.WriteElementString("Address1", null, address.Address1);
                        xmlWriter.WriteElementString("Address2", null, address.Address2);
                        xmlWriter.WriteElementString("City", null, address.City);
                        xmlWriter.WriteElementString("StateProvinceID", null, address.StateProvinceID.ToString());
                        xmlWriter.WriteElementString("StateProvince", null, (address.StateProvince == null) ? string.Empty : address.StateProvince.Name);
                        xmlWriter.WriteElementString("ZipPostalCode", null, address.ZipPostalCode);
                        xmlWriter.WriteElementString("CountryID", null, address.CountryID.ToString());
                        xmlWriter.WriteElementString("Country", null, (address.Country == null) ? string.Empty : address.Country.Name);
                        xmlWriter.WriteElementString("CreatedOn", null, address.CreatedOn.ToString());
                        xmlWriter.WriteEndElement();
                    }
                    xmlWriter.WriteEndElement();
                }
                xmlWriter.WriteEndElement();
            }

            xmlWriter.WriteEndElement();
            xmlWriter.WriteEndDocument();
            xmlWriter.Close();
            return stringWriter.ToString();
        }
Example #32
0
 // FillCustomerList
 public static void FillCustomerList(CustomerCollection coll, SqlDataReader reader)
 {
     FillCustomerList(coll, reader, -1, 0);
 }