I'm new to Java and Blackberry and i'm stuck with a registration screen, due to the fallowing:
I have a registration screen, where i show 2 radiobuttons, male and female. Only these 'labels' are not for me to write, it's a value and a tag that i request to a webservice.
What i needed was something like:
MyRadioButton rb1=(String label, String value, Group rbg);
and it's Super(label, value, group); ---this value more of an internal label ID, so to speak, a pk_id.---
so i could, after, retrieve which Rbutton was selected and it's value, so i could send it back when i click the Register Button.
I have an example of how to do it, but not for blackberry:
Gender[] gender = WebServCall.GetUserGender();
if (gender != null && gender.length == 2)
{
holder.radiob1.setText(gender[0].genderType);
holder.radiob1.setTag(gender[0].PK_ID);
holder.radiob2.setText(gender[1].genderType);
holder.radiob2.setTag(gender[1].PK_ID);
}
else
{
//alert
}
}
static class ViewHolder
{
RadioButton radiob1;
RadioButton radiob2;
}
(...)
//Get the inserted information, by the user
...
RadioButton register_buffer_Gender1 = (RadioButton) findViewById(R.id.radiob1);
RadioButton register_buffer_Gender2 = (RadioButton) findViewById(R.id.radiob2);
...
boolean check1 = register_buffer_Gender1.isChecked();
boolean check2 = register_buffer_Gender2.isChecked();
....
Could you give and example of how to do this, but for blackberry?
Thank you
The approach is actually pretty similar in BlackBerry development:
//Setting up the buttons
RadioButtonGroup group = new RadioButtonGroup();
RadioButtonField radio1 = new RadioButonField(gender[0].genderType, group);
radio1.setCookie(gender[0].PK_ID);
RadioButtonField radio2 = new RadioButtoNField(gender[1].genderType, group);
radio2.setCookie(gender[1].PK_ID);
add(radio1);
add(radio2);
////////////////////////
//Retrieving info from the buttons
boolean check1 = radio1.isSelected();
boolean check2 = radio2.isSelected();
//or you can use the group
int checkedIndex = group.getSelectedIndex();
I would suggest taking a look at the documentation on RadioButtonField and RadioButtonGroup, should get you on your way.
Related
I'am new in MVC and I encountered this challenge. Where I have 2 queries but it is almost similar. One is for summary and other one is for drilldown.
What I want to achieve is to create two command text in one list controller, and control it by radio buttons.
The idea is something like this:
o Drilldown
o Summary
when I click the drilldown button, i will call the first query and vice versa with the summary.
My problem is I didn't know what's the right way to control this things.
[System.Web.Http.HttpPost]
public List<ChartData> GetData(STANDCST0058Criteria criteria)
{
List<ChartData> result = new List<ChartData>();
using (var mgr = WebDatabaseHelper.GetHelper())
{
PCommand cmd = mgr.GetSQLCommand();
string draw_myprojects = #"select distinct
p.projectno,
CAST(sum ((cp.samplecost1) / 1000) AS DECIMAL(12,0)) as SC_1,
CAST(sum ((cp.samplecost2) / 1000) AS DECIMAL(12,0)) as SC_2
GROUP BY p.projectno";
string draw_summary = #"SELECT
CAST(sum ((cp.samplecost1) / 1000) AS DECIMAL(12,0)) as SC_1,
CAST(sum ((cp.samplecost2) / 1000) AS DECIMAL(12,0)) as SC_2";
cmd.AddParameter("#projectId", criteria.Project);
var dr = cmd.ExecuteReader();
while (dr.Read())
{
result.Add(new ChartData()
{
ProjectNo = dr.GetString("ProjectNo"),
SC_1 = dr.GetDecimal("SC_1"),
SC_2 = dr.GetDecimal("SC_2"),
});
}
dr.Close();
}
return result;
}
I'm trying to create a list of orders in a custom Controller in a NopCommerce/MVC application and i want the list to be sorted by creationDate and contain total orders for that date and convert these values to string format.
The thing is i don't want an ActionResult displaying a grid in the view like in Admin/Orders. All i want is a List of all paid orders between model.StartDate and model.EndDate that contains two parameters "CreationDateUtc" and TotalOrders". i simply just need a list containing the data of orders sorted by creationdate.
The if i choose StartDate 2014-03-29 and EndDate 2014-04-02 the output i want would look something like this:
List OrdersTotalList with parameters CreationDateUtc and TotalOrders
CreationDateUtc "2014-03-29"
TotalOrders "562"
CreationDateUtc "2014-03-30"
TotalOrders "485"
CreationDateUtc "2014-03-31"
TotalOrders "733"
CreationDateUtc "2014-04-01"
TotalOrders "729"
CreationDateUtc "2014-04-02"
TotalOrders "681
"
I'm trying to access the data by an implementations of OrderList from OrderController in my CustomController. Problem is this method always returns 10 objects when infact the total number of orders within this timespace is 58. When debugging Total = orders.TotalCount are actually showing 58 orders as one int value). Also a gridmodel is used here but i really don't need a gridmodel, i just need the data from the database:
public List OrderList(GridCommand command, OrderListModel model, OrderModel Omodel)
{
DateTime S = new DateTime(2014, 3, 29); //-- Dates for testing
DateTime E = new DateTime(2014, 4, 02);
model.StartDate = S;
model.EndDate = E;
DateTime? startDateValue = (model.StartDate == null) ? null
: (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.StartDate.Value, _dateTimeHelper.CurrentTimeZone);
DateTime? endDateValue = (model.EndDate == null) ? null
: (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.EndDate.Value, _dateTimeHelper.CurrentTimeZone).AddDays(1);
OrderStatus? orderStatus = model.OrderStatusId > 0 ? (OrderStatus?)(model.OrderStatusId) : null;
PaymentStatus? paymentStatus = model.PaymentStatusId > 0 ? (PaymentStatus?)(model.PaymentStatusId) : null;
ShippingStatus? shippingStatus = model.ShippingStatusId > 0 ? (ShippingStatus?)(model.ShippingStatusId) : null;
//load orders
var orders = _orderService.SearchOrders(startDateValue, endDateValue, orderStatus,
paymentStatus, shippingStatus, model.CustomerEmail, model.OrderGuid, command.Page - 1, command.PageSize);
var gridModel = new GridModel<OrderModel>
{
Data = orders.Select(x =>
{
var customerCurrency = _currencyService.GetCurrencyByCode(x.CustomerCurrencyCode);
var totalInCustomerCurrency = _currencyService.ConvertCurrency(x.OrderTotal, x.CurrencyRate);
return new OrderModel()
{
Id = x.Id,
OrderTotal = _priceFormatter.FormatPrice(totalInCustomerCurrency, true, customerCurrency),
OrderStatus = x.OrderStatus.GetLocalizedEnum(_localizationService, _workContext),
PaymentStatus = x.PaymentStatus.GetLocalizedEnum(_localizationService, _workContext),
ShippingStatus = x.ShippingStatus.GetLocalizedEnum(_localizationService, _workContext),
CreatedOn = _dateTimeHelper.ConvertToUserTime(x.CreatedOnUtc, DateTimeKind.Utc)
};
}),
Total = orders.TotalCount <-- Returns all orders (58) but as an integer
};
var reportSummary = _orderReportService.GetOrderAverageReportLine
(orderStatus, paymentStatus, shippingStatus, startDateValue, endDateValue, model.CustomerEmail);
var profit = _orderReportService.ProfitReport
(orderStatus, paymentStatus, shippingStatus, startDateValue, endDateValue, model.CustomerEmail);
var aggregator = new OrderModel()
{
aggregatorprofit = _priceFormatter.FormatPrice(profit, true, false),
aggregatortax = _priceFormatter.FormatPrice(reportSummary.SumTax, true, false),
aggregatortotal = _priceFormatter.FormatPrice(reportSummary.SumOrders, true, false)
//aggregatordates =
};
List<Order> TotalProductsSold = new List<Order>();
foreach (var o in orders)
{
TotalProductsSold.Add(o);
}
return TotalProductsSold.ToList(); //<-- returns 10 orders containing all order info
}
If i understand correct in order to archive this i have to first search through orders and if their PaymentStatus is Paid. Then create a List in the Method from above. A foreach loop could iterate through orders and add orders to the List, all though i need to specify i only want CreationDate and TotalOrders for that date as parameters in the List.
I know this isn't right but i emagine something similar. The thing is i need a list of order objects and not one object with one value:
List<OrderModel> OrdersTotalList = new List<OrderModel>();
foreach (var o in orders)
{
OrderModel OM = new OrderModel(OM.OrderTotal, OM.CreatedOn);
OrdersTotalList.Add(OM);
}
return OrdersTotalList; //--
Am i completely of or is this the right aproach? I was hoping someone more familiar with NopCommerce knows more about this.
Sorry for all the text
Thank you
Solved.
In order to get a full list of orders you can create a new constructor in IOrderService/OrderService that is of type List instead of IPagedList. The method used for searching orders are called "SearchOrders" and is of type IPagedList. IPagedList contains the property PageSize wich results in only 10 orders.
You can create a new method with same implementation as SearchOrders and change IPagedList to List, remove "int pageIndex" and "int pageSize".
Then use:
_orderService.YourNewConstructor(DateTime? startTime, DateTime? endTime,
OrderStatus? os, PaymentStatus? ps, ShippingStatus? ss, string billingEmail,
string orderGuid)
{
some code...
}
This will give you access to all orders.
I am fairly new to SharePoint development and as you may all know that it is very basic for one to know how to access fields in a choice column...
My problem:
I want to access the values of the Check Boxes from a Choice Column.
For Example:
I have a document library called Libe, this document library has a custom column with type Choice and has 4 checkboxes with the values:
Category 1
Category 2
Category 3
Category 4
How do I get the values like literally the text values of what is in the Check Box List: "Category 1", "Category 2" ... "Category 4".
Any ideas?
I can access the column fine and get the selected values, I just do not know how to get the values the user can choose from.
Answer
SPFieldMultiChoice Fld = (SPFieldMultiChoice)list.Fields["Column"];
List<string> fieldList = new List<string>();
foreach (string str in Fld.Choices)
{
fieldList.Add(str);
}
Above is the answer, I can't answer my own question until I have a 100 rep.
using (SPSite site = new SPSite("http://servername/"))
{
using (SPWeb web = site.OpenWeb())
{
SPList list = web.Lists["ListName"];
string values = list["yourColumn"] as string;
string[] choices = null;
if (values != null)
{
choices = values.Split(new string[] { ";#" }, StringSplitOptions.RemoveEmptyEntries);
}
}
}
You can try this code for getting choice field value from document library.
I'm obviously still missing something about how to bind the selected item in a DropDownList.
I set up the SelectList like this in a repository:
public SelectList GetAgencyList(System.Guid donorId, Int32 selected)
{
AgenciesDonorRepository adRepo = new AgenciesDonorRepository();
List<AgenciesDonor> agencyDonors = adRepo.FindByDonorId(donorId);
IEnumerable<SelectListItem> ad = from a in agencyDonors
select new SelectListItem {
Text = a.Agencies.AgencyName,
Value = a.AgenciesDonorId.ToString()
};
return(new SelectList(ad, "Value", "Text", (selected == 0 ? 0 : selected)));
}
Then in the controller, this:
ViewData["AgenciesDonorList"] = repo.GetAgencyList(donorId, ccResult.AgenciesDonors.AgenciesDonorId);
return View(ccResult);
And in the view, this:
<%=Html.DropDownList("AgenciesDonorList", (IEnumerable<SelectListItem>)ViewData["AgenciesDonorList"])%>
In the debugger right before return View(...), I can see the proper item is selected (true) and all others are false. But in the view, the select option never makes it, and the first time is always shown.
Does this have nything to do with my use of int as the selected param?
Thx. Dale
Change GetAgencyList to:
public SelectList GetAgencyList(System.Guid donorId, Int32 selected)
{
AgenciesDonorRepository adRepo = new AgenciesDonorRepository();
List<AgenciesDonor> agencyDonors = adRepo.FindByDonorId(donorId);
var ad = from a in agencyDonors
select new {
Text = a.Agencies.AgencyName,
Value = a.AgenciesDonorId
};
return(new SelectList(ad, "Value", "Text", selected));
}
ad doesn't have to be of type IEnumerable<SelectListItem>. Is AgenciesDonorId Int32?
I would have to agree with LukLed I am not sure what you are doing with the statement: (selected == 0 ? 0 : selected) If I pass in a 0 then it returns 0 and if I pass in something other than 0 then it uses that value.
Edit:
Oh... I see it. Change the cast:
<%=Html.DropDownList("AgenciesDonorList", (IEnumerable<SelectListItem>)ViewData["AgenciesDonorList"])%>
To:
<%=Html.DropDownList("AgenciesDonorList", (SelectList)ViewData["AgenciesDonorList"])%>
I'm trying to do something similar to this post where I don't pull back all columns from a particular entity, however my framework makes use of inheritence and I lose scope of the entity type after it's been cast to an anonymous type.
The structure of my Entity Framework has a base entity called Action. From here I've created two inherited entities called Event and Activity. I want to pull back the last X Actions and pass them to my strongly typed view which accepts an Action and from there determines if its an Activity or Event and renders the correct partial view.
if(Model.GetType() == typeof(Event))
{
//render Event view
}
else if(Model.GetType() == typeof(Activity))
{
//render Activity view
}
I can pull the last 10 as an anonymous type and then cast:
var result = from a in new DataContext().Actions
where a.UserId == someGuidValue
select new { a.CreatedOn, a.Summary };
List<Action> list = result.AsEnumerable()
.Select(o => new Action {
CreatedOn = o.CreatedOn,
Summary = o.Summary
}).ToList();
However, once I pass the new List of Actions to my strongly typed view it loses scope of whether it's an Activity or an Event since it's been cast as an Action. My question is, without exposing the discriminator column, is there any way to cast each item to the proper type or am I going about this the wrong way?
A bit kludgy, but will work:
var result = from a in new DataContext().Actions
where a.UserId == someGuidValue
let IsEvent = a as Event != null
select new { a.CreatedOn, IsEvent, a.Summary };
List<Action> list = result.AsEnumerable()
.Select(o => o.IsEvent ?
(Action) new Event {
CreatedOn = o.CreatedOn,
Summary = o.Summary
}
: (Action) new Activity {
CreatedOn = o.CreatedOn,
Summary = o.Summary
}
}).ToList();
Example with type-specific columns, presuming that e.EventSpecific is of a nullable type.
var result = from a in new DataContext().Actions
where a.UserId == someGuidValue
let ev = a as Event
let IsEvent = ev != null
select new { a.CreatedOn, IsEvent, a.Summary, ev.EventSpecific };
List<Action> list = result.AsEnumerable()
.Select(o => o.IsEvent ?
(Action) new Event {
CreatedOn = o.CreatedOn,
Summary = o.Summary,
EventSpecific = o.EventSpecific
}
: (Action) new Activity {
CreatedOn = o.CreatedOn,
Summary = o.Summary,
EventSpecific = o.EventSpecific // will be null, but using o.EventSpecific saves casting
}
}).ToList();
If o.EventSpecific is of a non-nullable type, then you must convert it to a nullable type in the L2E query.
You are probably on the wrong way. At first I would assume that Action should be an abstract class and you should not be able to create instances of it at all. If you then only fetch a subset of the properties and the subset does no longer allow to discriminate between events and activities, it is probably the wrong way to try making events and activities out of them.
So it actually seems not to be a technical problem - it should be quite easy to include some discrimination information in the anonymous type - but a design problem. I suggest to rethink if it is required to discriminate the query result and if so if it is really a good idea to discriminate the result in absence of an discriminator.