Simple message application using devexpress? - devexpress

I have an application created with vb.net 2010 / SQl server 2008r2 / Devexpress 2011.2
This applicaion is used by several users in network , and the database is on a server.
Now I'm thinking to create inside this application a send/receive message system.
It's a simple idea : There is a table in database that hold the messages. A user create a message in this table , and other user query this table on some intervals , and if there is a new message they can read the new record from this table and read the message.
I know how can i do this , but i don't know if there is a control on devexpress that can help me to display the messages like in a email program.
Thank you !

No, there is no pre created control on devexpress that can help you to display the messages like in a email program. But you can create a program with the help of these control, even in DevExpress XtraNavBar Demo have such type demo application that may help you to create such application that you want.
Check this demo screen:

The best I can think is to use a ASPxGridview (with detail row) and to refresh it client side periodically.
Just like the example above, you'll need three columns (1 image for the read state, 1 for the title and 1 for the sender), in the detail row you can display the message.
It should be something like this :
<dx:ASPxGridView runat="server" ID="grid" DataSourceID="datasource" KeyFieldName="Id">
<Columns>
<dx:GridViewDataImageColumn FieldName="ImageUrl" Caption="&nbsp" Width="30px">
...
</dx:GridViewDataColumn>
<dx:GridViewDataTextColumn FieldName="Title"/>
<dx:GridViewDataTextColumn FieldName="Sender"/>
</Columns>
<Templates>
<DetailRow>
...
</DetailRow>
</Templates>
</dx:ASPxGridView>

Related

How can i populate and optimize DropDownList from WebService using Select2.js

I'm working on customer selection module that will autocomplete while typing. It seems that Select2.js would do the job, I already managed to populate my dropdownlist but on the back-end (.cs file) with a simple data binding.
The problem is, I am only working with a sample data of 15 customers so the performance is just fine, i am expecting an actual data of almost 2000 customers so just by binding would messed up the performance.
here is my code for the binding event and implementation of select2.js
.aspx file:
<asp:DropDownList runat="server" ID="ddlCustomers" CssClass="form-control" async="">
<asp:ListItem></asp:ListItem>
</asp:DropDownList>
.cs file:
protected void BindDropDownCustomers()
{
DataTable dt = SharedClass.getAPI("CustomerProfile_All"); //Returns Data from Webservice
DataColumn newColumn = new DataColumn();
//just formating the display
newColumn.ColumnName = "FullName";
newColumn.DataType = System.Type.GetType("System.String");
newColumn.Expression = "Cust_Last_Name+', '+Cust_First_Name";
dt.Columns.Add(newColumn);
ddlCustomers.DataTextField = "FullName";
ddlCustomers.DataValueField = "SmartCardID";
ddlCustomers.DataSource = dt.DefaultView;
ddlCustomers.DataBind();
ddlCustomers.Items.Insert(0, new ListItem("Select Customer", ""));
}
select2.js script:
$('#<%= ddlCustomers.ClientID %>').select2({
placeholder: "Select customer",
minimumResultsForSearch: 2,
minimumInputLength: 3,
allowClear: true
});
I want something like, after the user enters a minimum of 3 characters, a query will be executed and get all related data that will populate the dropdownlist and limit or optimize the display at the same time.
Well, In my opinion, running a loop 2,000 times on a client machine using javascript (it would be better to check if the chars that were typed by user were more than 3 here) is fine instead of making a call to the server and opening SQL Connection to query something whenever user types something. Think of it as when the network will be slow the lag would be more and what if tens of thousands users make the same call to the server and server is just searching through the records? Well that was just an opinion. Of course, you can decide what is suitable for you.
If you still want to do it, you can either look out for some paid controls or see if there is one in ajax toolkit.
Moreover, if you want to do it in a custom way then you can use jquery-ui autocomplete to achieve the task.
I am not going to give the source code to do that but here is the rough idea that you might want to do:
Show a basic few records on load
Hook up jQuery-UI autocomplete to the text box that is searching and returning the results from the db
Add Custom HTML when you get the respond as it is in your HTML page and Hook up jquery/javascript events to select the relevant values.
Hope this gives a rough idea.

Send an ok/cancel confirm with database data? ASP.Net VB

Can someone help me with this:
I want to send a confirm message to the user if a button is clicked. But the problem is that I want server data on the message.
For Example:
|¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯|
| You are going to delete |
| 4 messages, are you sure? |
| |
| |OK| |Cancel| |
|___________________________|
The number 4 is brought from database with a Stored Procedure.
If the user clicks OK it should do some other code, if cancel is clicked, it should just return...
This is for a website on ASP.net using Visual Basic.
Please help!
Update:
After #T.S. answer I came up with this:
'Method for receiving the number...
'messages = numberReceived
Page.ClientScript.RegisterStartupScript(Me.GetType, "Confirmation", "<script> if (confirm('You will delete " & messages.ToString & " messages, are you sure?')) { ConfirmOnClean() }; </script>", False)
And the javascript function ConfirmOnClean() gets called correctly. What can I do to call a method on the codebehind after the user clicked OK?
Update:
I Finally solved it by Just adding a hidden field on the form:
<asp:HiddenField ID="cleanStatus" Value="dontClean" runat="server" />
And then on the Confirm on clean function I just did:
function ConfirmOnClean() {
$('#<%=cleanStatus.ClientId %>').val('clean');
__doPostBack('<%=btnClean %>','');
}
And on the Page_Load method on my codebehind I added:
If cleanStatus.Value.Equals("clean") Then
OnConfirm() 'Method for calling the stored procedure for deleting the messages.
End If
I hope this helps someone!
Your question is lacking concrete code. So here is one option:
Assume you have some Id. You call stored proc
Dim message as String
Using cmd as new SqlCommand(...
cmd.ExecuteNoQuery()
' retrieve your parameters here
message = cmd.Parameters(0).Value
End Using
Now code returns to the user with the values you retrieved. You can register script block to show the message immediately on the page http://msdn.microsoft.com/en-us/library/z9h4dk8y%28v=vs.110%29.aspx
When user User clicks Ok, you can, for example, set a hidden field with a value and invoke postback. YOur aspx page will read the value and invoke DB-call to delete values.
You need to provide more details to get more concrete solution here

Store and retrieve the content on page postback.

I want to store the content in a format like this, and be able to retrieve after page postback. Can I use a Hidden field? If so which datatype (not string?) Stringbuilder ?
<b>Email Template:</b> UserAssignment
<b>TO:</b> manojp.nayak#gmail.com<b>CC:</b>
<b>FROM:</b>admin#gmail.com <b>SUBJECT:</b>Task Assignment Project Activity has been assigned to you.
<b>BODY:</b> Deliverable Information :
Test Deliverable 01 Test Issue 01
Project Activity assigned by: Admin at: 2013-01-29 7:50 PM
Automated Email Notification. Do not reply.
Email Comments: 123test
<b>FILES:</b>
Sure you can.
you can use something like:
<asp:HiddenField ID="HiddenField_data" runat="server" />
And from code behind on your event you can save the value you want in here with something like:
HiddenField_data.Value = #"<b>Email Template:</b> UserAssignment
<b>TO:</b> manojp.nayak#gmail.com<b>CC:</b>
<b>FROM:</b>admin#gmail.com <b>SUBJECT:</b>Task Assignment Project Activity has been assigned to you.
<b>BODY:</b> Deliverable Information :
Test Deliverable 01 Test Issue 01
Project Activity assigned by: Admin at: 2013-01-29 7:50 PM
Automated Email Notification. Do not reply.
Email Comments: 123test
<b>FILES:</b> ";
You can use User Control to encapsulate your content
Visibility : You can use Visible property of your user control
Persistance : You can use EnableViewState property
Link : http://msdn.microsoft.com/fr-fr/library/system.web.ui.usercontrol(v=vs.80).aspx

Covert ASP.net 2.0 to ASP.net MVC C# 3.0 (C#)

A while back I created a REAL BASIC appointment scheduling form (again, emphasis on REAL BASIC, as in "no-frills") in an ASP.net 2.0 project using C# (and code-behinds).
Well, I dusted off that code but 2 years later I am using MVC 3.0 (again, C#), and I needed help converting the following code. I can set up a model, do a #using model.MyModel name in my view, then inside an Html.BeginForm do an #Html.EditorFor (or whatever I choose). The CSS is also not a problem. But when I look at the ASP.net 2.0 code I feel like I am looking at some alien language. I am no expert, so that's my problem.
Any help is greatly appreciated.
In my old appointment.ascx:
<asp:TextBox runat="server" ID="txtCalendarAppointmentRequest1" SkinID="txt150" />
<asp:ImageButton runat="Server" ID="imgbtnCalendarAppointmentRequest1" SkinID="calendar" AlternateText="Calendar" CausesValidation="false" ToolTip="Click here to pick a date." /><br />
<ajaxToolkit:CalendarExtender ID="calextAppointmentRequest1" runat="server" TargetControlID="txtCalendarAppointmentRequest1" PopupButtonID="imgbtnCalendarAppointmentRequest1" />
<asp:RequiredFieldValidator ID="rfv_txtCalendarAppointmentRequest1" runat="server" ControlToValidate="txtCalendarAppointmentRequest1" ErrorMessage="<b><u>No Date Selected</u></b><br/><br/>Select an appropriate FIRST date within the next 15 days.<br/><br/>" Display="None" />
<ajaxToolkit:ValidatorCalloutExtender ID="vce_rfv_txtCalendarAppointmentRequest1" runat="server" Enabled="True" TargetControlID="rfv_txtCalendarAppointmentRequest1" CssClass="CustomValidatorCalloutStyle" WarningIconImageUrl="~/App_Themes/LOREMPLLC/Images/warning.jpg" CloseImageUrl="~/App_Themes/LOREMPLLC/Images/close.jpg" />
<asp:CompareValidator ID="cv_txtCalendarAppointmentRequest1" runat="server" ControlToValidate="txtCalendarAppointmentRequest1" Operator="DataTypeCheck" Type="Date" ErrorMessage="<b><u>Incorrect Date</u></b><br/><br/>Select an appropriate FIRST date within the next 15 days.<br/><br/>" Display="None" />
<ajaxToolkit:ValidatorCalloutExtender ID="vce_cv_txtCalendarAppointmentRequest1" runat="server" Enabled="True" TargetControlID="cv_txtCalendarAppointmentRequest1" CssClass="CustomValidatorCalloutStyle" WarningIconImageUrl="~/App_Themes/LOREMPLLC/Images/warning.jpg" CloseImageUrl="~/App_Themes/LOREMPLLC/Images/close.jpg" />
<asp:RangeValidator ID="rv_txtCalendarAppointmentRequest1" runat="server" ControlToValidate="txtCalendarAppointmentRequest1" Type="Date" ErrorMessage="<b><u>Date Outside Range</u></b><br/><br/>Select a FIRST date within the next 15 days.<br/><br/>" Display="None" />
<ajaxToolkit:ValidatorCalloutExtender ID="vce_rv_txtCalendarAppointmentRequest1" runat="server" Enabled="True" TargetControlID="rv_txtCalendarAppointmentRequest1" CssClass="CustomValidatorCalloutStyle" WarningIconImageUrl="~/App_Themes/LOREMPLLC/Images/warning.jpg" CloseImageUrl="~/App_Themes/LOREMPLLC/Images/close.jpg" />
And in my code-behind appointment.ascx.cs:
rv_txtCalendarAppointmentRequest1.MinimumValue = System.DateTime.Now.ToShortDateString();
rv_txtCalendarAppointmentRequest1.MaximumValue = System.DateTime.Now.AddDays(15).ToShortDateString();
Basically, and again REAL BASIC, I was giving users an option to pick 3 future dates for an appointment and ALL with a max date of 15 days from the current date.
I will probably add a radio button list for time frames (morning, afternoon, evening).
Ideally, I would love to have a true scheduling ability. Things like Dxhtmlscheduler and DayPilot MVC are overkill AND too complicated right now for me to integrate.
If I was able, I'd block Sundays and times between 8pm and 8am. If I were truly able I'd love to be able to put blocks of time in over the next few weeks, but I'll stick to the REAL BASIC part I mentioned. :)
Your old ASP.Net control basically consists of:
a TextBox for recording the date
an AjaxToolkit control to make a calendar picker and hook that up to the text box
three validators which ensure that the date textbox has something entered in it (so is required) falls within the given range (the next 15 days) and is a valid date.
3 AjaxToolKit ValidatorCalloutExtenders - which basically make the validation messages look a bit fancier.
To recreate this in MVC, you'll need a Model with a DateTime property. You don't need to do anything special to the property to get the 'required' and 'is a valid date' validation (by default, the built in validation assumes that this property is required, as it is a not nullable property). You would need to create a custom validator to recreate the date range validation (google 'asp.net mvc 3 custom validation' for herlp).
You'd also need some sort of javascript calendar control - as others have mention, the JQuery UI one works well.
Then, in your View, you'd have something like this:
<script type="text/javascript">
var minDate = new Date();
var maxDate = new Date(dt.getTime()+15*24*60*60*1000);
$(function () {
$('input.date_control').datepicker( { minDate: minDate , maxDate: maxDate });
});
</script>
#{ Html.EnableClientValidation();}
#using (Html.BeginForm("Add", "Something"))
{
#Html.TextBoxFor(x => x.MyDatePropert, new { #class = "date_control" })
}
Note: - this is a 'datepicker' - not a 'date/timepicker' - so you can't block 'times between 8pm and 8am' as this doesn't make sense - but then your original control didn't do that either :)
If that was a requirement - you'd need to look at a different javascript control - but the concept would remain the same.
For the calendar itself you could use JQuery Calendar.
You can do pretty much everything you want - restrict days, set min or max date etc
http://jqueryui.com/demos/datepicker/#min-max
With regards to validation, decorate properties on your model with DataAnnotations
There's a really nice article on Scott's blog about validation in MVC
http://weblogs.asp.net/srkirkland/archive/2011/02/23/introducing-data-annotations-extensions.aspx
Hope that helps

Show user specific data from database based on LoginID username

I am attempting to convert an online game i have written in ASP into ASP.NET,, but I am failing at a very early and probably a very amateurish stage.
I am using a Sample ASPX project.
There is an ASPNETDB database included, when i register my username is added to the DB along with a userID and various other fields. This is stored in a table called aspnet_Users.
The Login Control is stored in a Site.Master file
<div class="loginDisplay">
<asp:LoginView ID="HeadLoginView" runat="server" EnableViewState="false"
onviewchanged="HeadLoginView_ViewChanged">
<AnonymousTemplate>
[ Log In ]
</AnonymousTemplate>
<LoggedInTemplate>
Welcome <span class="bold"><asp:LoginName ID="HeadLoginName" runat="server" /></span>!
[ <asp:LoginStatus ID="HeadLoginStatus" runat="server" LogoutAction="Redirect" LogoutText="Log Out" LogoutPageUrl="~/"/> ]
</LoggedInTemplate>
</asp:LoginView>
I have created a new table called tblClubs, which stores information such as ClubName, StadiumCapacity etc
I added a field called 'Owner' and this is directly related to the UserName field in the aspnet_Users table
What I am trying to solve is to show user specific information from the database, based on their LoginID.
i.e
My username is Laclerque and my club is called Racing Mongoose, the stadium capacity is 9500.. the information for each User needs to be different and just show the information that is relevant to them.
obviously in the longer term, there is going to be 100's of these associations required for the full game, but not until i can get my head around the basics of how to set this information. I tend to work better when i can see a working sample, and then adapt things to suit my needs.
Hope this is enough information, and thanks in advance if anyone can help.
You can take a look at asp.net's online example: Here
Hope that helps!

Resources