Wednesday, March 9, 2011

Caching and Manipulating a DataTable in memory (without storing in SQL)

Default.aspx.cs
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;usingSystem.IO;using System.Data;using System.Data.SqlClient;public
{


{

{
th =
th.AddRowWithVerification(
th.AddRowWithVerification(
th.AddRowWithVerification(
Session[
}

{
th =
}
GridView1.DataSource = th.GetTable();
GridView1.DataBind();
partial class _Default : System.Web.UI.Page TableHandler th;protected void Page_Load(object sender, EventArgs e)if (Session["THTable"] == null)new TableHandler();"aa11", "bb", "ccb", DateTime.Now);"aa2", "bb", "cc", DateTime.Now);"aa22", "bbb", "ccb", DateTime.Now);"THTable"] = th.GetTable();if (Session["THTable"] != null && th == null)new TableHandler();// Start date
DateTime startDate = new DateTime(2005, 2, 1, 3, 4, 12, 56);// End date
DateTime endDate = new DateTime(2005, 12, 12, 4, 30, 45, 12);// Time span
TimeSpan diffDate = endDate.Subtract(startDate);// Spit it out Label1.Text =

Label1.Text += (diffDate.Days.ToString() +
Label1.Text += (diffDate.Hours.ToString() +
Label1.Text += (diffDate.Minutes.ToString() +
Label1.Text += (diffDate.Seconds.ToString() +
Label1.Text += (diffDate.Milliseconds.ToString() +
Label1.Text +=
Label1.Text += diffDate.TotalMilliseconds +
Label1.Text +=
Label1.Text += (
}

{
th.AddRowWithVerification(TextBox1.Text,TextBox2.Text,TextBox3.Text,
GridView1.DataBind();
}
}

"Start Date:" + startDate.ToString("yyyy-MM-dd HH:mm:ss.fff") + "<br>" + "End Date:" + endDate.ToString("yyyy-MM-dd HH:mm:ss.fff") +"<br>" + "Time Difference: ";" Days,");" Hours,");" Minutes,");" Seconds,");" Milliseconds " + "<br>");"Total TimeDifference: " + diffDate.TotalMinutes + "Minutes = " + diffDate.TotalHours + "Hours = ";"Millisecs = " + diffDate.TotalDays + "Days" + "<br>";DateTime.Now.AddMinutes(-30).ToString("yyyy-MM-dd HH:mm:ss.fff") + " " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "<br>";DateTime.Now.AddMinutes(-30) < DateTime.Now) ? (DateTime.Now.AddMinutes(-30).ToString("yyyy-MM-dd HH:mm:ss.fff")) : DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");protected void Button1_Click(object sender, EventArgs e)DateTime.Now);//pagepublic class TableHandler{


{

{
x =
x.Columns.Add(
x.Columns.Add(
x.Columns.Add(
x.Columns.Add(

dr[
dr[
dr[
dr[
x.Rows.Add(dr);
System.Web.
}
DataTable x;public TableHandler()if (System.Web.HttpContext.Current.Session["THTable"] == null)new DataTable();new DataColumn("IPAddress", System.Type.GetType("System.String")));new DataColumn("PortNo", System.Type.GetType("System.String")));new DataColumn("DeviceIMEINo", System.Type.GetType("System.String")));new DataColumn("DateTime", System.Type.GetType("System.DateTime")));DataRow dr = x.NewRow();"IPAddress"] = "sfds";"PortNo"] = "sdfds";"DeviceIMEINo"] = "dsfds";"DateTime"] = DateTime.Now;HttpContext.Current.Session["THTable"] = x;elsex = (
}

{
(
DeleteOldRecords();
DataTable)System.Web.HttpContext.Current.Session["THTable"];public void AddRowWithVerification(string IPAddress, string PortNo, string DeviceIMEINo, DateTime dtinn)new Utility()).WriteLog("C:\\test\\test.txt" ,"AddRowWithVerification Called");DataRow[] dr = x.Select("DeviceIMEINo = '" + DeviceIMEINo + "'");if (dr.Count() > 0) //row already exists , update it{

drr[
drr[
drr[
}
DataRow drr = dr[0];"IPAddress"] = IPAddress;"PortNo"] = PortNo;"DateTime"] = dtinn;else //add new row{

drr[
drr[
drr[
drr[
x.Rows.Add(drr);
}
System.Web.
}
DataRow drr = x.NewRow();"IPAddress"] = IPAddress;"PortNo"] = PortNo;"DeviceIMEINo"] = DeviceIMEINo;"DateTime"] = dtinn;HttpContext.Current.Session["THTable"] = x;//AddRowWithVerification
{

dr[
dr[
dr[
x.Rows.Add(dr);
System.Web.
}
public void AddRow(string IPAddress, string PortNo, string DeviceIMEINo)DataRow dr = x.NewRow();"IPAddress"] = IPAddress;"PortNo"] = PortNo;"DeviceIMEINo"] = DeviceIMEINo;HttpContext.Current.Session["THTable"] = x;//AddRow
{

}
public DataTable GetTable()return (DataTable)System.Web.HttpContext.Current.Session["THTable"];//GetTable
{


{

{
drr.Delete();
(
}
}
}
void DeleteOldRecords()DataRow[] dr = x.Select("DateTime < '" + DateTime.Now.AddMinutes(-1).ToString("yyyy-MM-dd HH:mm:ss.fff") + "'");if (dr.Count() > 0)foreach (DataRow drr in dr)new Utility()).WriteLog("C:\\test\\test.txt", "Deleted Some Records");//DeleteOldRecords
{


DeviceIMEIMo = dr[0][

}
public string GetDeviceIMEINo(string IPAddress)string DeviceIMEIMo = "";DataRow[] dr = x.Select("IPAddress = " + IPAddress.Trim());"DeviceIMEINo"].ToString().Trim();return DeviceIMEIMo;//GetDeviceIMEINo}



//TableHandlerpublic class Utility{

{


sr.WriteLine(LogString);
sr.Flush();
sr.Close();
}
}
public void WriteLog(string FileName, string LogString)FileStream ff = new FileStream(FileName, FileMode.Append);StreamWriter sr = new StreamWriter(ff);
Default.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %><!
<
<
DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">html xmlns="http://www.w3.org/1999/xhtml">head runat="server">
</
<
<title></title>head>body><form id="form1" runat="server"><div>
<asp:GridView ID="GridView1" runat="server"></asp:GridView><asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><asp:TextBox ID="TextBox2" runat="server"></asp:TextBox><asp:TextBox ID="TextBox3" runat="server"></asp:TextBox><asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
</div>
</
</
</form>body>html>





using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using
System.IO;using System.Data;using System.Data.SqlClient;public
{


{

{
th =
th.AddRowWithVerification(
th.AddRowWithVerification(
th.AddRowWithVerification(
Session[
}

{
th =
}
GridView1.DataSource = th.GetTable();
GridView1.DataBind();

partial class _Default : System.Web.UI.Page TableHandler th;protected void Page_Load(object sender, EventArgs e)if (Session["THTable"] == null)new TableHandler();"aa11", "bb", "ccb", DateTime.Now);"aa2", "bb", "cc", DateTime.Now);"aa22", "bbb", "ccb", DateTime.Now);"THTable"] = th.GetTable();if (Session["THTable"] != null && th == null)new TableHandler();// Start date
DateTime startDate = new DateTime(2005, 2, 1, 3, 4, 12, 56);// End date
DateTime endDate = new DateTime(2005, 12, 12, 4, 30, 45, 12);// Time span
TimeSpan diffDate = endDate.Subtract(startDate);// Spit it out Label1.Text =

Label1.Text += (diffDate.Days.ToString() +
Label1.Text += (diffDate.Hours.ToString() +
Label1.Text += (diffDate.Minutes.ToString() +
Label1.Text += (diffDate.Seconds.ToString() +
Label1.Text += (diffDate.Milliseconds.ToString() +
Label1.Text +=
Label1.Text += diffDate.TotalMilliseconds +
Label1.Text +=
Label1.Text += (
}

{
th.AddRowWithVerification(TextBox1.Text,TextBox2.Text,TextBox3.Text,
GridView1.DataBind();
}
}


"Start Date:" + startDate.ToString("yyyy-MM-dd HH:mm:ss.fff") + "<br>" + "End Date:" + endDate.ToString("yyyy-MM-dd HH:mm:ss.fff") +"<br>" + "Time Difference: ";" Days,");" Hours,");" Minutes,");" Seconds,");" Milliseconds " + "<br>");"Total TimeDifference: " + diffDate.TotalMinutes + "Minutes = " + diffDate.TotalHours + "Hours = ";"Millisecs = " + diffDate.TotalDays + "Days" + "<br>";DateTime.Now.AddMinutes(-30).ToString("yyyy-MM-dd HH:mm:ss.fff") + " " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "<br>";DateTime.Now.AddMinutes(-30) < DateTime.Now) ? (DateTime.Now.AddMinutes(-30).ToString("yyyy-MM-dd HH:mm:ss.fff")) : DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");protected void Button1_Click(object sender, EventArgs e)DateTime.Now);//pagepublic class TableHandler{


{

{
x =
x.Columns.Add(
x.Columns.Add(
x.Columns.Add(
x.Columns.Add(

dr[
dr[
dr[
dr[
x.Rows.Add(dr);
System.Web.
}
DataTable x;public TableHandler()if (System.Web.HttpContext.Current.Session["THTable"] == null)new DataTable();new DataColumn("IPAddress", System.Type.GetType("System.String")));new DataColumn("PortNo", System.Type.GetType("System.String")));new DataColumn("DeviceIMEINo", System.Type.GetType("System.String")));new DataColumn("DateTime", System.Type.GetType("System.DateTime")));DataRow dr = x.NewRow();"IPAddress"] = "sfds";"PortNo"] = "sdfds";"DeviceIMEINo"] = "dsfds";"DateTime"] = DateTime.Now;HttpContext.Current.Session["THTable"] = x;elsex = (
}

{
(
DeleteOldRecords();

DataTable)System.Web.HttpContext.Current.Session["THTable"];public void AddRowWithVerification(string IPAddress, string PortNo, string DeviceIMEINo, DateTime dtinn)new Utility()).WriteLog("C:\\test\\test.txt" ,"AddRowWithVerification Called");DataRow[] dr = x.Select("DeviceIMEINo = '" + DeviceIMEINo + "'");if (dr.Count() > 0) //row already exists , update it{

drr[
drr[
drr[
}
DataRow drr = dr[0];"IPAddress"] = IPAddress;"PortNo"] = PortNo;"DateTime"] = dtinn;else //add new row{

drr[
drr[
drr[
drr[
x.Rows.Add(drr);
}
System.Web.
}
DataRow drr = x.NewRow();"IPAddress"] = IPAddress;"PortNo"] = PortNo;"DeviceIMEINo"] = DeviceIMEINo;"DateTime"] = dtinn;HttpContext.Current.Session["THTable"] = x;//AddRowWithVerification
{

dr[
dr[
dr[
x.Rows.Add(dr);
System.Web.
}
public void AddRow(string IPAddress, string PortNo, string DeviceIMEINo)DataRow dr = x.NewRow();"IPAddress"] = IPAddress;"PortNo"] = PortNo;"DeviceIMEINo"] = DeviceIMEINo;HttpContext.Current.Session["THTable"] = x;//AddRow
{

}
public DataTable GetTable()return (DataTable)System.Web.HttpContext.Current.Session["THTable"];//GetTable
{


{

{
drr.Delete();
(
}
}
}
void DeleteOldRecords()DataRow[] dr = x.Select("DateTime < '" + DateTime.Now.AddMinutes(-1).ToString("yyyy-MM-dd HH:mm:ss.fff") + "'");if (dr.Count() > 0)foreach (DataRow drr in dr)new Utility()).WriteLog("C:\\test\\test.txt", "Deleted Some Records");//DeleteOldRecords
{


DeviceIMEIMo = dr[0][

}
public string GetDeviceIMEINo(string IPAddress)string DeviceIMEIMo = "";DataRow[] dr = x.Select("IPAddress = " + IPAddress.Trim());"DeviceIMEINo"].ToString().Trim();return DeviceIMEIMo;//GetDeviceIMEINo}




//TableHandlerpublic class Utility{

{


sr.WriteLine(LogString);
sr.Flush();
sr.Close();
}
}
public void WriteLog(string FileName, string LogString)FileStream ff = new FileStream(FileName, FileMode.Append);StreamWriter sr = new StreamWriter(ff);


Tuesday, March 8, 2011

TimeSpan , DateDiff , and millisecond date formatting in .net

CODE :


// Start dateDateTime startDate = new DateTime(2005, 2, 1, 3, 4, 12, 56);
// End dateDateTime endDate = new DateTime(2005, 12, 12, 4, 30, 45, 12);
// Time span TimeSpan diffDate = endDate.Subtract(startDate);
// Spit it out Label1.Text = "Start Date:" + startDate.ToString("yyyy-MM-dd HH:mm:ss.fff") + "<br>" + "End Date:" + endDate.ToString("yyyy-MM-dd HH:mm:ss.fff") +
"<br>" + "Time Difference: " ;
Label1.Text += (diffDate.Days.ToString() + " Days,");
Label1.Text += (diffDate.Hours.ToString() + " Hours,");
Label1.Text += (diffDate.Minutes.ToString() + " Minutes,");
Label1.Text += (diffDate.Seconds.ToString() + " Seconds,");
Label1.Text += (diffDate.Milliseconds.ToString() + " Milliseconds " + "<br>");
Label1.Text += "Total TimeDifference: " + diffDate.TotalMinutes + "Minutes = " + diffDate.TotalHours + "Hours = ";
Label1.Text += diffDate.TotalMilliseconds + "Millisecs = " + diffDate.TotalDays + "Days";

OUTPUT :

Start Date:2005-02-01 03:04:12.056
End Date:2005-12-12 04:30:45.012
Time Difference: 314 Days,1 Hours,26 Minutes,32 Seconds,956 Milliseconds
Total TimeDifference: 452246.549266667Minutes = 7537.44248777778Hours = 27134792956Millisecs = 314.060103657407Days


Friday, March 4, 2011

Error 3930 - Current Transaction cannot be committed



BEGIN TRY      
 BEGIN TRANSACTION TranA     
  DECLARE  @cond INT;
  SET @cond =  'A';    
END TRY    
BEGIN CATCH     
 PRINT 'a'    
END CATCH;    
COMMIT TRAN TranA





a
Msg 3930, Level 16, State 1, Line 9
The current transaction cannot be committed and cannot support operations that write to the log file. Roll back the transaction.
Msg 3998, Level 16, State 1, Line 1
Uncommittable transaction is detected at the end of the batch. The transaction is rolled back.

Wednesday, February 23, 2011

Simple Resume Template - Tomasz Pęczek - http://tpeczek.blogspot.com/


ęczek
Golkowice 486, 30-698 Kraków
phone: 505 131 056
e-mail:
tpeczek@gmail.com
TECHNICAL SKILLS AND COMPETENCES
Software Designing: UML
Software Development: C# (.Net Framework 2.0/3.5/4.0), C/C++ (STL/WinApi)
Databases: SQL, PL/SQL, MS SQL Server, Oracle
Web Development: ASP.NET MVC, ASP.NET, ASP.NET AJAX, XHTML, CSS,
JavaScript, jQuery
Additional: XML (XSD, XSLT), WiX
PERSONAL INFORMATION
Date of birth: 06.09.1984, Sosnowiec
Nationality: Polish
EDUCATION
2003 – 2008 Silesian University of Technology in Gliwice
Faculty of Automatic Control, Electronics and Computer Science; Institute of
Computer Science, specialization: „System Software” graduated with honors.
1999 – 2003 IV Liceum OgólnoksztaÅ‚c
WORK EXPERIENCE
I 2009 – present Global Services sp. z o.o. –
ące im. Stanisława Staszica in Sosnowiec
Software Development Engineer
·
of application architect and developer in a pilot project in this technology.
Introduction of ASP.NET MVC technology into the company, taking the role
·
web applications in ASP.NET 3.5 and ASP.NET AJAX technologies.
Performing the role of application architect and lead developer for number of
·
processes management module for the National Health Fund Departments,
based on Windows Workflow Foundation technology.
Performing the role of application architect and developer for business
·
in Smart Client Software Factory technology.
Performing design and development tasks within the .Net desktop applications
·
use of Windows Communication Foundation technology.
Development of SOA architecture in National Health Fund Departments with
·
module implemented as Windows Services.
Performing the role of application architect and developer for system services
·
Designing and developing for Oracle database
·
Creating application installers in WiX technology
·
Conducting internal technologies trainings.
XI 2009 – I 2011 TECHBAZA.PL sp. z o.o. –
Software Developer
·
build with use of ASP.NET 3.5, ASP.NET AJAX and PostgreSQL database.
Working as developer in „Techbaza.pl” project – an online prices comparer,
·
"Techbaza.pl" project.
Preparation of individual and commercial users management system for the
·
Development of the products filtering system of the portal.
·
Development of the favorite products module.
·
Design and development of the advanced statistics module.
·
Development of the errors reporting module.
·
Design and development of images host module.
VI 2009 – VI 2010 Gospodarstwo Pomocnicze przy CMJ –
Application Architect, Software Developer
·
wska
developed with use of ASP.NET 3.5, ASP.NET AJAX and SQL Server 2008
database.
Performing all design and development tasks within the "System badaniaźników jakościowych" ("Quality indicators research system") project,
XI 2006 – XII 2008 Gliwickie Studio Komputerowe –
At the beginning as Software Developer and after one year also as
Application Architect (.Net)
·
sp. z o.o. (working in „System Informatyczny Wspomagania DziaÅ‚alno
NFZ” (National Health Fund Activity Support System) project).
Working as a subcontractor for Sygnity S.A. and after that for Global Servicesści
·
in „Systemu Informatycznego Wspomagania DziaÅ‚alno
carrying out the process of their migration to ASP.NET AJAX technology.
Obtaining the role of the application architect for most of the Web applicationsÅ›ci NFZ”, and then
·
National Health Fund Departments, based on Windows Workflow Foundation
technology.
Design and development of business processes management module for the
·
of SIWDNFZ system (with use of Smart Client Software Factory technology)
Performing design and development tasks within the .Net desktop applications
·
use of Windows Communication Foundation technology.
Development of SOA architecture in National Health Fund Departments with
·
Designing and developing for Oracle database.
XII 2005 – X 2006 Biuro UsÅ‚ug Rynkowych Zbigniew Maciej Szymik
Network Administrator
–
·
1 server)
Administration of company network based on Windows 2003 Server (20 users,
·
Installation and configuration of Windows 9x/2000/XP based stations
·
Administration of Microsoft SQL Server database
·
accounting software
Installation, configuration and assist in the implementation of financial and
·
Configuration and repairs of hardware
VI 2005 – XI 2005 Firma Wasyluk.com
– Game Developer
·
Poland
Organization and administration league games in Electronic Sports League.
PRESENTATIONS
X 2010 – Rich user interface in ASP.NET MVC applications with jQuery plugins
Presentation at
Microsoft Technology Summit 2010, Warsaw, Poland.
CERTIFICATES
Microsoft Certified Professional Developer – Windows Developer
Microsoft Certified Professional Developer – Web Developer
Microsoft Certified Technology Specialist – .Net Framework 2.0 Windows
Applications
Microsoft Certified Technology Specialist – .Net Framework 2.0 Web Applications
Microsoft Certified Technology Specialist – .Net Framework 3.5 Windows Workflow
Foundation Applications
Microsoft Certified Technology Specialist – .Net Framework 3.5 ASP.NET
Applications
KNOWLEDGE OF LANGUAGES
English- fluent in writing and speaking (confirmed by FCE certificate)
ADDITIONAL INFOMARTION
Blog: http://tpeczek.blogspot.com/
Microsoft course: „Microsoft SQL Server”
Driving License: Category B
„Wyra
niezb
Osobowych, Dz. U. Nr 133, poz. 883).”
żam zgodę na przetwarzanie moich danych osobowych zawartych w tym dokumencie dla potrzebędnych do realizacji procesu rekrutacji (zgodnie z ustawa z dnia 29.08.1997 o Ochronie Danych

Tomasz P

Tuesday, February 22, 2011

Taking one sample from each group

Problem : You have a database table like following and want to return only one DeviceIMEINo for
one type of UnitModel.



UnitModelDeviceIMEINo 
GPRMC357224020036161 
GPRMC357224020065137 
KS-1689650492806 
KS-16813632782450 
M1AVL355689017535734 
M1AVL359587013296408 
M1AVL359587013296655 
M1AVL359587013296846 
M1AVL359587013296879 
M1AVL359587013297331 
M1AVL359587013297430 
M1AVL359587013297992 
M1AVL359587013299576 
M1AVL359587013302065 
M1AVL359587013307155 

This table is actually result of group by query:
select UnitModel , DeviceIMEINo from livedatagroup by UnitModel , DeviceIMEINo order by UnitModel , DeviceIMEINo

You need to write a subquery for this :
select unitmodel , deviceimeino , ID from (select UnitModel , DeviceIMEINo ,row_number() OVER ( partition by unitmodel order by unitmodel) as id from livedatagroup by UnitModel , DeviceIMEINo ) Awhere id = 1

The inner table creates a row_number column  . The outer query simply takes one rec from each group
with id = 1 (i.e. min id ) You can take min  or max as well if required.

The result is as follows :

unitmodeldeviceimeinoID
GPRMC3572240200361611
KS-16896504928061
M1AVL3595870149474621

Wednesday, February 9, 2011

CREATE TRIGGER AND ALTER TRIGGER MUST BE THE FIRST STATEMENT IN A QUERY BATCH.

CREATE TRIGGER AND ALTER TRIGGER MUST BE THE FIRST STATEMENT IN A QUERY BATCH. EVEN A 'USE' DATABASE command is not allowed. SO THE FOLLOWINNG :

USE GPS_Live
ALTER TRIGGER [dbo].[Trigger_gt06_1]
ON [dbo].[gt06]
AFTER INSERT

GIVES Following ERROR :
'ALTER TRIGGER' must be the first statement in a query batch.

The error is given for create trigger also

Comparing features of LangGraph vs CrewAI

LangGraph Orchestration vs CrewAI Orchestration The following table compares LangGraph and CrewAI orchestration across their menta...