|
Hi,
in my application (running in Windows CE) I use a XML file to store some configuration data that, at runtime, I load in a DataSet.
To read and to store these data I use the following code:
Private Shared Function SetCfgData() As Boolean
Try
Dim fs As New FileStream(CGlobali.CfgDataFileComplName, FileMode.Open)
Dim xr As XmlReader = System.Xml.XmlReader.Create(fs)
CGlobali.CfgData.Clear()
CGlobali.CfgData.ReadXml(xr)
xr.Close()
fs.Close()
Catch ex As System.IO.FileNotFoundException
MessageBox.Show("File " & CGlobali.CfgDataFileComplName & " not found.")
Return False
Catch ex As XmlException
MessageBox.Show("XmlException occured: " & ex.ToString)
Return False
End Try
Return True
When the user modifies these data, they are automatically updated in the DataSet and saved in the file, at least that's what I would do...
To save the data from the DataSet to the file I do this:
Private Shared Function UpdateCgfFile() As Boolean
Try
Dim StreamEncoding As Encoding
StreamEncoding = Encoding.Unicode
Dim cfgfile As New System.IO.StreamWriter(CGlobali.CfgDataFileComplName, True, StreamEncoding)
CGlobali.CfgData.WriteXml(cfgfile)
cfgfile.Close()
Return True
Catch ex As Exception
Return False
End Try
End Function
What I would get with the above code is to update existing fields in the xml file with the new values, but what I get is that the same fields are added to the existing ones.
This is the "original" file:
="1.0"="UTF-16"
<Sezioni>
<PLC>
<IP>10.0.0.85</IP>
<Port>502</Port>
<Description></Description>
<PauComm>15000</PauComm>
<ConTOut>5000</ConTOut>
<RxTOut>5000</RxTOut>
</PLC>
</Sezioni>
and this is the file after a save:
="1.0"="UTF-16"
<Sezioni>
<PLC>
<IP>10.0.0.85</IP>
<Port>502</Port>
<Description></Description>
<PauComm>15000</PauComm>
<ConTOut>5000</ConTOut>
<RxTOut>5000</RxTOut>
</PLC>
</Sezioni>
<Sezioni>
<PLC>
<IP>192.168.1.10</IP>
<Port>502</Port>
<Description />
<PauComm>15000</PauComm>
<ConTOut>5000</ConTOut>
<RxTOut>5000</RxTOut>
</PLC>
</Sezioni>
Obviously this is not the result I want to achieve, I do not want to duplicate fields, I want to update the existing ones.
Can someone tell me what I'm doing wrong?
Thanks in advance.
|
|
|
|
|
steve_9496613 wrote: Can someone tell me what I'm doing wrong?
Dim cfgfile As New System.IO.StreamWriter(CGlobali.CfgDataFileComplName, True, StreamEncoding)
What does the second parameter in the StreamWriter do?
true to append data to the file; false to overwrite the file. If the specified file does not exist, this parameter has no effect, and the constructor creates a new file.
|
|
|
|
|
...ops...
...next time I'll be more careful...
Thanks Eddy
|
|
|
|
|
You're welcome
|
|
|
|
|
I have a assembly A that must use .NET framework 3.5. This assembly has a referense to a 3rd party assembly that has been developed with .net framework 4.0. The problem is that I can't build because the 3rd party uses FW 4.0. Is it possible to solve this?
|
|
|
|
|
Create a (console) "server" app in 4.0 that references the 3rd party assembly.
Create a connection using "Named Pipes" from your 3.5 app (as "client") to the "server".
Start the server and the client, and acccess the 4.0 assembly by the client thru the server.
(Or: use message queues; a web service (on the same machine); etc.)
|
|
|
|
|
Hey guys so atm when the user goes to the holiday page, they can do 1 of 2 things
1)use a drop down box to select 'person name' and click 'view' this will display all the current holidays for this person
2)click 'create new' which will bring the user to a create page which allows them to add a new holiday(from here they select person name from drop and and select what date from calender)
This all works, however if the user originally follows the first path of selecting a person name and clicking view(it will display their holidays) if they then take the path of 2 and click 'create' it will jump to the create page. however the drop down box will be back at 'select' i would like the existing person selected from the previous drop down to display in this drop down.
A cookie or url/parameter?
anyway Im stuck please help
I've tried a cookie.
[code]
[HttpGet]
public ViewResult Index(string sortOrder, int? currentPersonID)
{
var holidays = db.Holidays.Include("Person");
HolidayList model = new HolidayList();
if (currentPersonID.HasValue)
{
model.currentPersonID = currentPersonID.Value;
}
else
{
model.currentPersonID = 0;
}
model.PList4DD = db.People.ToList();
ViewBag.NameSortParm = String.IsNullOrEmpty(sortOrder) ? "date" : "";
var dates = from d in db.Holidays
where d.PersonId == currentPersonID.Value
select d;
switch (sortOrder)
{
case "date":
dates = dates.OrderBy(p => p.HolidayDate);
break;
}
model.HList4DD = dates.ToList();
var cookie = new HttpCookie("cookie_name", "currentPersonID");
Response.AppendCookie(cookie);
return View(model);
}
public ActionResult Create()
{
var cookie = Request.Cookies["cookie_name"];
if (cookie != null)
{
string value = cookie.Value;
}
ViewBag.cookie = cookie.Value;
ViewBag.Id = new SelectList(db.People, "Id", "Name");
return View();
//tried to use the currentPersonID in index as an int but it woudlnt allow me.
[/code]
My View
[code]
@model HolidayBookingApp.Models.startANDend
@{
ViewBag.Title = "Create";
}
<p>
<span>@ViewBag.cookie</span>
<h2>Create</h2>
<form action ="ListHolidays" id="listHolidays" method="post">
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
<legend>Holiday</legend>
<div>
@Html.LabelFor(model => model.PersonId, "Person")
</div>
<div>
@Html.DropDownListFor(model => model.PersonId,
new SelectList(ViewBag.Id, "Value", "Text"),
"---Select---"
)
@Html.ValidationMessageFor(model => model.PersonId)
</div>
<div>
@Html.LabelFor(model => model.HolidayDate)
</div>
<div>
@Html.TextBoxFor(model => model.HolidayDate)
@Html.TextBoxFor(model => model.endDate)
<script>
$("#HolidayDate").addClass('date-pick');
$("#endDate").addClass('date-pick');
$(function () {
$('.date-pick').datePicker(
{
createButton: false,
renderCallback: function ($td, thisDate, month, year) {
if (thisDate.isWeekend()) {
$td.addClass('weekend');
$td.addClass('disabled');
}
}
}
)
.bind('click',
function () {
$(this).dpDisplay();
this.blur();
return false;
}
)
.bind('dateSelected',
function (e, selectedDate, $td) {
console.log('You selected ' + selectedDate);
}
);
$('#HolidayDate').bind('dpClosed',
function (e, selectedDates) {
var d = selectedDates[0];
if (d) {
d = new Date(d);
$('#endDate').dpSetStartDate(d.addDays(0).asString());
}
}
);
$('#endDate').bind('dpClosed',
function (e, selectedDates) {
var d = selectedDates[0];
if (d) {
d = new Date(d);
$('#HolidayDate').dpSetEndDate(d.addDays(0).asString());
}
}
);
});
</script>
@Html.ValidationMessageFor(model => model.HolidayDate)
</div>
<p>
<input type="submit" value="Create"/>
</p>
</fieldset>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
@*
<p>Current Person Selected is:
@TempData["currentPersonID"]
</p>*@
[code]
Once I get this going how can i get my drop down to store the value? Any help?
Thanks
|
|
|
|
|
So the user selects holidays (start and end dates) from two calendars, the dates from start to end are then stored in the DB in separate records per date.
(thanks to help from a previous question this all works fine)
Now, I want some sort of error message which doesnt allow the button to be clicked if the dates the user are selecting already exist in the DB.
Im unsure if this is done from the view, or controller?
View:
<form action ="ListHolidays" id="listHolidays" method="post">
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
<legend>Holiday</legend>
<div>
@Html.LabelFor(model => model.PersonId, "Person")
</div>
<div>
@Html.DropDownListFor(model => model.PersonId,
new SelectList(ViewBag.Id, "Value", "Text"),
"---Select---"
)
@Html.ValidationMessageFor(model => model.PersonId)
</div>
<div>
@Html.LabelFor(model => model.HolidayDate)
</div>
<div>
@Html.TextBoxFor(model => model.HolidayDate)
@Html.TextBoxFor(model => model.endDate)
<script>
$("#HolidayDate").addClass('date-pick');
$("#endDate").addClass('date-pick');
$(function () {
$('.date-pick').datePicker(
{
createButton: false,
renderCallback: function ($td, thisDate, month, year)
{
if (thisDate.isWeekend())
{
$td.addClass('weekend');
$td.addClass('disabled');
}
}
}
)
.bind('click',
function ()
{
$(this).dpDisplay();
this.blur();
return false;
}
)
.bind('dateSelected',
function (e, selectedDate, $td)
{
console.log('You selected ' + selectedDate);
}
);
$('#HolidayDate').bind('dpClosed',
function (e, selectedDates)
{
var d = selectedDates[0];
if (d)
{
d = new Date(d);
$('#endDate').dpSetStartDate(d.addDays(1).asString());
}
}
);
$('#endDate').bind('dpClosed',
function (e, selectedDates)
{
var d = selectedDates[0];
if (d)
{
d = new Date(d);
$('#HolidayDate').dpSetEndDate(d.addDays(-1).asString());
}
}
);
});
</script>
@Html.ValidationMessageFor(model => model.HolidayDate)
</div>
<p>
<input type="submit" value="Create"/>
</p>
controller:
HttpPost] public ActionResult listHolidays(Holiday holiday, int? PersonId, string HolidayDate, string endDate) {
DateTime startDates = Convert.ToDateTime(HolidayDate),
endDates = Convert.ToDateTime(endDate);
while (startDates <= endDates)
{
if (startDates.DayOfWeek != DayOfWeek.Saturday && startDates.DayOfWeek != DayOfWeek.Sunday)
{
Holiday holiday1 = new Holiday();
holiday1.PersonId = PersonId.Value;
holiday1.HolidayDate = startDates;
db.Holidays.AddObject(holiday1);
db.SaveChanges();
}
startDates = startDates.AddDays(1);
}
return RedirectToAction("Index");
so...? if holidayDate = db.exisitng date?
Unsure how to go about this.
Please advise.
thanks
|
|
|
|
|
I'd be tempted to use this logic:
$(function () {
$('.date-pick').datePicker(
{
createButton: false,
renderCallback: function ($td, thisDate, month, year)
{
if (thisDate.isWeekend())
{
$td.addClass('weekend');
$td.addClass('disabled');
}
if (thisDate.isHoliday())
{
$td.addClass('holiday');
$td.addClass('disabled');
}
}
}
)
Where you do the check for thisDate.isWeekend, add in a check to see if the date has previously been selected as well. That way you give the user a good UI experience because you can show that a date has previously been selected. Now, you will also need to add a check in to the controller to prevent the user from adding a date that's previously been selected because you are working in a multi-user system here.
|
|
|
|
|
Ahh yes i see...the holiday method was a ice feature as well...I get what your saying Pete, but unfortunately I don't know how to hard code a check for the UI that will show what dates are already chosen, how can i pull the dates across?
Also regarding putting a check in the controller could you give any advice on this? I know what I am meant to do but don't know the syntax
datetime startDate
if statedate = db.holidayDate
MessageBox("error")
disable 'select'btn
|
|
|
|
|
Hi Pete,
Im trying to give the UI experience of date if it has been previously accepted.
In My JS file:
/**
* An Array of day names starting with Sunday.
*/
Date.dayNames = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
/**
* An Array of abbreviated day names starting with Sun.
*/
Date.abbrDayNames = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
/**
* An Array of month names starting with Janurary.
*/
Date.monthNames = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
/**
* An Array of abbreviated month names starting with Jan.
*/
Date.abbrMonthNames = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
/**
* The first day of the week for this locale.
*/
Date.firstDayOfWeek = 1;
/**
* The format that string dates should be represented as (e.g. 'dd/mm/yyyy' for UK, 'mm/dd/yyyy' for US, 'yyyy-mm-dd' for Unicode etc).
*/
Date.format = 'dd/mm/yyyy';
/**
* The first two numbers in the century to be used when decoding a two digit year. Since a two digit year is ambiguous (and date.setYear
* only works with numbers < 99 and so doesn't allow you to set years after 2000) we need to use this to disambiguate the two digit year codes.
*/
Date.fullYearStart = '20';
(function () {
function add(name, method) {
if (!Date.prototype[name]) {
Date.prototype[name] = method;
}
};
/**
* Checks if the year is a leap year.
*/
add("isLeapYear", function () {
var y = this.getFullYear();
return (y % 4 == 0 && y % 100 != 0) || y % 400 == 0;
});
/**
* Checks if the day is a weekend day (Sat or Sun).
*/
add("isWeekend", function () {
return this.getDay() == 0 || this.getDay() == 6;
});
I'm tryihg to add a check into 'isWeekend' to include dates that already exist but don't know how.
Can you Advise?
Thanks
|
|
|
|
|
Hmm - I would do this differently. In order to get the dates that had already been selected, I would call back to the server to retrieve those dates and use that to blank out those dates in the UI.
|
|
|
|
|
|
Maybe, for simplicities sake, you should just stick to informing the user that the date they picked is invalid. You seem very new to this, and adding complexity like this could well be beyond you right now - unfortunately, I don't have the time to write a fully working sample for you to demonstrate how this all hangs together.
|
|
|
|
|
No problem pete, yeah i'm a beginner at this stuff. Will just have to keep at it.
Thanks for the help though
|
|
|
|
|
No problem. Sorry I couldn't be more help here.
|
|
|
|
|
So the user can select 2 different dates, a start date and an end date from 2 calendars, when they click 'add' the dates between&including the dates selected will be added to the DB, each date as a separate record.
This works fine however I dont want weekends to be added to the DB.
Iv updated the UI of datepicker http://www.kelvinluck.com/assets/jquery/datePicker/v2/demo/datePickerCustomCellRender.html but if a user selects fri-mon for example fri,sat,sun and mon will be added to the db Iv tried to only run the code if datyofweek is not saturday or sunday
public ActionResult listHolidays(Holiday holiday, int? PersonId, string HolidayDate, string endDate)
{
DateTime startDates = Convert.ToDateTime(HolidayDate),
endDates = Convert.ToDateTime(endDate);
while (startDates <= endDates)
{
if (startDates.DayOfWeek != DayOfWeek.Saturday || startDates.DayOfWeek != DayOfWeek.Sunday)
{
Holiday holiday1 = new Holiday();
holiday1.PersonId = PersonId.Value;
holiday1.HolidayDate = startDates;
db.Holidays.AddObject(holiday1);
db.SaveChanges();
startDates = startDates.AddDays(1);
}
}
return RedirectToAction("Index");
}
any help?
Thanks
|
|
|
|
|
xnaLearner wrote: if (startDates.DayOfWeek != DayOfWeek.Saturday || startDates.DayOfWeek != DayOfWeek.Sunday)
That's an AND condition, not an OR condition. It should read:
if (startDates.DayOfWeek != DayOfWeek.Saturday && startDates.DayOfWeek != DayOfWeek.Sunday)
|
|
|
|
|
|
|
Hi,
I have created a windows service, I want to deploy it on the server. Can anybody please help me in deploying it. When I googled for it, I found that I have to have project installer file in my project.
What is project installer file, how should I write it to deploy my windows service. I am new to this windows service field, any kind of help, code snippet, or link would be very helpful.
Thanks in advance.
Thanks & Regards,
Abdul Aleem Mohammad
St Louis MO - USA
|
|
|
|
|
As long as you aren't using Visual Studio 2012, this[^] should help.
|
|
|
|
|
Hi,
I am using Visual Studio 2010 but .Net Framework 3.5, I think it should work?
Thanks & Regards,
Abdul Aleem Mohammad
St Louis MO - USA
|
|
|
|
|
It should work. The steps really didn't change.
|
|
|
|
|
So I am using the JQuery.datePicker example... http://www.kelvinluck.com/assets/jquery/datePicker/v2/demo/datePickerStartEnd.html
I had the Jquery calendar working fine, but it olnly allowed me to enter 1 date at a time and save it to the DB.
I want the user to select a start and a multiple date, run a loop through the dates and each day to the DB.
Slightly lost at the minute and any help would be appreciated....
Here is part of my view for my ActionResult create()//which allows the user to add a new day.
<form action ="ListHolidays" id="listHolidays" method="post">
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
<legend>Holiday</legend>
<div>
@Html.LabelFor(model => model.PersonId, "Person")
</div>
<div>
@Html.DropDownListFor(model => model.PersonId,
new SelectList(ViewBag.Id, "Value", "Text"),
"---Select---"
)
@Html.ValidationMessageFor(model => model.PersonId)
</div>
<div>
@Html.LabelFor(model => model.HolidayDate)
</div>
<div>
@Html.TextBoxFor(model => model.HolidayDate)
@Html.TextBoxFor(model => model.endDate)
<script>
$("#HolidayDate").addClass('date-pick');
$("#endDate").addClass('date-pick');
$(function ()
{
$('.date-pick').datePicker()
$('#HolidayDate').bind('dpClosed',
function (e, selectedDates)
{
var d = selectedDates[0];
if (d)
{
d = new Date(d);
$('#endDate').dpSetStartDate(d.addDays(1).asString());
}
}
);
$('#endDate').bind('dpClosed',
function (e, selectedDates)
{
var d = selectedDates[0];
if (d)
{
d = new Date(d);
$('#HolidayDate').dpSetEndDate(d.addDays(-1).asString());
}
}
);
});
</script>
@Html.ValidationMessageFor(model => model.HolidayDate)
</div>
<p>
<input type="submit" value="Create"/>
</p>
and my post for listHolidays:
[HttpPost]
public ActionResult listHolidays(Holiday holiday, int? PersonId, string HolidayDate, string endDate)
{
IList<DateTime> dates = new List<DateTime>();
dates.Add(DateTime.Parse(HolidayDate));
dates.Add(DateTime.Parse(endDate));
List<DateTime> orderedDates = dates.OrderBy(d => d).ToList();
for (int i = 0; i < orderedDates.Count; i++ )
{
db.Holidays.AddObject(holiday);
db.SaveChanges();
return View();
}
return RedirectToAction("Index");
}
The problem being in my list Holidays, im not sure how to run through the loop from start to end date, and add a new record to the DB for each one.
Please advise
|
|
|
|
|