Tuesday, July 15, 2008

Creation of Gantt Chart using Java Script

Output:








function Gantt(gDiv)
{
var _GanttDiv = gDiv;
var _taskList = new Array();
this.AddTaskDetail = function(value)
{
_taskList.push(value);

}
this.Draw = function()
{
var _offSet = 0;
var _dateDiff = 0;
var _currentDate = new Date();
var _maxDate = new Date();
var _minDate = new Date();
var _dTemp = new Date();
var _firstRowStr = "
";
var _thirdRow = "";
var _gStr = "";
var _colSpan = 0;
var counter = 0;

_currentDate.setFullYear(_currentDate.getFullYear(), _currentDate.getMonth(),
_currentDate.getDate());
if(_taskList.length > 0)
{
_maxDate.setFullYear(_taskList[0].getTo().getFullYear(),
_taskList[0].getTo().
getMonth(), _taskList[0].getTo().getDate());
_minDate.setFullYear(_taskList[0].getFrom().getFullYear(),
_taskList[0].getFrom().
getMonth(), _taskList[0].getFrom().getDate());

for(i = 0; i < _taskList.length; i++)
{
if(Date.parse(_taskList[i].getFrom()) < Date.parse(_minDate))
_minDate.setFullYear(_taskList[i].getFrom().getFullYear(),
_taskList[i].getFrom().
getMonth(), _taskList[i].getFrom().getDate());
if(Date.parse(_taskList[i].getTo()) > Date.parse(_maxDate))
_maxDate.setFullYear(_taskList[i].getTo().getFullYear(),
_taskList[i].getTo().
getMonth(), _taskList[i].getTo().getDate());
}

//---- Fix _maxDate value for better displaying-----
// Add at least 5 days

if(_maxDate.getMonth() == 11) //December
{
if(_maxDate.getDay() + 5 > getDaysInMonth(_maxDate.getMonth() + 1,
_maxDate.getFullYear()))
_maxDate.setFullYear(_maxDate.getFullYear() + 1, 1, 5);
//The fifth day of next month will be used
else
_maxDate.setFullYear(_maxDate.getFullYear(), _maxDate.getMonth(),
_maxDate.getDate() + 5); //The fifth day of next month will be used
}
else
{
if(_maxDate.getDay() + 5 > getDaysInMonth(_maxDate.getMonth() + 1,
_maxDate.getFullYear()))
_maxDate.setFullYear(_maxDate.getFullYear(), _maxDate.getMonth() + 1,
5); //The fifth day of next month will be used
else
_maxDate.setFullYear(_maxDate.getFullYear(), _maxDate.getMonth(),
_maxDate.getDate() + 5); //The fifth day of next month will be used
}

//--------------------------------------------------

_gStr = "";
_gStr += "";
_thirdRow = "";
_dTemp.setFullYear(_minDate.getFullYear(), _minDate.getMonth(),
_minDate.getDate());
while(Date.parse(_dTemp) <= Date.parse(_maxDate))
{
if(_dTemp.getDay() % 6 == 0) //Weekend
{
_gStr += "";
if(Date.parse(_dTemp) == Date.parse(_currentDate))
_thirdRow += "";
else
_thirdRow += "";
}
else
{
_gStr += "";
if(Date.parse(_dTemp) == Date.parse(_currentDate))
_thirdRow += "";
else
_thirdRow += "";
}
if(_dTemp.getDate() < getDaysInMonth(_dTemp.getMonth() + 1,
_dTemp.getFullYear()))
{
if(Date.parse(_dTemp) == Date.parse(_maxDate))
{
_firstRowStr += "";
}
_dTemp.setDate(_dTemp.getDate() + 1);
_colSpan++;
}
else
{
_firstRowStr += "";
_colSpan = 0;
if(_dTemp.getMonth() == 11) //December
{
_dTemp.setFullYear(_dTemp.getFullYear() + 1, 0, 1);
}
else
{
_dTemp.setFullYear(_dTemp.getFullYear(), _dTemp.getMonth() + 1, 1);
}
}
}
_thirdRow += "";
_gStr += "" + _thirdRow;
_gStr += "
style='width:200px;'>Task
 
" +
_dTemp.getDate() + "
style='height:" + (_taskList.length * 21) + "'>  style='height:" + (_taskList.length * 21) + "'> 
" + _dTemp.getDate()
+ "
  T" +
(_dTemp.getMonth() + 1) + "/" + _dTemp.getFullYear() + "
T" +
(_dTemp.getMonth() + 1) + "/" + _dTemp.getFullYear() + "
";
_gStr = _firstRowStr + _gStr;
for(i = 0; i < _taskList.length; i++)
{

_offSet = (Date.parse(_taskList[i].getFrom()) - Date.parse(_minDate))
/ (24 * 60 * 60 * 1000);
_dateDiff = (Date.parse(_taskList[i].getTo()) - Date.parse(_taskList
[i].getFrom())) / (24 * 60 * 60 * 1000) + 1;
_gStr += "
style='float:left; width:" + (27 * _dateDiff - 1) + "px;'>" +

getProgressDiv(_taskList[i].getProgress()) + "
style='float:left; padding-left:3'>" + _taskList[i].getResource()
+ "
";
_gStr += "
" + _taskList[i].getTask() + "
"; }

_GanttDiv.innerHTML = _gStr;
}
}
}
function getProgressDiv(progress)
{
return "
"
}
// GET NUMBER OF DAYS IN MONTH
function getDaysInMonth(month, year)
{

var days;
switch(month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
days = 31;
break;
case 4:
case 6:
case 9:
case 11:
days = 30;
break;
case 2:
if (((year% 4)==0) && ((year% 100)!=0) || ((year% 400)==0))
days = 29;
else
days = 28;
break;
}
return (days);
}










StyleSheet.css:



body {
}

/*----- SICON GANTT CHART STYLE CLASSES --------------------------
* DESCRIPTION : Theses class is required for SIcon Gantt Chart
* NOTE : Should change the color, the text style only
*----------------------------------------------------------------*/
.Gantt
{
font-family:tahoma, arial, verdana;
font-size:11px;
}

.GTaskTitle
{
font-family:tahoma, arial, verdana;
font-size:11px;
font-weight:bold;
}

.GMonth
{
padding-left:5px;
font-family:tahoma, arial, verdana;
font-size:11px;
font-weight:bold;
}

.GToday
{
background-color: #FDFDE0;
}

.GWeekend
{
font-family:tahoma, arial, verdana;
font-size:11px;
background-color:#F5F5F5;
text-align:center;
}

.GDay
{
font-family:tahoma, arial, verdana;
font-size:11px;
text-align:center;
}

.GTask
{
border-top:1px solid #CACACA;
border-bottom:1px solid #CACACA;
height:14px;
background-color:yellow;
}

.GProgress
{
background-color:black;
height:2px;
overflow: hidden;
margin-top:5px;
}

Dynamic Creation of Controls

Output:












Firstly add a panel control ,a textbox and a button to design page .when we enter a number in textbox at run time ,the same number controls are created at runtime.


Source Code:

protected void btninsert_Click(object sender, EventArgs e)
{
int count =Convert.ToInt32(TextBox1.Text);
Panel1.Controls.Clear();
Table tb = new Table();
tb.GridLines = GridLines.Both;
for (int i = 0; i < count; i++)
{

TableCell c1 = new TableCell();
TableRow rw = new TableRow();
TextBox tx = new TextBox();
c1.Controls.Add(tx);
rw.Cells.Add(c1);
tb.Rows.Add(rw);
}
Panel1.Controls.Add(tb);
}

Wednesday, June 4, 2008

Paging Advantage of Datalist Control in asp.net with c#

HTML Coding :


















Server Side Coding: c#

SqlConnection scn = new SqlConnection("Data Source=.;Initial Catalog=iptv_database;Integrated Security=True");
int Start;
protected void Page_Load(object sender, EventArgs e)
{

if (!Page.IsPostBack)
{
ViewState["Start"] = 0;
BindData();
}
}
void BindData()
{

SqlDataAdapter da = new SqlDataAdapter("select * from addprogram", scn);
DataSet ds= new DataSet();
Start = (int)ViewState["Start"];
ViewState["Size"] = 2;
da.Fill(ds,Start,(int)ViewState["Size"], "addprogram");
DataList1.DataSource = ds;
DataList1.DataBind();


}
protected void lnkPrevious_Click(object sender, EventArgs e)
{
Start = (int)ViewState["Start"] - (int)ViewState["Size"];
ViewState["Start"] = Start;
if (Start <= 0)
{
ViewState["Start"] = 0;
}
BindData();
}
protected void lnkNext_Click(object sender, EventArgs e)
{
int count = DataList1.Items.Count;
Start = (int)ViewState["Start"] + (int)ViewState["Size"];
ViewState["Start"] = Start;
if (count <(int)ViewState["Size"])
{
ViewState["Start"] = (int)ViewState["Start"] + (int)ViewState["Size"];
Start = (int)ViewState["Start"];

}

Saturday, May 31, 2008

Creating Controls at Runtime

TextBox txt1 = new TextBox();
TextBox txt2 = new TextBox();
txt1.Text = "This is the textbox inside the placeholder";
txt2.Text = "This is the textbox inside the panel";
txt1.Style["width"] = "250px";
txt2.Style["width"] = "250px";
PlaceHolder1.Controls.Add(txt1);
Panel1.Controls.Add(txt2);

Friday, May 9, 2008

VideoStreaming in asp.net with c#

using System.IO;
using System.IO.Compression;
FileStream sourceFile;
GZipStream compStream;
FileStream destFile;
protected void btnCompress_Click1(object sender, EventArgs e)
{
if (File1.PostedFile != null)
{
txtSource.Text = File1.PostedFile.FileName.ToString();

}
sourceFile = File.OpenRead(txtSource.Text);
destFile = File.Create(txtDestination.Text);
compStream = new GZipStream(destFile, CompressionMode.Compress);
int theByte = sourceFile.ReadByte();
while (theByte != -1)
{
compStream.WriteByte((byte)theByte);
theByte = sourceFile.ReadByte();
}
sourceFile.Close();
destFile.Close();
}


protected void btnDecompress_Click(object sender, EventArgs e)
{

if (File1.PostedFile != null)
{
txtSource.Text = File1.PostedFile.FileName.ToString();

}

string srcFile = txtSource.Text;
string dstFile = txtDestination.Text;

FileStream fsIn = null; // will open and read the srcFile
FileStream fsOut = null; // will be used by the GZipStream for output to the dstFile
GZipStream gzip = null;
const int bufferSize = 4096;
byte[] buffer = new byte[bufferSize];
int count = 0;


{

fsIn = new FileStream(srcFile, FileMode.Open, FileAccess.Read, FileShare.Read);
fsOut = new FileStream(dstFile, FileMode.Create, FileAccess.Write, FileShare.None);
gzip = new GZipStream(fsIn, CompressionMode.Decompress, true);
while (true)
{
count = gzip.Read(buffer, 0, bufferSize);
if (count != 0)
{
fsOut.Write(buffer, 0, count);
}
if (count != bufferSize)
{
// have reached the end
break;
}
}
}

}
}

Monday, April 28, 2008

RSS Feeds in asp.net with c#

A simple Program to view xml in Datagrid

using System.Xml;


XmlTextReader reader = new XmlTextReader("http://msdn.microsoft.com/rss.xml");

// creates a new instance of DataSet

DataSet ds = new DataSet();

// Reads the xml into the dataset

ds.ReadXml(reader);

// Assigns the data table to the datagrid

myDataGrid.DataSource = ds.Tables[2];

// Binds the datagrid

myDataGrid.DataBind();

Using RSS Feeds with Asp.net

RSS stands for (Really Simple Syndication). Basically RSS feeds are xml files which are provided by many websites so you can view their contents on your own websites rather than browsing their site. Suppose you are a movie lover and you want to get the list of top 5 movies from 10 websites. One way will be to visit all 10 websites and see the top 5 list. This method though is used in general by lot of people but its quite tiring method. It will take you 10-15 minutes to browse all the websites and see the top 5 list of movies. One easy way will be if those movie websites provides RSS feeds to be used by the users. If they provide RSS feeds you can embed them in your page and now you don't have to browse all the websites since the information is available on a single page. Hence, this saves you a time and a lot of browsing.

Most of the Blogs websites provide RSS feeds so you can embed your or someone's else latest entries of blog on your website. In this article we will see how we can embed RSS feeds to our webform using Asp.net.

Using Authorization with Swagger in ASP.NET Core

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