Thursday, 12 September 2013

Subtracting date by one and obey calendar correctly

Subtracting date by one and obey calendar correctly

Im attempting to subtract the day by one with localtime, but I also need
it to obey the monthly format.
For example, let's say it's July first, my program will need to display
data from June 30th with localtime, but if I subtract the date by 1 it's
not going to be helpful.
my $minutes_back = 4;
my $dt = localtime( time - $minutes_back * 60 );
my $date_from=sprintf("%d/%d/%d",$dt->mon,$dt->mday,$dt->year);
Does anyone have a better way, other than me storing the current date and
doing an eval if it's the first then backtrack to the previous month?

How can I get the GPS traces within a region from OpenStreetMap (OSM)?

How can I get the GPS traces within a region from OpenStreetMap (OSM)?

The link to download the GPS traces on OSM is quite easy to get.
However, each of the files inside is all super big. And also there is no
geolocation categorization. So I suppose the data inside can be the GPS
traces from any part of the world.
What if I just need the GPS traces within ONE location, say Boston city?
How can I get that?

Wednesday, 11 September 2013

unable to get changed culture value

unable to get changed culture value

i am not able to get changed culture value.i have drowdownlist .After
changing of dropdown value my culture is going to change.but everytime i
am geting english culture value.please let me know how to get value as per
culture changed.
below is my code:
protected void ddlclick_SelectedIndexChanged(object sender, EventArgs e)
{
Session["CurrentUI"] = "pa-IN";
Response.Redirect(Request.Url.OriginalString);
}
protected void Page_Load(object sender, EventArgs e)
{
if (Session["CurrentUI"] != null)
{
String selectedLanguage = (string)Session["CurrentUI"];
UICulture = selectedLanguage;
Culture = selectedLanguage;
Thread.CurrentThread.CurrentCulture =
CultureInfo.CreateSpecificCulture(selectedLanguage);
Thread.CurrentThread.CurrentUICulture = new
CultureInfo(selectedLanguage);
}
base.InitializeCulture();
if (Thread.CurrentThread.CurrentCulture.ToString() == "pa-IN")
{
string ind1 =(string)ResourceDLL.abc.company.company1.Name;
lblmsg.Text = ind1;
}
}

WPF Change colour of checkmark in Listboxitem with ItemTemplate

WPF Change colour of checkmark in Listboxitem with ItemTemplate

Any WPF experts out there who can show me how to modify my styles in order
to change the the colour of the checkmark of a Checkbox contained in a
ListBoxItem. So far I have the following which is cobbled together from
MahApps styling:
<Style TargetType="ListBox" BasedOn="{StaticResource MetroListBox}"
x:Key="CheckBoxList" >
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBox}">
<Border BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding
BorderThickness}"
Background="{TemplateBinding Background}"
CornerRadius="3">
<ScrollViewer>
<ItemsPresenter />
</ScrollViewer>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="ItemTemplate">
<Setter.Value>
<DataTemplate>
<CheckBox IsChecked="{Binding
RelativeSource={RelativeSource AncestorType={x:Type
ListBoxItem}}, Path=IsSelected}"
Content="{Binding}"/>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="ListBoxItem" BasedOn="{StaticResource MetroListBoxItem}">
<Setter Property="MinHeight" Value="20" />
<Setter Property="Margin" Value="0,0,0,5" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">
<Border x:Name="Border"
Background="{TemplateBinding Background}"
SnapsToDevicePixels="True">
<ContentPresenter Margin="5, 0, 0, 0"
VerticalAlignment="{TemplateBinding
VerticalContentAlignment}" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter TargetName="Border" Property="Background"
Value="{DynamicResource AccentSelectedColorBrush}"
/>
<Setter Property="Foreground"
Value="{DynamicResource TextBrush}" />
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="Border" Property="Background">
<Setter.Value>
<SolidColorBrush Color="{DynamicResource
AccentColor3}" />
</Setter.Value>
</Setter>
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Foreground"
Value="{DynamicResource GrayBrush5}" />
</Trigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsEnabled" Value="False" />
<Condition Property="IsSelected" Value="True" />
</MultiTrigger.Conditions>
<MultiTrigger.Setters>
<Setter TargetName="Border"
Property="Background" Value="{DynamicResource
GrayBrush5}" />
<Setter Property="Foreground"
Value="{DynamicResource
AccentSelectedColorBrush}" />
</MultiTrigger.Setters>
</MultiTrigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsSelected" Value="True" />
<Condition
Property="Selector.IsSelectionActive"
Value="True" />
</MultiTrigger.Conditions>
<Setter TargetName="Border" Property="Background"
Value="{DynamicResource AccentSelectedColorBrush}"
/>
</MultiTrigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsMouseOver" Value="True" />
<Condition
Property="Selector.IsSelectionActive"
Value="True" />
</MultiTrigger.Conditions>
<MultiTrigger.Setters>
<Setter TargetName="Border"
Property="Background">
<Setter.Value>
<SolidColorBrush
Color="{DynamicResource AccentColor3}"
/>
</Setter.Value>
</Setter>
</MultiTrigger.Setters>
</MultiTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Regards Alan

How to change FOR XML PATH to run in SQL 2000

How to change FOR XML PATH to run in SQL 2000

Please provide updated code example based on my code that would execute in
SQL 2000. I'm aware that FOR XML PATH does not work in SQL 2000.
Here is my code:
SELECT @group_ids = STUFF(( SELECT DISTINCT '],[' + LTRIM(groupid)
FROM #DistinctPages
ORDER BY '],[' + LTRIM(groupid)
FOR XML PATH('')
), 1,2, '') + ']'
--set details of report to -- if the value is null
SELECT @colsNull = STUFF((SELECT ', coalesce(' + QUOTENAME(groupid) +',
''--'') as '+QUOTENAME(groupid)
FROM #DistinctPages
GROUP BY groupid
ORDER BY groupid
FOR XML PATH(''), TYPE ).value('.', 'NVARCHAR(MAX)') ,1,1,'')

What priority/precedence is applied to multiple xsl:imported stylesheets?

What priority/precedence is applied to multiple xsl:imported stylesheets?

What priorities or precedence rules, if any, are applied to A.xsl, B.xsl,
and C.xsl by virtue of the order in which they are imported?
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:my="http://me"
version="2.0">
<xsl:import href="A.xsl"/>
<xsl:import href="B.xsl"/>
<xsl:import href="C.xsl"/>
...

Spring form send null model object to database

Spring form send null model object to database

I want to send data from form to PostgreSQL. When I send data by form,
hibernate save (by save() method) blank record .. I did it manually (for
test) without using form and then everything is ok.
Spitter.class (entity for user)
@Entity
@Table(name="spitter")
public class Spitter implements Serializable {
private static final long serialVersionUID = 829803238866007413L;
@Id
//@SequenceGenerator(name = "hibernate_sequence")
@GeneratedValue(strategy=GenerationType.AUTO) @Column(name="spitter_id")
private Long id;
@Column(unique=true) @Size(min=3, max=20) @Pattern(regexp =
"^[a-zA-Z0-9]+$", message="Nie poprawna nazwa uzytkownika.")
private String username;
@Size(min=5, max=15, message="Haslo musi miec minimum 5 znakow.")
private String password;
@Size(min=3, max=25, message="Blad w imieniu i nazwisku.")
private String fullName;
@OneToMany(mappedBy="spitter")
private List<Spittle> spittles;
@Email(message="Nie poprawny adres email.")
private String email;
private boolean updateByEmail;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getFullName() {
return fullName;
}
public void setFullName(String fullName) {
this.fullName = fullName;
}
public List<Spittle> getSpittles() {
return spittles;
}
public void setSpittles(List<Spittle> spittles) {
this.spittles = spittles;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public void setUpdateByEmail(boolean updateByEmail) {
this.updateByEmail = updateByEmail;
}
public boolean isUpdateByEmail() {
return updateByEmail;
}
@Override
public boolean equals(Object obj) {
Spitter other = (Spitter) obj;
return other.fullName.equals(fullName) &&
other.username.equals(username) && other.password.equals(password);
}
@Override
public int hashCode() {
// TODO Auto-generated method stub
return super.hashCode();
}
}
SpitterController.class createSpitterProfile - shows form (edit.jsp) and
sends model object (spitter) to form addSpitterFromForm - receives binding
data from form and save it to database and redirects to simply user
profile showSpitterProfile - there is of course null model object
exception
@Controller
@RequestMapping("/spitters")
public class SpitterController {
private final SpitterService spitterService;
@Inject //@Autowired
public SpitterController(SpitterService spitterService) {
this.spitterService = spitterService;
}
//...
@RequestMapping(method = RequestMethod.GET, params = "new")
public String createSpitterProfile(Model model) {
model.addAttribute("spitter", new Spitter());
return "spitters/edit";
}
@RequestMapping(method = RequestMethod.POST)
public String addSpitterFromForm(@Valid Spitter spitter, BindingResult
bindingResult) {
if(bindingResult.hasErrors())
return "spitters/edit";
spitterService.saveSpitter(spitter);
return "redirect:/spitters/" + spitter.getUsername();
}
@RequestMapping(value="/{username}", method = RequestMethod.GET)
public String showSpitterProfile(@PathVariable String username, Model
model) {
model.addAttribute(spitterService.getSpitter(username));
return "spitters/view";
}
edit.jsp (registration form for new user (Spitter))
<%@ taglib prefix="sf" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="s" uri="http://www.springframework.org/tags"%>
<div>
<h2>New account test</h2>
<sf:form method="POST" modelAttribute="spitter"
enctype="multipart/form-data">
<fieldset>
<table>
<tr>
<th><sf:label path="fullName">Full name:</sf:label></th>
<td><sf:input path="fullName" size="15" /><br/>
<sf:errors path="fullName" cssClass="error" />
</td>
</tr>
<tr>
<th><sf:label path="username">Username:</sf:label></th>
<td><sf:input path="username" size="15" maxlength="15" />
<small id="username_msg">No spaces, please.</small><br/>
<sf:errors path="username" cssClass="error" />
</td>
</tr>
<tr>
<th><sf:label path="password">Password:</sf:label></th>
<td><sf:password path="password" size="30"
showPassword="true"/>
<small>6 characters or more (be tricky!)</small><br/>
<sf:errors path="password" cssClass="error" />
</td>
</tr>
<tr>
<th><sf:label path="email">Email Address:</sf:label></th>
<td><sf:input path="email" size="30"/>
<small>In case you forget something</small><br/>
<sf:errors path="email" cssClass="error" />
</td>
</tr>
<tr>
<th></th>
<td>
<sf:checkbox path="updateByEmail"/>
<sf:label path="updateByEmail">Send me email updates!</sf:label>
</td>
</tr>
<tr>
<th></th>
<td>
<input name="commit" type="submit"
value="I accept. Create my account." />
</td>
</tr>
</table>
</fieldset>
</sf:form>
</div>
and blank saved record to Postgres..