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

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;
}
}
}=========================================================================================

Encryption and Decription


using System;

using System.Data;

using System.Configuration;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;
using System.Xml;using System.Text;

using System.Security.Cryptography;

using System.IO;using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

string str= Encrypt("Silpa");

SqlConnection con = new SqlConnection("Data Source=INFO-9;Initial Catalog=test;Integrated Security=True");

SqlCommand cmd=new SqlCommand("insert into pwdd values('"+str+"')",con);

con.Open();

cmd.ExecuteNonQuery();

con.Close();

string str1 = Decrypt("88tlfz/eGbtHNKDnXU6gQw==");

}
public static string Decrypt(string TextToBeDecrypted)

{

RijndaelManaged RijndaelCipher = new RijndaelManaged();
string Password = "CSC";

string DecryptedData;
try {

byte[] EncryptedData = Convert.FromBase64String(TextToBeDecrypted);
byte[] Salt = Encoding.ASCII.GetBytes(Password.Length.ToString());

//Making of the key for decryption

PasswordDeriveBytes SecretKey = new PasswordDeriveBytes(Password, Salt);

//Creates a symmetric Rijndael decryptor object.

ICryptoTransform Decryptor = RijndaelCipher.CreateDecryptor(SecretKey.GetBytes(32), SecretKey.GetBytes(16));
MemoryStream memoryStream = new MemoryStream(EncryptedData);

//Defines the cryptographics stream for decryption.THe stream contains decrpted data

CryptoStream cryptoStream = new CryptoStream(memoryStream, Decryptor, CryptoStreamMode.Read);
byte[] PlainText = new byte[EncryptedData.Length];

int DecryptedCount = cryptoStream.Read(PlainText, 0, PlainText.Length); memoryStream.Close();

cryptoStream.Close();
//Converting to string

DecryptedData = Encoding.Unicode.GetString(PlainText, 0, DecryptedCount);

}

catch

{

DecryptedData = TextToBeDecrypted;

}

return DecryptedData;

}
public static string Encrypt(string TextToBeEncrypted)

{

RijndaelManaged RijndaelCipher = new RijndaelManaged();

string Password = "CSC";

byte[] PlainText = System.Text.Encoding.Unicode.GetBytes(TextToBeEncrypted);

byte[] Salt = Encoding.ASCII.GetBytes(Password.Length.ToString()); PasswordDeriveBytes SecretKey = new PasswordDeriveBytes(Password, Salt);

//Creates a symmetric encryptor object.

ICryptoTransform Encryptor = RijndaelCipher.CreateEncryptor(SecretKey.GetBytes(32), SecretKey.GetBytes(16));

MemoryStream memoryStream = new MemoryStream();

//Defines a stream that links data streams to cryptographic transformations CryptoStream cryptoStream = new CryptoStream(memoryStream, Encryptor, CryptoStreamMode.Write);

cryptoStream.Write(PlainText, 0, PlainText.Length);

//Writes the final state and clears the buffer

cryptoStream.FlushFinalBlock();

byte[] CipherBytes = memoryStream.ToArray();

memoryStream.Close();

cryptoStream.Close();

string EncryptedData = Convert.ToBase64String(CipherBytes);
return EncryptedData;

}
}

Using Authorization with Swagger in ASP.NET Core

 Create Solution like below LoginModel.cs using System.ComponentModel.DataAnnotations; namespace UsingAuthorizationWithSwagger.Models {     ...