Soal Tugas Besar - No. 1
Soal Tugas Besar - No. 1
namespace Soal1
{
public partial class Form1 : Form
{
int x, y;
private void Posisi(int x, int y, Color clr)
{
int num = (y - 1 < 0) ? 4 : (y - 1);
int num2 = (x -1 < 0) ? 4 : (x - 1);
int num3 = (y + 1) % 5;
int num4 = (x + 1) % 5;
int num5 = (x - 1 < 0) ? 4 : (x - 1);
int num6 = (y - 1 < 0) ? 4 : (y - 1);
int num7 = (x - 1 < 0) ? 4 : (x - 1);
int num8 = (y + 1) % 5;
int num9 = (x + 1) % 5;
int num10 = (y - 1 < 0) ? 4 : (y - 1);
int num11 = (x + 1) % 5;
int num12 = (y + 1) % 5;
string temp, temp1, temp2, temp3, temp4, temp5, temp6, temp7, temp8;
if (clr == Color.White)
{
temp = "Box" + x + y;
temp1 = "Box" + x + num;
temp2 = "Box" + num2 + y;
temp3 = "Box"+ x + num3;
temp4 = "Box" + num4 + y;
temp5 = "Box" + num5 + num6;
temp6 = "Box" + num7 + num8;
temp7 = "Box" + num9 + num10;
temp8 = "Box" + num11 + num12;
foreach (Control k in this.Controls)
{
if (k.Name == temp || k.Name == temp1 || k.Name == temp2 || k.Name ==
temp3 || k.Name == temp4 || k.Name == temp5 || k.Name == temp6||k.Name == temp7 ||k.Name
== temp8)
k.BackColor = Color.White;
}
}
if (clr == Color.Black)
{
temp = "Box" + x + y;
temp1 = "Box" + x + num;
temp2 = "Box" + num2 + y;
temp3 = "Box" + x + num3;
temp4 = "Box" + num4 + y;
temp5 = "Box" + num5 + num6;
temp6 = "Box" + num7 + num8;
temp7 = "Box" + num9 + num10;
temp8 = "Box" + num11 + num12;
foreach (Control k in this.Controls)
{
if (k.Name == temp)
k.BackColor = Color.Black;
if (k.Name == temp1 || k.Name == temp2 || k.Name == temp3 || k.Name
== temp4 || k.Name == temp5 || k.Name == temp6 || k.Name == temp7 || k.Name == temp8)
k.BackColor = Color.Gray;
}
}
}
public Form1()
{
InitializeComponent();
y = x = 2;
Posisi(x, y, Color.Black);
}
private void BtnUp_Click(object sender, EventArgs e)
{
Posisi(x, y, Color.White);
x = ((x - 1 < 0) ? 4 : (x - 1));
Posisi(x, y, Color.Black);
}
private void BtnDown_Click(object sender, EventArgs e)
{
Posisi(x, y, Color.White);
x = ((x + 1 )%5);
Posisi(x, y, Color.Black);
}
private void BtnRight_Click(object sender, EventArgs e)
{
Posisi(x, y, Color.White);
y = ((y + 1) % 5);
Posisi(x, y, Color.Black);
}
private void BtnLeft_Click(object sender, EventArgs e)
{
Posisi(x, y, Color.White);
y = ((y - 1 < 0) ? 4 : (y - 1));
Posisi(x, y, Color.Black);
}
}
}
NO. 2
Kode Program
using System.IO;
namespace Soal2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
richTextBox1.ReadOnly = true;
folderBrowserDialog1.ShowNewFolderButton = false;
}
private void BtnFolder_Click(object sender, EventArgs e)
{
folderBrowserDialog1.ShowDialog();
string[] file = Directory.GetFiles(folderBrowserDialog1.SelectedPath);
string[] array = file;
for (int i = 0; i < array.Length; i++)
{
string Name = array[i];
FileInfo fileInfo = new FileInfo(Name);
listView1.Items.Add(fileInfo.Name);
listView1.Items[listView1.Items.Count 1].SubItems.Add(Form1.CSize(fileInfo.Length));
listView1.Items[listView1.Items.Count 1].SubItems.Add(fileInfo.LastWriteTime.ToString("dd MMMM yyyy HH:mm:ss"));
}
}
NO. 3
using System.IO;
namespace Soal3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
folderBrowserDialog1.ShowNewFolderButton = false;
}
private void BtnFolder_Click(object sender, EventArgs e)
{
folderBrowserDialog1.ShowDialog();
List<string> list = new List<string>();
string[] files = Directory.GetFiles(folderBrowserDialog1.SelectedPath,
"*.bmp");
list.AddRange(files);
files = Directory.GetFiles(folderBrowserDialog1.SelectedPath, "*.jpg");
list.AddRange(files);
files = Directory.GetFiles(folderBrowserDialog1.SelectedPath, "*.jpeg");
list.AddRange(files);
files = Directory.GetFiles(folderBrowserDialog1.SelectedPath, "*.png");
list.AddRange(files);
files = Directory.GetFiles(folderBrowserDialog1.SelectedPath, "*.gif");
list.AddRange(files);
files = Directory.GetFiles(folderBrowserDialog1.SelectedPath, "*.tif");
list.AddRange(files);
files = Directory.GetFiles(folderBrowserDialog1.SelectedPath, "*.tiff");
list.AddRange(files);
TreeView.Nodes.Clear();
foreach (string a in list)
{
FileInfo fileInfo = new FileInfo(a);
TreeView.Nodes.Add(fileInfo.Name);
TreeView.Nodes[TreeView.Nodes.Count - 1].Nodes.Add("Size = " +
CSize(fileInfo.Length));
TreeView.Nodes[TreeView.Nodes.Count - 1].Nodes.Add("Type = " +
CType(fileInfo.Extension));
TreeView.Nodes[TreeView.Nodes.Count - 1].Nodes.Add("Date :");
TreeView.Nodes[TreeView.Nodes.Count - 1].Nodes[2].Nodes.Add("Created = "
+ fileInfo.CreationTime.ToString("dd MMM yyyy HH:mm:ss"));
TreeView.Nodes[TreeView.Nodes.Count - 1].Nodes[2].Nodes.Add("Modified = "
+ fileInfo.LastWriteTime.ToString("dd MMM yyyy HH:mm:ss"));
TreeView.Nodes[TreeView.Nodes.Count - 1].Nodes[2].Nodes.Add("Accessed = "
+ fileInfo.LastAccessTime.ToString("dd MMM yyyy HH:mm:ss"));
string[] array = fileInfo.Attributes.ToString().Split(new char[]
{
','
});
TreeView.Nodes[TreeView.Nodes.Count - 1].Nodes.Add("Attributes :");
string[] array2 = array;
for (int i = 0; i < array2.Length; i++)
{
string text = array2[i];
TreeView.Nodes[TreeView.Nodes.Count 1].Nodes[3].Nodes.Add(text.Trim());
}
}
}
private static string CSize(long size)
{
string result;
if (size > 1073741824L)
{
result = Math.Round((double)((float)size / 1.07374182E+09f), 2) + " GB";
}
else
{
if (size > 1048576L)
result = Math.Round((double)((float)size / 1048576f), 2) + " MB";
else
{
if (size > 1024L)
result = Math.Round((double)((float)size / 1024f), 2) + " KB";
else
result = size + " Bytes";
}
}
return result;
}
private static string CType(string ext)
{
string result;
if (ext.ToUpper() == ".BMP")
result = "Bitmap Image";
else
{
if (ext.ToUpper() == ".JPG" || ext.ToUpper() == ".JPEG")
result = "Joint Photographic Experts Group";
else
{
if (ext.ToUpper() == ".PNG")
result = "Portable Network Graphics";
else
{
if (ext.ToUpper() == ".GIF")
result = "Graphics Interchange Format";
else
{
if (ext.ToUpper() == ".TIF" || ext.ToUpper() == ".TIFF")
result = "Tagged Image Format";
else
result = "<Unknown Type>";
}
}
}
}
return result;
}
private void TreeView_AfterSelect(object sender, TreeViewEventArgs e)
{
int num = e.Node.FullPath.IndexOf("\\");
string selectedPath = folderBrowserDialog1.SelectedPath;
string text;
if (num < 0)
text = e.Node.Text;
else
NO. 4
using System.IO;
using System.Drawing;
namespace Soal4
{
public partial class Form1 : Form
{
private Bitmap bmp;
public Form1()
{
InitializeComponent();
openFileDialog1.Title = "Open Image File";
openFileDialog1.Filter = "Bitmap File (.Bmp)|*.bmp|JPG File
(.jpg,.jpeg)|*.jpg;*.jpeg|PNG File (.png)|*.png";
openFileDialog1.FileName = "";
saveFileDialog1.Title = "Save Dile Image";
saveFileDialog1.Filter = "Bitmap File (.Bmp)|*.bmp|JPG File
(.jpg,.jpeg)|*.jpg;*.jpeg|PNG File (.png)|*.png";
saveFileDialog1.FileName = "";
msPorses.Enabled = false;
msSave.Enabled = false;
}
private void msOpen_Click(object sender, EventArgs e)
{
openFileDialog1.FileName = "";
openFileDialog1.ShowDialog();
}
private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
{
if (File.Exists(this.openFileDialog1.FileName))
{
bmp = new Bitmap(this.openFileDialog1.FileName);
pictureBox1.Image = bmp;
msSave.Enabled = true;
msPorses.Enabled = true;
}
}
private void msSave_Click(object sender, EventArgs e)
{
saveFileDialog1.FileName = "";
saveFileDialog1.ShowDialog();
}
private void saveFileDialog1_FileOk(object sender, CancelEventArgs e)
{
FileInfo info = new FileInfo(this.saveFileDialog1.FileName);
if (info.Extension.ToUpper() == ".BMP")
bmp.Save(saveFileDialog1.FileName,
System.Drawing.Imaging.ImageFormat.Bmp);
else
{
if (info.Extension.ToUpper() == ".JPG")
bmp.Save(saveFileDialog1.FileName,
System.Drawing.Imaging.ImageFormat.Jpeg);
else
bmp.Save(saveFileDialog1.FileName,
System.Drawing.Imaging.ImageFormat.Png);
}
bmp = null;
pictureBox1.Image = null;
msSave.Enabled = false;
msPorses.Enabled = false;
}
private void msExit_Click(object sender, EventArgs e)
{
base.Close();
}
private void msNegative_Click(object sender, EventArgs e)
{
long num = 1L;
for (int i = 0; i < bmp.Width; i++)
{
for (int j = 0; j < bmp.Height; j++)
{
Color pixel = bmp.GetPixel(i, j);
bmp.SetPixel(i, j, Color.FromArgb((int)(255 - pixel.R), (int)(255 pixel.G), (int)(255 - pixel.B)));
num += 1L;
}
progressBar1.Value = (int)((float)num / (float)(bmp.Width * bmp.Height) *
100f);
Application.DoEvents();
}
pictureBox1.Image = bmp;
progressBar1.Value = 0;
}
private void msGreyScale_Click(object sender, EventArgs e)
{
long num = 1L;
for (int i = 0; i < bmp.Width; i++)
{
for (int j = 0; j < bmp.Height; j++)
{
Color pixel = bmp.GetPixel(i, j);
int num2 = (int)((pixel.R + pixel.G + pixel.B) / 3);
bmp.SetPixel(i, j, Color.FromArgb(num2, num2, num2));
num += 1L;
}
progressBar1.Value = (int)((float)num / (float)(bmp.Width * bmp.Height) *
100f);
Application.DoEvents();
}
pictureBox1.Image = bmp;
progressBar1.Value = 0;
}
private void msblackWhite_Click(object sender, EventArgs e)
{
long num = 1L;
for (int i = 0; i < bmp.Width; i++)
{
for (int j = 0; j < bmp.Height; j++)
{
Color pixel = bmp.GetPixel(i, j);
int num2 = ((pixel.R + pixel.G + pixel.B) / 3 > 127) ? 255 : 0;
bmp.SetPixel(i, j, Color.FromArgb(num2, num2, num2));
num += 1L;
}
progressBar1.Value = (int)((float)num / (float)(bmp.Width * bmp.Height) *
100f);
Application.DoEvents();
}
pictureBox1.Image = bmp;
progressBar1.Value = 0;
}
private void msRotate_Click(object sender, EventArgs e)
{
long num = 1L;
bmp.RotateFlip(RotateFlipType.Rotate90FlipXY);
pictureBox1.Image = bmp;
progressBar1.Value = (int)((float)num / (float)(bmp.Width * bmp.Height) *
100f);
Application.DoEvents();
pictureBox1.Image = bmp;
progressBar1.Value = 0;
}
}
}
using System.Data.SqlClient;
namespace UAS___Soal_2
{
public partial class Form1 : Form
{
SqlConnection conn;
SqlDataAdapter da1, da2, da3;
DataSet ds1, ds2, ds3;
public Form1()
{
InitializeComponent();
}