public void SortByPropertyTypeThenProject_Customer(string value1, string value2) { CustomerModel model1 = new CustomerModel { PropertyType = value2, Project = value2, }; CustomerModel model2 = new CustomerModel { PropertyType = value2, Project = value1, }; CustomerModel model3 = new CustomerModel { PropertyType = value1, Project = value1, }; CustomerCollection collection = new CustomerCollection(); collection.Add(model1); collection.Add(model2); collection.Add(model3); var customers = (collection.Sort(CustomerPredicate.SortByPropertyTypeThenProject)).ToList(); Assert.Equal(value1, customers[0].Project); Assert.Equal(value1, customers[0].PropertyType); Assert.Equal(value1, customers[1].Project); Assert.Equal(value2, customers[1].PropertyType); Assert.Equal(value2, customers[2].Project); Assert.Equal(value2, customers[2].PropertyType); }
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; }
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); }
//internal void CategoryProc(IDataReader dr, FieldDictionary Fields, object Param) //{ // CategoryCollection coll = Param as CategoryCollection; // Category item = Mapper.ReadCategory(dr, Fields); // coll.Add(item); //} internal static void CustomerProc(IDataReader dr, FieldDictionary Fields, object Param) { CustomerCollection coll = Param as CustomerCollection; Customer item = Mapper.ReadCustomer(dr, Fields); coll.Add(item); }
private void btnAddCustomer_Click(object sender, EventArgs e) { Customer c = new Customer(txtFirstName.Text, txtLastName.Text, txtPhone.Text); customers.Add(c); RebindCustomers(); }
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); } }
private void btnAddCustomer_Click(object sender, EventArgs e) { Customer c = new Customer(txtFirstName.Text, txtLastName.Text, txtPhone.Text); customers.Add(c); //RebindCustomersRebindCustomers(); // Automatically called by delegate }
private void _customersGridView_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e) { // track the user delete entity so later we can persist such deletion CustomerEntity customerSelected = ((CustomerEntity)e.Row.DataBoundItem); _customersToDelete.Add(customerSelected); }
public void Add_Customer() { CustomerModel model = new CustomerModel(); CustomerCollection collection = new CustomerCollection(); collection.Add(model); Assert.Equal(1, collection.Count); }
private void btnAddCustomer_Click(object sender, EventArgs e) { int id = customers.GetNextId(); Customer c = new Customer(id, txtFirstName.Text, txtLastName.Text, txtPhone.Text); int rowsAffected = c.InsertIntoDB(); MessageBox.Show(rowsAffected + " rows affected."); customers.Add(c); //RebindCustomersRebindCustomers(); // Automatically called by delegate }
public void SortByLastName_Descending_Customer(string value1, string value2) { CustomerModel model1 = new CustomerModel { LastName = value1, }; CustomerModel model2 = new CustomerModel { LastName = value2, }; CustomerCollection collection = new CustomerCollection(); collection.Add(model1); collection.Add(model2); var customers = (collection.Sort(CustomerPredicate.SortByLastName)).ToList(); Assert.Equal(value2, customers[0].LastName); Assert.Equal(value1, customers[1].LastName); }
public static CustomerCollection ToDtoCollection(this EntityCollection <CustomerEntity> entities) { OnBeforeEntityCollectionToDtoCollection(entities); var seenObjects = new Hashtable(); var collection = new CustomerCollection(); foreach (var entity in entities) { collection.Add(entity.ToDto(seenObjects, new Hashtable())); } OnAfterEntityCollectionToDtoCollection(entities, collection); return(collection); }
private async void GetAllCustomer() { Task <List <CustomerModel> > task = Task.Run <List <CustomerModel> >(() => { var t = _customerDataAccess.GetAllData(Properties.Resources.GetAllCustomer); return(t); }); CustomerCollection.Clear(); _log.Message("Getting All Customer from the database"); var _customerCollection = await task; _customerCollection.ForEach(t => CustomerCollection.Add(t)); }
private void btnAddCustomer_Click(object sender, EventArgs e) { int id = customers.IncrementID(); Customer c = new Customer(); c.CustomerID = id; c.FirstName = txtFirstName.Text; c.LastName = txtLastName.Text; c.SSN = txtSSN.Text; c.BirthDate = dtBirthDate.Value; customers.Add(c); }
public string GetAllCustomers(HttpListenerContext ct, ActionInfo hi) { DataLogics logicsLayer = new DataLogics(); var result = logicsLayer.SelectAllCustomers(); CustomerCollection cc = new CustomerCollection(); foreach (var cust in result) { cc.Add(cust); } return(GetResponseString <CustomerCollection>(cc, ct)); }
public CustomerCollection GetCustomers() { CustomerCollection customers = new CustomerCollection(); using(IDataReader dr = new CustomerDataAdapter().GetCustomers()) { while (dr.Read()) { customers.Add(PopulateReader(dr)); } dr.Close(); } return customers; }
public static CustomerCollection Search(SearchFilter SearchKey) { CustomerCollection collection = new CustomerCollection(); using (var reader = SqlHelper.ExecuteReader("Customer_Search", SearchFilterManager.SqlSearchDynParam(SearchKey))) { while (reader.Read()) { Customer obj = new Customer(); obj = GetItemFromReader(reader); collection.Add(obj); } } return(collection); }
public CustomerCollection GetAllCustomersDynamicCollection(string whereExpression, string orderBy) { IDBManager dbm = new DBManager(); CustomerCollection cols = new CustomerCollection(); try { dbm.CreateParameters(2); dbm.AddParameters(0, "@WhereCondition", whereExpression); dbm.AddParameters(1, "@OrderByExpression", orderBy); IDataReader reader = dbm.ExecuteReader(CommandType.StoredProcedure, "SelectCustomersDynamic"); while (reader.Read()) { Customer customer = new Customer(); customer.CustomerID = Int32.Parse(reader["CustomerID"].ToString()); customer.TerritoryID = Int32.Parse(reader["TerritoryID"].ToString()); customer.AddressID = Int32.Parse(reader["AddressID"].ToString()); customer.AccountNumber = reader["AccountNumber"].ToString(); customer.CreditLimit = Decimal.Parse(reader["CreditLimit"].ToString()); customer.DeliveryDay = Int16.Parse(reader["DeliveryDay"].ToString()); customer.CustomerType = reader["CustomerType"].ToString(); customer.Name = reader["Name"].ToString(); customer.ContactName = reader["ContactName"].ToString(); customer.Email = reader["Email"].ToString(); customer.Phone = reader["Phone"].ToString(); customer.SecondPhone = reader["SecondPhone"].ToString(); customer.Fax = reader["Fax"].ToString(); customer.ModifiedDate = DateTime.Parse(reader["ModifiedDate"].ToString()); customer.BillingAddressID = Int32.Parse(reader["BillingAddressID"].ToString()); customer.ActiveFlag = Boolean.Parse(reader["ActiveFlag"].ToString()); cols.Add(customer); } } catch (Exception ex) { log.Write(ex.Message, "GetAllCustomersDynamicCollection"); throw (ex); } finally { dbm.Dispose(); } return(cols); }
public ActionResult <CustomerModel> CreateCustomer([FromForm] string data) { try { var badRequestMsg = "The data format is not supported"; CustomerModel customer = null; if (String.IsNullOrEmpty(data)) { return(BadRequest(badRequestMsg)); } if (data.Contains("|")) { customer = DataParser.Execute(data, Delimiter.Pipe); } else if (data.Contains(",")) { customer = DataParser.Execute(data, Delimiter.Comma); } else if (data.Contains(" ")) { customer = DataParser.Execute(data, Delimiter.Space); } if (customer == null) { return(BadRequest(badRequestMsg)); } _collection.Add(customer); return(Created(String.Empty, customer)); } catch (Exception ex) { if (ex is DataParsingException) { return(BadRequest(ex.Message)); } return(StatusCode(500)); } }
public static CustomerCollection GetAllItem(int CompanyID) { CustomerCollection collection = new CustomerCollection(); var sqlParams = new SqlParameter[] { new SqlParameter("@CompanyID", CompanyID), }; using (var reader = SqlHelper.ExecuteReader("Customer_GetAll", sqlParams)) { while (reader.Read()) { Customer obj = new Customer(); obj = GetItemFromReader(reader); collection.Add(obj); } } return(collection); }
public static CustomerCollection GetbyUser(string CreatedUser, int CompanyID) { CustomerCollection collection = new CustomerCollection(); Customer obj; var sqlParams = new SqlParameter[] { new SqlParameter("@CreatedUser", CreatedUser), new SqlParameter("@CompanyID", CompanyID), }; using (var reader = SqlHelper.ExecuteReader("Customer_GetAll_byUser", sqlParams)) { while (reader.Read()) { obj = GetItemFromReader(reader); collection.Add(obj); } } return(collection); }
/// <summary> /// Method for retrieving province list from Database /// </summary> /// <returns>the provinces</returns> public CustomerCollection GetProvince() { CustomerCollection provinces; using (SqlConnection connection = new SqlConnection(connectionString)) { string query = @"SELECT DISTINCT Province FROM Customer"; using (SqlCommand cmd = new SqlCommand()) { cmd.CommandType = CommandType.Text; cmd.CommandText = query; cmd.Connection = connection; connection.Open(); provinces = new CustomerCollection(); using (SqlDataReader reader = cmd.ExecuteReader()) { string province = null; while (reader.Read()) { if (!reader.IsDBNull(FIRST_INDEX)) { province = reader["Province"] as string; } provinces.Add(new Customer(province)); province = null; } } } return(provinces); } }
public CustomerCollection GetAllCustomers() { CustomerCollection customers = null; if (this.TryConnection()) { DatabaseParameters keyParameters = new DatabaseParameters(); DataTable table = this.QueryData(keyParameters, this.DataStructrure.Tables.MasterCustomer.ActualTableName); if (table == null) { return(customers); } customers = new CustomerCollection(); foreach (DataRow row in table.Rows) { CustomerObj obj2 = new CustomerObj(row[this.DataStructrure.Tables.MasterCustomer.CustomerID.ActualFieldName].ToString()) { Name1 = row[this.DataStructrure.Tables.MasterCustomer.Name1.ActualFieldName].ToString(), Name2 = row[this.DataStructrure.Tables.MasterCustomer.Name2.ActualFieldName].ToString(), City = row[this.DataStructrure.Tables.MasterCustomer.City.ActualFieldName].ToString(), Country = new CountryObj(row[this.DataStructrure.Tables.MasterCustomer.Country.ActualFieldName].ToString()), Currency = row[this.DataStructrure.Tables.MasterCustomer.Currency.ActualFieldName].ToString(), DistrChannel = row[this.DataStructrure.Tables.MasterCustomer.DistrChannel.ActualFieldName].ToString(), Division = row[this.DataStructrure.Tables.MasterCustomer.DistrChannel.ActualFieldName].ToString(), Fax = row[this.DataStructrure.Tables.MasterCustomer.Fax.ActualFieldName].ToString(), Incoterms1 = new IncotermsObj(row[this.DataStructrure.Tables.MasterCustomer.Incoterms.ActualFieldName].ToString()), Incoterms2 = row[this.DataStructrure.Tables.MasterCustomer.Incoterms2.ActualFieldName].ToString(), PaymentTerm = new TermOfPaymentObj(row[this.DataStructrure.Tables.MasterCustomer.PaymentTerms.ActualFieldName].ToString()), PO = row[this.DataStructrure.Tables.MasterCustomer.PO.ActualFieldName].ToString(), Region = new RegionObj(row[this.DataStructrure.Tables.MasterCustomer.Region.ActualFieldName].ToString()), SalesOrg = row[this.DataStructrure.Tables.MasterCustomer.SalesOrg.ActualFieldName].ToString(), Street = row[this.DataStructrure.Tables.MasterCustomer.Street.ActualFieldName].ToString(), Tel1 = row[this.DataStructrure.Tables.MasterCustomer.Tel.ActualFieldName].ToString() }; customers.Add(obj2); } } return(customers); }
public static void FillCustomerList(CustomerCollection coll, SqlDataReader reader, int totalRows, int firstRow) { int index = 0; bool readMore = true; while (reader.Read()) { if (index >= firstRow && readMore) { if (coll.Count >= totalRows && totalRows > 0) { readMore = false; } else { Customer cust = HelperMethods.GetCustomer(reader); coll.Add(cust); } } index++; } }
/// <summary> /// Method for retrieving customers list from Database /// </summary> /// <param name="selection">the selection to set</param> /// <returns>the customers</returns> public static CustomerCollection GetCustomers(int selection) { CustomerCollection customers; using (SqlConnection connection = new SqlConnection(connectionString)) { SelectionListCollection selectionList = new SelectionListCollection(); string provinceFilter = selectionList.Provinces(selection); string query; if (provinceFilter.Equals("ALL")) { query = @"SELECT CompanyName, Address, City, Province, PostalCode, CreditHold FROM Customer ORDER BY CompanyName"; } else { query = @"SELECT CompanyName, Address, 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 = connection; cmd.Parameters.AddWithValue("@province", provinceFilter); 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(1)) { address = reader["Address"] as string; } if (!reader.IsDBNull(2)) { city = reader["City"] as string; } if (!reader.IsDBNull(3)) { province = reader["Province"] as string; } if (!reader.IsDBNull(4)) { postalCode = reader["PostalCode"] as string; } if (!reader.IsDBNull(5)) { 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); } }
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); } }
//Read Data from Table public static CustomerCollection GetCustomer() { CustomerCollection customers; //connect to database using (SqlConnection conn = new SqlConnection(connString)) { //query to retrieve data from client table string query = @"SELECT * From Client912599"; using (SqlCommand cmd = new SqlCommand()) { cmd.CommandType = CommandType.Text; cmd.CommandText = query; cmd.Connection = conn; conn.Open(); customers = new CustomerCollection(); //read data using (SqlDataReader reader = cmd.ExecuteReader()) { string clientCode = null; string companyName = null; string address1 = null; string address2 = null; string city = null; string province = null; string postalCode = null; decimal ytdSale = 0m; bool creditHold = false; string notes = null; while (reader.Read()) { //get clientCode which can't be NULL from database setting clientCode = reader["ClientCode"] as string; //get CompanyName which can't be NULL from database setting companyName = reader["CompanyName"] as string; //get Address1 which can't be NULL from database setting address1 = reader["Address1"] as string; //get Address2 if (!reader.IsDBNull(3)) { address2 = reader["Address2"] as string; } //get City if (!reader.IsDBNull(4)) { city = reader["City"] as string; } //get Province which can't be NULL from database setting province = reader["Province"] as string; //get PostalCode if (!reader.IsDBNull(6)) { postalCode = reader["PostalCode"] as string; } //get YTDSales if (!reader.IsDBNull(7)) { ytdSale = (decimal)reader["YTDSales"]; } //get CreditHold if (!reader.IsDBNull(8)) { creditHold = (bool)reader["CreditHold"]; } //get Notes if (!reader.IsDBNull(9)) { notes = reader["Notes"] as string; } //Add data to customer list customers.Add(new Customer(clientCode, companyName, address1, address2, city, province, postalCode, ytdSale, creditHold, notes)); //Clear all data clientCode = null; companyName = null; address1 = null; address2 = null; city = null; province = null; postalCode = null; creditHold = false; ytdSale = 0m; notes = null; } } return(customers); } } }
public void ImportOrders() { CustomerCollection NewCustomers = new CustomerCollection(); SalesOrderHeaderCollection NewCustomerOrders = new SalesOrderHeaderCollection(); SqlCompactConnection conn = new SqlCompactConnection(); SalesOrderDetailCollection sodCol = new SalesOrderDetailCollection(); try { // conn.connect(); lblStatus.Text = "Connected to mobile database"; RefreshForm(); DataTable dtSoh = new DataTable(); string sql = "select * from salesorderheader where status=1"; dtSoh = conn.GetDataTable(sql); lblStatus.Text = "Received sales order header data (" + dtSoh.Rows.Count.ToString() + " records)"; RefreshForm(); //conn.Close(); //SalesOrderHeaderTableAdapter soh = new SalesOrderHeaderTableAdapter(); //SalesOrderDetailTableAdapter sod = new SalesOrderDetailTableAdapter(); SalesOrderHeader OrderHeader = new SalesOrderHeader(); int rows = dtSoh.Rows.Count; if (rows == 0) { MessageBox.Show("There are no records to import", "MICS", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); conn.DeleteOldOrders(); return; } // conn = new SqlCompactConnection(); DataTable dtSod = new DataTable(); sql = "select * from salesorderdetail where salesorderid in (select salesorderid from salesorderheader where status=1)"; dtSod = conn.GetDataTable(sql); lblStatus.Text = "Received sales order details data(" + dtSod.Rows.Count.ToString() + " records)"; RefreshForm(); int iCount = 0; lblStatus.Text = "Copying sales order information"; RefreshForm(); progressBar1.Minimum = 1; progressBar1.Maximum = dtSoh.Rows.Count; foreach (DataRow dr in dtSoh.Rows) { OrderHeader = new SalesOrderHeader(); int OrderID = Int32.Parse(dr["SalesOrderID"].ToString()); OrderHeader.OrderDate = DateTime.Parse(dr["OrderDate"].ToString()); OrderHeader.ShipDate = DateTime.Parse(dr["ShipDate"].ToString()); OrderHeader.DueDate = DateTime.Parse(dr["DueDate"].ToString()); OrderHeader.SalesOrderNumber = dr["SalesOrderNumber"].ToString(); OrderHeader.PurchaseOrderNumber = dr["PurchaseOrderNumber"].ToString(); OrderHeader.CustomerID = Int32.Parse(dr["CustomerID"].ToString()); if (OrderHeader.CustomerID == 0) { //This is a new customer. Customer NewCus = new Customer(); string comments = dr["Comment"].ToString(); //The comments has the territoryid and customer name in the format TerritoryID~CustomerName int pos = comments.IndexOf("~"); string territory = comments.Substring(0, pos); string CustName = comments.Substring(pos + 1); NewCus.TerritoryID = Int32.Parse(territory); NewCus.Name = CustName; NewCus.AddressID = 0; NewCus.BillingAddressID = 0; NewCus.ModifiedDate = DateTime.Now; OrderHeader.CustomerID = NewCus.AddCustomer(NewCus); NewCus.CustomerID = OrderHeader.CustomerID; NewCustomers.Add(NewCus); } OrderHeader.SalesPersonID = Int32.Parse(dr["SalesPersonID"].ToString()); OrderHeader.BillToAddressID = Int32.Parse(dr["BillToAddressID"].ToString()); OrderHeader.ShipToAddressID = Int32.Parse(dr["ShipToAddressID"].ToString()); OrderHeader.ShipMethodID = Int32.Parse(dr["ShipMethodID"].ToString()); OrderHeader.Status = byte.Parse(dr["Status"].ToString()); OrderHeader.SubTotal = decimal.Parse(dr["SubTotal"].ToString()); OrderHeader.TaxAmt = decimal.Parse(dr["TaxAmt"].ToString()); OrderHeader.TotalDue = decimal.Parse(dr["TotalDue"].ToString()); OrderHeader.Comment = "Mobile Order"; //save the mobile order id in currencyrateid OrderHeader.CurrencyRateID = OrderID; //save the mobile order id in currencyrateid OrderHeader.CurrencyRateID = OrderID; int ServerOrderID = OrderHeader.AddSalesOrderHeader(OrderHeader); OrderHeader.SalesOrderID = ServerOrderID; if (dr["CustomerID"].ToString() == "0") { //save orders of new customers in the collection NewCustomerOrders.Add(OrderHeader); } //reset the status to 9 in the mobile //Get order details in the mobile db // DataTable dtSod = new DataTable(); // sql = "select * from salesorderdetail where salesorderid=" + OrderID.ToString(); // dtSod = conn.GetDataTable(sql); //insert the details in the server foreach (DataRow drow in dtSod.Rows) { SalesOrderDetail OrderDetails = new SalesOrderDetail(); if (OrderID == Int32.Parse(drow["SalesOrderID"].ToString())) { OrderDetails.SalesOrderID = ServerOrderID; OrderDetails.ProductID = Int32.Parse(drow["ProductID"].ToString()); OrderDetails.OrderQty = short.Parse(drow["OrderQty"].ToString()); OrderDetails.UnitPrice = decimal.Parse(drow["UnitPrice"].ToString()); OrderDetails.SpecialOfferID = Int32.Parse(drow["SpecialOfferID"].ToString()); OrderDetails.UnitPriceDiscount = decimal.Parse(drow["UnitPriceDiscount"].ToString()); if (OrderDetails.UnitPriceDiscount > 0 && OrderDetails.SpecialOfferID == 0) { //check if the discount is coming from special offer deal. SpecialOfferProduct sop = new SpecialOfferProduct(); DataSet ds = new DataSet(); ds = sop.GetDiscountByProduct(OrderDetails.ProductID, OrderDetails.OrderQty); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["SpecialOfferID"] != DBNull.Value) { OrderDetails.SpecialOfferID = Int32.Parse(ds.Tables[0].Rows[0]["SpecialOfferID"].ToString()); } } } OrderDetails.LineTotal = decimal.Parse(drow["LineTotal"].ToString()); OrderDetails.CarrierTrackingNumber = ""; OrderDetails.AddSalesOrderDetail(OrderDetails); } } iCount++; //update the status of header record in the mobile to Uploaded //soh.UpdateStatusByID(OrderID); progressBar1.Value = iCount; RefreshForm(); OrderHeader = null; } lblStatus.Text = "updating sales mobile status"; //conn.UpdateMobileStatus(dtSoh); conn.UpdateMobileOrderHeader("status=9", "status=1"); MessageBox.Show(iCount.ToString() + " of " + rows.ToString() + " records imported successfully", "MICS", MessageBoxButtons.OK, MessageBoxIcon.Information); //update new order customerid for (int j = 0; j < NewCustomerOrders.Count; j++) { string update = "CustomerId=" + NewCustomerOrders[j].CustomerID.ToString(); string where = "SalesOrderID=" + NewCustomerOrders[j].CurrencyRateID.ToString(); conn.UpdateMobileOrderHeader(update, where); } //Add the new customer to the mobile database if (NewCustomers.Count > 0) { conn.SynchForm = this; conn.AddCustomer(NewCustomers); } progressBar1.Minimum = 0; progressBar1.Maximum = 100; lblStatus.Text = "Removing old orders"; progressBar1.Value = 25; RefreshForm(); conn.DeleteOldOrders(); lblStatus.Text = "Finished Removing old orders"; progressBar1.Value = 100; RefreshForm(); } catch (Exception ex) { MessageBox.Show(ex.Message, "MICS", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { conn.Close(); conn.Dispose(); } }
async void textBox1_TextChanged(object sender, TextChangedEventArgs e) { if (cts != null) { cts.Cancel(); } if (popup.IsOpen) { popup.IsOpen = false; } if (textBox1.Text.Length == 0) { CustomersListBox.SelectedItem = null; CustomersListBox.ScrollIntoView(CustomersListBox.Items[0]); } else if (textBox1.Text.StartsWith("70") || textBox1.Text.StartsWith("71") || textBox1.Text.StartsWith("76") || textBox1.Text.StartsWith("78") || textBox1.Text.StartsWith("03") || textBox1.Text.StartsWith("79") || textBox1.Text.StartsWith("81")) { CustomerCollection col = CustomersListBox.Items.SourceCollection as CustomerCollection; Customer ddd = col.FirstOrDefault(c => c.PhoneNumber.StartsWith(textBox1.Text)); foreach (Customer user in CustomersListBox.Items) { if (user.PhoneNumber.StartsWith(textBox1.Text)) { CustomersListBox.SelectedItem = user; CustomersListBox.ScrollIntoView(user); return; } } CustomersListBox.SelectedItem = null; } else { foreach (Customer user in CustomersListBox.Items) { if (user.Username.StartsWith(textBox1.Text)) { CustomersListBox.SelectedItem = user; CustomersListBox.ScrollIntoView(user); return; } } CustomersListBox.SelectedItem = null; try { cts = new CancellationTokenSource(); await Task.Delay(2000, cts.Token); cts = null; CustomerCollection equalList = new CustomerCollection(); if (textBox1.Text.Contains("ismaelr") && (ResellersComboBox.SelectedItem as Reseller).Name.Equals("ahkvoip0", StringComparison.OrdinalIgnoreCase)) { foreach (Customer c in CustomersListBox.Items) { if (c.Username.Equals("ismael")) { equalList.Add(c); didMeanText.Text = "You must select"; possibleCustomers.ItemsSource = equalList; popup.IsOpen = true; CustomersListBox.IsEnabled = false; CustomersListBox.Opacity = 0.5; return; } } } foreach (Customer c in CustomersListBox.Items) { if (LevenshteinDistance(c.Username, textBox1.Text) < 3) { equalList.Add(c); } } if (equalList.Count > 0) { didMeanText.Text = "Did you mean:"; possibleCustomers.ItemsSource = equalList; popup.IsOpen = true; CustomersListBox.IsEnabled = false; CustomersListBox.Opacity = 0.5; } } catch { } } }
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); } }
public static CustomerCollection GetCustomers() { CustomerCollection customers = new CustomerCollection(); using (SqlConnection conn = new SqlConnection(connString)) { string query = $@"SELECT ClientCode, CompanyName, Address1, Address2, City, Province, PostalCode, YTDSales, CreditHold, Notes FROM {customerTableName} ORDER By ClientCode"; using (SqlCommand cmd = new SqlCommand()) { cmd.CommandType = CommandType.Text; cmd.CommandText = query; cmd.Connection = conn; conn.Open(); using (SqlDataReader reader = cmd.ExecuteReader()) { string customerCode; string companyName; string address; string address2; string city; string province; string postalCode; decimal ytdSales; bool creditHold; string notes; while (reader.Read()) { if (!reader.IsDBNull(0)) { customerCode = reader["ClientCode"] as string; } else { customerCode = null; } if (!reader.IsDBNull(1)) { companyName = reader["CompanyName"] as string; } else { companyName = null; } if (!reader.IsDBNull(2)) { address = reader["Address1"] as string; } else { address = null; } if (!reader.IsDBNull(3)) { address2 = reader["Address2"] as string; } else { address2 = null; } if (!reader.IsDBNull(4)) { city = reader["City"] as string; } else { city = null; } if (!reader.IsDBNull(5)) { province = reader["Province"] as string; } else { province = null; } if (!reader.IsDBNull(6)) { postalCode = reader["PostalCode"] as string; } else { postalCode = null; } if (!reader.IsDBNull(7)) { ytdSales = (decimal)reader["YTDSales"]; } else { ytdSales = 0.0m; } if (!reader.IsDBNull(8)) { creditHold = (bool)reader["CreditHold"]; } else { creditHold = false; } if (!reader.IsDBNull(9)) { notes = reader["Notes"] as string; } else { notes = null; } customers.Add(new Customer { CustomerCode = customerCode, CompanyName = companyName, Address = address, Address2 = address2, City = city, Province = province, PostalCode = postalCode, YTDSales = ytdSales, CreditHold = creditHold, Notes = notes }); } } } } return(customers); }
/// <summary> /// Gets all customers in a certain province. /// </summary> /// <param name="provinceFilter">The province code (e.g. ON, BC). Use ALL for all provinces</param> /// <returns></returns> public static CustomerCollection GetCustomersByProvince(string provinceFilter) { CustomerCollection customers = new CustomerCollection(); //creating the DB connection using (SqlConnection connectionToDB = new SqlConnection(dbConnectionString)) { //querying all distingct provinces string query = string.Format("{0} {1} {2}", "SELECT CompanyName, Address, City, Province, PostalCode, CreditHold", "FROM Customer", provinceFilter.ToUpper() == "ALL" ? "" : "WHERE Province = @province"); using (SqlCommand dbCommand = new SqlCommand(query, connectionToDB)) { dbCommand.Parameters.AddWithValue("@province", provinceFilter); connectionToDB.Open(); //read the data using (SqlDataReader reader = dbCommand.ExecuteReader()) { while (reader.Read()) { string companyName = (string)reader[0]; string address = null; if (!reader.IsDBNull(1)) { address = (string)reader[1]; } string city = null; if (!reader.IsDBNull(2)) { city = (string)reader[2]; } string province = null; if (!reader.IsDBNull(3)) { province = (string)reader[3]; } string postalCode = null; if (!reader.IsDBNull(4)) { postalCode = (string)reader[4]; } bool creditHold = false; if (!reader.IsDBNull(5)) { creditHold = ((byte)reader[5] != 0); } Customer customer = new Customer { CompanyName = companyName, Address = address, City = city, Province = province, PostalCode = postalCode, CreditHold = creditHold }; customers.Add(customer); } } } } return(customers); }
public static CustomerCollection GetAllCustomers(string byProvince) { CustomerCollection customers; using (SqlConnection conn = new SqlConnection(connString)) { string query = $"SELECT CustomerCode, CompanyName, Address, City, Province, PostalCode, CreditHold From Customer {byProvince}"; using (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 = null; string companyName = null; string address = null; string city = null; string province = null; string postalCode = null; bool creditHold = false; while (reader.Read()) { if (!reader.IsDBNull(0)) { customerCode = reader["CustomerCode"] as string; } if (!reader.IsDBNull(1)) { companyName = reader["CompanyName"] as string; } if (!reader.IsDBNull(2)) { address = reader["Address"] as string; } if (!reader.IsDBNull(3)) { city = reader["City"] as string; } if (!reader.IsDBNull(4)) { province = reader["Province"] as string; } if (!reader.IsDBNull(5)) { postalCode = reader["PostalCode"] as string; } if (!reader.IsDBNull(6)) { creditHold = (bool)reader["CreditHold"]; } customers.Add(new Customer(customerCode, companyName, address, city, province, postalCode, creditHold)); customerCode = null; companyName = null; address = null; city = null; province = null; postalCode = null; creditHold = false; } } } return(customers); } }
public void Add(string customerName) { _customerCollection.Add(customerName); }