private string dateConvert(string datDate){
System.Globalization.CultureInfo cultEnGb = new System.Globalization.CultureInfo("en-GB");
System.Globalization.CultureInfo cultEnUs = new System.Globalization.CultureInfo("en-US");
DateTime dtGb = Convert.ToDateTime(datDate, cultEnGb.DateTimeFormat); datDate = dtGb.ToString(cultEnUs.DateTimeFormat.ShortDatePattern);
return datDate;}
ASP.NET is a development framework for building web pages and web sites with HTML, CSS, JavaScript and server scripting. ASP.NET supports three different development models: Web Pages, MVC (Model View Controller), and Web Forms.
Tuesday, April 28, 2009
Monday, April 27, 2009
ASP.Net 2.0 C# DateTime IFormatProvider Using ParseExact
In the previous article C# Convert String to DateTime you learnt the use of Convert.ToDateTime function in C# ASP.Net 2.0. Following are 2 other methods to convert the DateTime format using IFormatProvider:
DateTime .ParseExact
DateTime.Parse
To use IFormatProvider you have to pass the culture info for DateTime format coz in different cultures DateTime format of displaying the sequence of month and date varies.
E.g.:
For French Culture use the following:
IFormatProvider culture = new CultureInfo("fr-Fr", true);
For US English use the following:
IFormatProvider culture = new CultureInfo("fr-Fr", true);
Both cultures mentioned above accept the different DateTime Formats.
If you are using
DateTime.Parse
then you have to pass the MM/dd/yyyy hh:mm:ss
Format of DateTime for French culture and dd/MM/yyyy hh:mm:ss for US English culture. You have to check the format for different cultures by changing the position of month and day.
Using DateTime Parse:
dt = DateTime.Parse(myDateTimeString, culture,DateTimeStyles.NoCurrentDateDefault);
Using DateTime ParseExact:
dt = DateTime.ParseExact(myDateTimeString,"MM/dd/yyyy hh:mm:ss", culture, DateTimeStyles.NoCurrentDateDefault);
C# Code to ParseExact the DateTime String:
string myDateTimeString;
myDateTimeString = "19/02/2008 05:44:00";
IFormatProvider culture = new CultureInfo("fr-Fr", true);
dt = DateTime.ParseExact(myDateTimeString,"dd/MM/yyyy hh:mm:ss", culture, DateTimeStyles.NoCurrentDateDefault);
Response.Write(dt.Day + "/" + dt.Month + "/" + dt.Year);
DateTime .ParseExact
DateTime.Parse
To use IFormatProvider you have to pass the culture info for DateTime format coz in different cultures DateTime format of displaying the sequence of month and date varies.
E.g.:
For French Culture use the following:
IFormatProvider culture = new CultureInfo("fr-Fr", true);
For US English use the following:
IFormatProvider culture = new CultureInfo("fr-Fr", true);
Both cultures mentioned above accept the different DateTime Formats.
If you are using
DateTime.Parse
then you have to pass the MM/dd/yyyy hh:mm:ss
Format of DateTime for French culture and dd/MM/yyyy hh:mm:ss for US English culture. You have to check the format for different cultures by changing the position of month and day.
Using DateTime Parse:
dt = DateTime.Parse(myDateTimeString, culture,DateTimeStyles.NoCurrentDateDefault);
Using DateTime ParseExact:
dt = DateTime.ParseExact(myDateTimeString,"MM/dd/yyyy hh:mm:ss", culture, DateTimeStyles.NoCurrentDateDefault);
C# Code to ParseExact the DateTime String:
string myDateTimeString;
myDateTimeString = "19/02/2008 05:44:00";
IFormatProvider culture = new CultureInfo("fr-Fr", true);
dt = DateTime.ParseExact(myDateTimeString,"dd/MM/yyyy hh:mm:ss", culture, DateTimeStyles.NoCurrentDateDefault);
Response.Write(dt.Day + "/" + dt.Month + "/" + dt.Year);
Saturday, March 21, 2009
Windows form close and open next form in Windows Application in C#.NET
Form2 Form2 = new Form2();
Form2.StartPosition = FormStartPosition.CenterParent;
this.Hide();
Form2.ShowDialog();
this.Close();
Form2.StartPosition = FormStartPosition.CenterParent;
this.Hide();
Form2.ShowDialog();
this.Close();
Wednesday, March 4, 2009
Find if a value exists in an Array in VB6.0
Module:
Option Explicit
Public Function IsInArray(FindValue As Variant, arrSearch As Variant) As Boolean
On Error GoTo LocalError
If Not IsArray(arrSearch) Then Exit Function
If Not IsNumeric(FindValue) Then FindValue = UCase(FindValue)
IsInArray = InStr(1, vbNullChar & Join(arrSearch, vbNullChar) & vbNullChar, _
vbNullChar & FindValue & vbNullChar) > 0
Exit Function
LocalError:
'Justin (just in case)
End Function
Usage:
Private Sub Command1_Click()
Dim x(5) As String
x(0) = 5
x(1) = 100
x(2) = 2000
x(3) = 11
x(4) = 7
x(5) = 1010
MsgBox IsInArray(10, x)
End Sub
Option Explicit
Public Function IsInArray(FindValue As Variant, arrSearch As Variant) As Boolean
On Error GoTo LocalError
If Not IsArray(arrSearch) Then Exit Function
If Not IsNumeric(FindValue) Then FindValue = UCase(FindValue)
IsInArray = InStr(1, vbNullChar & Join(arrSearch, vbNullChar) & vbNullChar, _
vbNullChar & FindValue & vbNullChar) > 0
Exit Function
LocalError:
'Justin (just in case)
End Function
Usage:
Private Sub Command1_Click()
Dim x(5) As String
x(0) = 5
x(1) = 100
x(2) = 2000
x(3) = 11
x(4) = 7
x(5) = 1010
MsgBox IsInArray(10, x)
End Sub
Tuesday, March 3, 2009
VB code to show all table names of a databse
Dim rs As ADODB.Recordset
Dim con As New ADODB.Connection
Dim tables() As String
Dim table1, tablename As String
Dim i As Integer
Private Sub Command1_Click()
If con.State = adStateOpen Then
con.Close
End If
con.Open "Provider=SQLOLEDB.1;Data Source=.;Initial Catalog=GMS;Integrated Security=SSPI"
Set rs = New ADODB.Recordset
Set rs = con.OpenSchema(adSchemaTables, Array(Empty, Empty, Empty, "TABLE"))
Do Until rs.EOF
'MsgBox rs!table_name
'Combo1.AddItem (rs!table_name)
If table1 = "" Then
table1 = rs!table_name
Else
table1 = table1 & "," & rs!table_name
End If
rs.MoveNext
Loop
rs.Close
tablename = "adcdata"
Set rs = Nothing
tables() = Split(table1, ",")
For i = 0 To UBound(tables()) - 1
If tablename = tables(i) Then
MsgBox "yes"
Else
End If
Next i
MsgBox table1
End Sub
Private Sub Form_Load()
'con.ConnectionString = "provider=microsoft.jet.oledb.4.0;" & " data source=" & App.Path & "\rubberpark.mdb"
End Sub
Dim con As New ADODB.Connection
Dim tables() As String
Dim table1, tablename As String
Dim i As Integer
Private Sub Command1_Click()
If con.State = adStateOpen Then
con.Close
End If
con.Open "Provider=SQLOLEDB.1;Data Source=.;Initial Catalog=GMS;Integrated Security=SSPI"
Set rs = New ADODB.Recordset
Set rs = con.OpenSchema(adSchemaTables, Array(Empty, Empty, Empty, "TABLE"))
Do Until rs.EOF
'MsgBox rs!table_name
'Combo1.AddItem (rs!table_name)
If table1 = "" Then
table1 = rs!table_name
Else
table1 = table1 & "," & rs!table_name
End If
rs.MoveNext
Loop
rs.Close
tablename = "adcdata"
Set rs = Nothing
tables() = Split(table1, ",")
For i = 0 To UBound(tables()) - 1
If tablename = tables(i) Then
MsgBox "yes"
Else
End If
Next i
MsgBox table1
End Sub
Private Sub Form_Load()
'con.ConnectionString = "provider=microsoft.jet.oledb.4.0;" & " data source=" & App.Path & "\rubberpark.mdb"
End Sub
Tuesday, February 10, 2009
VB code to create kml file and open google earth with sms application
Dim message, mess As String
Dim sms() As String
Dim sm() As String
Dim lat, lon, d1, d2 As String
Dim lat1, lon1 As Double
Dim lt1, ln1 As Double
Dim u, loc, s, n, msg, ms, tid, tre, mob As String
Dim i As Integer
Dim temp, t, l, g, o, e, result As Double
Dim h() As String
Dim k() As String
Private Sub Combo1_Click()
MSComm1.CommPort = Combo1.Text
End Sub
Private Sub Command1_Click()
If MSComm1.InBufferCount > 0 Then
u = MSComm1.Input
Text1.Text = Text1.Text & us = Mid(u, 2, 4)
n = Mid(u, 13, 1)
If Mid(u, 2, 4) = "CMTI" Then
loc = Mid(u, 13, 1)
MSComm1.Output = "AT+CMGR=" & loc & Chr(13)
Text1.Text = Text1.Text & "AT+CMGR=" & loc & Chr(13)
Text1.Text = MSComm1.Input
message = Text1.Text
'message = "@0996.54553,N,07630.23133449,E,@0968.5172,N,07639.4825,E"
message = "@0997.9844,N,07660.2006,E,@0968.5172,N,07639.4825,E"
sms() = Split(message, "@")
mess = sms(1)
sm() = Split(mess, ",")
lat = sm(0)
convert (lat)
lat1 = resultl
t1 = lat1
d1 = sm(1)
lon = sm(2)
convert (lon)
lon1 = result
ln1 = lon1
d2 = sm(3)
Dim stAppName As String
Create KML FILE:

Dim path As String
Shell """C:\Program Files\Google\Google Earth\GoogleEarth.exe"" ""C:\Program Files\Google\Google Earth\ret.kml"""
End Sub
Private Sub Command2_Click()
MSComm1.Output = "AT+CMGS=" & Chr(34) & "+91" & num & Chr(34) & Chr(13) & "123456FORWARD" & Chr(26)
End Sub
Private Sub Command3_Click()
MSComm1.Output = "AT+CMGS=" & Chr(34) & "+91" & num & Chr(34) & Chr(13) & "123456RIGHT" & Chr(26)
End Sub
Private Sub Command4_Click()
MSComm1.Output = "AT+CMGS=" & Chr(34) & "+91" & num & Chr(34) & Chr(13) & "123456LEFT" & Chr(26)
End Sub
Private Sub Command5_Click()
MSComm1.PortOpen = True
End Sub
Private Sub Command6_Click()
MSComm1.PortOpen = False
End Sub
Private Sub Command7_Click()
MSComm1.Output = "AT+CMGS=" & Chr(34) & "+91" & num & Chr(34) & Chr(13) & "123456PULLY" & Chr(26)
End Sub
Function convert(val As String)
temp = val
h() = Split(temp, ".")
t = h(0)
l = t / 100
n = h(1)
k() = Split(l, ".")
g = k(0)
o = k(1)
e = o + n
result = g + "." + e
End Function
Private Sub Timer1_Timer()
If MSComm1.InBufferCount > 0 Then
Text1.Text = MSComm1.Input
End If
End Sub
Dim sms() As String
Dim sm() As String
Dim lat, lon, d1, d2 As String
Dim lat1, lon1 As Double
Dim lt1, ln1 As Double
Dim u, loc, s, n, msg, ms, tid, tre, mob As String
Dim i As Integer
Dim temp, t, l, g, o, e, result As Double
Dim h() As String
Dim k() As String
Private Sub Combo1_Click()
MSComm1.CommPort = Combo1.Text
End Sub
Private Sub Command1_Click()
If MSComm1.InBufferCount > 0 Then
u = MSComm1.Input
Text1.Text = Text1.Text & us = Mid(u, 2, 4)
n = Mid(u, 13, 1)
If Mid(u, 2, 4) = "CMTI" Then
loc = Mid(u, 13, 1)
MSComm1.Output = "AT+CMGR=" & loc & Chr(13)
Text1.Text = Text1.Text & "AT+CMGR=" & loc & Chr(13)
Text1.Text = MSComm1.Input
message = Text1.Text
'message = "@0996.54553,N,07630.23133449,E,@0968.5172,N,07639.4825,E"
message = "@0997.9844,N,07660.2006,E,@0968.5172,N,07639.4825,E"
sms() = Split(message, "@")
mess = sms(1)
sm() = Split(mess, ",")
lat = sm(0)
convert (lat)
lat1 = resultl
t1 = lat1
d1 = sm(1)
lon = sm(2)
convert (lon)
lon1 = result
ln1 = lon1
d2 = sm(3)
Dim stAppName As String
Create KML FILE:

Dim path As String
Shell """C:\Program Files\Google\Google Earth\GoogleEarth.exe"" ""C:\Program Files\Google\Google Earth\ret.kml"""
End Sub
Private Sub Command2_Click()
MSComm1.Output = "AT+CMGS=" & Chr(34) & "+91" & num & Chr(34) & Chr(13) & "123456FORWARD" & Chr(26)
End Sub
Private Sub Command3_Click()
MSComm1.Output = "AT+CMGS=" & Chr(34) & "+91" & num & Chr(34) & Chr(13) & "123456RIGHT" & Chr(26)
End Sub
Private Sub Command4_Click()
MSComm1.Output = "AT+CMGS=" & Chr(34) & "+91" & num & Chr(34) & Chr(13) & "123456LEFT" & Chr(26)
End Sub
Private Sub Command5_Click()
MSComm1.PortOpen = True
End Sub
Private Sub Command6_Click()
MSComm1.PortOpen = False
End Sub
Private Sub Command7_Click()
MSComm1.Output = "AT+CMGS=" & Chr(34) & "+91" & num & Chr(34) & Chr(13) & "123456PULLY" & Chr(26)
End Sub
Function convert(val As String)
temp = val
h() = Split(temp, ".")
t = h(0)
l = t / 100
n = h(1)
k() = Split(l, ".")
g = k(0)
o = k(1)
e = o + n
result = g + "." + e
End Function
Private Sub Timer1_Timer()
If MSComm1.InBufferCount > 0 Then
Text1.Text = MSComm1.Input
End If
End Sub
Crystal Reports with Selection formula
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WEIGHBRIDGE1
{
public partial class MonthReport : Form
{
SqlConnection scn = new SqlConnection("Data Source=.;Initial Catalog=Weighingbridge;Integrated Security=True");
public MonthReport()
{
InitializeComponent();
}
private static string mth;
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboBox1.Text == "January")
{
mth = "January";
}
if (comboBox1.Text == "February")
{
mth = "February";
}
if (comboBox1.Text == "March")
{
mth = "March";
}
if (comboBox1.Text == "April")
{
mth = "April";
}
if (comboBox1.Text == "May")
{
mth = "May";
}
if (comboBox1.Text == "June")
{
mth = "June";
}
if (comboBox1.Text == "July")
{
mth = "July";
}
if (comboBox1.Text == "August")
{
mth = "August";
}
if (comboBox1.Text == "September")
{
mth = "September";
}
if (comboBox1.Text == "October")
{
mth = "October";
}
if (comboBox1.Text == "November")
{
mth = "November";
}
if (comboBox1.Text == "December")
{
mth = "December";
}
//-------------------------------------------------------------------------------------------- if (mth == "January")
{
Class1.month = "{Transaction.Dateoftransaction} in '1/1/2007' to ' 1/31/2007' ";
}
if (mth == "February")
{
Class1.month = "{Transaction.Dateoftransaction} in ' 1/2/2007' to ' 28/2/2007' ";
}
if (mth == "March")
{
Class1.month = "{Transaction.Dateoftransaction} in ' 1/3/2007' to '31/3/2007' ";
}
if (mth == "April")
{
Class1.month = "{Transaction.Dateoftransaction} in ' 1/4/2007' to '30/4/2007' ";
}
if (mth == "May")
{
Class1.month = "{Transaction.Dateoftransaction} in ' 1/5/2007' to ' 31/5/2007' ";
}
if (mth == "June")
{
Class1.month = "{Transaction.Dateoftransaction} in ' 1/6/2007' to ' 30/6/2007' ";
}
if (mth == "July")
{
Class1.month = "{Transaction.Dateoftransaction} in ' 1/7/2007' to ' 31/7/2007' ";
}
if (mth == "August")
{
Class1.month = "{Transaction.Dateoftransaction} in '1/8/2007' to '31/8/2007' ";
}
if (mth == "September")
{
Class1.month = "{Transaction.Dateoftransaction} in '1/9/2007' to '30/9/2007' ";
}
if (mth == "October")
{
Class1.month = "{Transaction.Dateoftransaction} in '1/10/2007' to '31/10/2007' ";
}
if (mth == "November")
{
Class1.month = "{Transaction.Dateoftransaction} in '1/11/2007' to '30/11/2007' ";
}
if (mth == "December")
{
Class1.month = "{Transaction.Dateoftransaction} in '1/12/2007' to '31/12/2007' ";
}
MonthlyReportPrint mr = new MonthlyReportPrint();
mr.Show();
}
}
}==============================================================================================using System;
using System.Collections.Generic;
using System.Text;using System.Data;
namespace WEIGHBRIDGE1
{
public class Class1
{
public Class1()
{
}
public static string strno;
public static string date;
public static string fdate;
public static string tdate;
public static string month;
public static string billno;
public static string cname;
//public string strno { get; set; }
}
}
========================================================================================using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WEIGHBRIDGE1
{
public partial class MonthlyReportPrint : Form
{
SqlConnection scn = new SqlConnection("Data Source=.;Initial Catalog=Weighingbridge;Integrated Security=True");
public MonthlyReportPrint()
{
InitializeComponent();
}
private void MonthlyReportPrint_Load(object sender, EventArgs e)
{
//scn.Open();
//SqlDataAdapter da = new SqlDataAdapter("select * from [Transaction] ", scn);
//DataSet ds = new DataSet();
//da.Fill(ds);
//CrystalmonthReport cm = new CrystalmonthReport();
//cm.SetDataSource(ds);
//crystalReportViewer1.ReportSource = cm;
crystalReportViewer1.SelectionFormula = Class1.month;
}
}
}=========================================================================================
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WEIGHBRIDGE1
{
public partial class MonthReport : Form
{
SqlConnection scn = new SqlConnection("Data Source=.;Initial Catalog=Weighingbridge;Integrated Security=True");
public MonthReport()
{
InitializeComponent();
}
private static string mth;
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboBox1.Text == "January")
{
mth = "January";
}
if (comboBox1.Text == "February")
{
mth = "February";
}
if (comboBox1.Text == "March")
{
mth = "March";
}
if (comboBox1.Text == "April")
{
mth = "April";
}
if (comboBox1.Text == "May")
{
mth = "May";
}
if (comboBox1.Text == "June")
{
mth = "June";
}
if (comboBox1.Text == "July")
{
mth = "July";
}
if (comboBox1.Text == "August")
{
mth = "August";
}
if (comboBox1.Text == "September")
{
mth = "September";
}
if (comboBox1.Text == "October")
{
mth = "October";
}
if (comboBox1.Text == "November")
{
mth = "November";
}
if (comboBox1.Text == "December")
{
mth = "December";
}
//-------------------------------------------------------------------------------------------- if (mth == "January")
{
Class1.month = "{Transaction.Dateoftransaction} in '1/1/2007' to ' 1/31/2007' ";
}
if (mth == "February")
{
Class1.month = "{Transaction.Dateoftransaction} in ' 1/2/2007' to ' 28/2/2007' ";
}
if (mth == "March")
{
Class1.month = "{Transaction.Dateoftransaction} in ' 1/3/2007' to '31/3/2007' ";
}
if (mth == "April")
{
Class1.month = "{Transaction.Dateoftransaction} in ' 1/4/2007' to '30/4/2007' ";
}
if (mth == "May")
{
Class1.month = "{Transaction.Dateoftransaction} in ' 1/5/2007' to ' 31/5/2007' ";
}
if (mth == "June")
{
Class1.month = "{Transaction.Dateoftransaction} in ' 1/6/2007' to ' 30/6/2007' ";
}
if (mth == "July")
{
Class1.month = "{Transaction.Dateoftransaction} in ' 1/7/2007' to ' 31/7/2007' ";
}
if (mth == "August")
{
Class1.month = "{Transaction.Dateoftransaction} in '1/8/2007' to '31/8/2007' ";
}
if (mth == "September")
{
Class1.month = "{Transaction.Dateoftransaction} in '1/9/2007' to '30/9/2007' ";
}
if (mth == "October")
{
Class1.month = "{Transaction.Dateoftransaction} in '1/10/2007' to '31/10/2007' ";
}
if (mth == "November")
{
Class1.month = "{Transaction.Dateoftransaction} in '1/11/2007' to '30/11/2007' ";
}
if (mth == "December")
{
Class1.month = "{Transaction.Dateoftransaction} in '1/12/2007' to '31/12/2007' ";
}
MonthlyReportPrint mr = new MonthlyReportPrint();
mr.Show();
}
}
}==============================================================================================using System;
using System.Collections.Generic;
using System.Text;using System.Data;
namespace WEIGHBRIDGE1
{
public class Class1
{
public Class1()
{
}
public static string strno;
public static string date;
public static string fdate;
public static string tdate;
public static string month;
public static string billno;
public static string cname;
//public string strno { get; set; }
}
}
========================================================================================using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WEIGHBRIDGE1
{
public partial class MonthlyReportPrint : Form
{
SqlConnection scn = new SqlConnection("Data Source=.;Initial Catalog=Weighingbridge;Integrated Security=True");
public MonthlyReportPrint()
{
InitializeComponent();
}
private void MonthlyReportPrint_Load(object sender, EventArgs e)
{
//scn.Open();
//SqlDataAdapter da = new SqlDataAdapter("select * from [Transaction] ", scn);
//DataSet ds = new DataSet();
//da.Fill(ds);
//CrystalmonthReport cm = new CrystalmonthReport();
//cm.SetDataSource(ds);
//crystalReportViewer1.ReportSource = cm;
crystalReportViewer1.SelectionFormula = Class1.month;
}
}
}=========================================================================================
Subscribe to:
Posts (Atom)
Using Authorization with Swagger in ASP.NET Core
Create Solution like below LoginModel.cs using System.ComponentModel.DataAnnotations; namespace UsingAuthorizationWithSwagger.Models { ...
-
Codebehind C#: public static Bitmap CreateFirstCard(string Name,string MembNo,string Mobile,string Phone, ...
-
Inbox.aspx <%@ Page Title="" Language="C#" MasterPageFile="~/Marketing/admin.master" EnableEventValid...
-
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.D...