tag:blogger.com,1999:blog-86294536220375706312024-03-13T11:26:23.570-07:00Share For Brightness Algorithm ve C#, .NET ProgramingArzu Türkmenhttp://www.blogger.com/profile/11385315485221708959noreply@blogger.comBlogger8125tag:blogger.com,1999:blog-8629453622037570631.post-71733211883546408622015-09-21T03:22:00.000-07:002015-09-21T03:22:12.545-07:00Format Number As Money, How?Sometimes we need convert entered numbers as money format. Thanks to javascript we can do it simultaneously. Firstly we define textbox to enter number, and give this textbox id to handle it in javascript code.<br />
<br />
<blockquote class="tr_bq">
<span style="font-family: 'Andale Mono', 'Lucida Console', Monaco, fixed, monospace; font-size: x-small;">@Html.TextBoxFor(model => model.Para, new { @class = "form-control",</span> </blockquote>
<blockquote class="tr_bq">
<span style="font-family: 'Andale Mono', 'Lucida Console', Monaco, fixed, monospace; font-size: x-small;">@ID = "paraId", @Value = String.Format("{0:C}", Model.Para) }) </span></blockquote>
<br />
We define id as paraId.Also if model is not null, we format it as money by using<b> 'String.Format("{0:C}, Model.Para")' .</b><br />
<b><br /></b>
User enters number in textbox,it triggers the javascript code.<br />
<blockquote class="tr_bq">
<pre style="background-color: #eeeeee; border: 1px dashed rgb(153, 153, 153); overflow: auto; padding: 5px; width: 100%;"><code><span style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace;"><span style="font-size: x-small;">
$(function () {
$("#paraId").on("change", function (e) {
var num = </span></span><span style="font-family: 'Andale Mono', 'Lucida Console', Monaco, fixed, monospace; font-size: x-small;">$('#paraId').val()</span><span style="font-family: 'Andale Mono', 'Lucida Console', Monaco, fixed, monospace; font-size: x-small;">;</span><span style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace;"><span style="font-size: x-small;">
</span></span><span style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace;"><span style="font-size: x-small;"> num = num.toString().replace(/\$|\,/g, '');
if (isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num * 100 + 0.50000000001);
cents = num % 100;
num = Math.floor(num / 100).toString();
if (cents < 10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3) ; i++)
num = num.substring(0, num.length - (4 * i + 3)) + '.' +
num.substring(num.length - (4 * i + 3));
document.getElementById("paraId").value = (((sign) ? '' : '-') + num + ',' + cents);
});
});
</span></span></code></pre>
</blockquote>
Firstly, we get entered value by '<span style="font-family: 'Andale Mono', 'Lucida Console', Monaco, fixed, monospace; font-size: x-small;"><b>$('#paraId').val()</b></span>'. Then We use math methods abs, floor, After we find money format, We set value of result like '<span style="font-family: 'Andale Mono', 'Lucida Console', Monaco, fixed, monospace; font-size: x-small;"><b>document.getElementById("paraId").value = (((sign) ? '' : '-') + num + ',' + cents)</b></span>'.<br />
<br />
<br />
<br />
<br />
<br />Arzu Türkmenhttp://www.blogger.com/profile/11385315485221708959noreply@blogger.com0tag:blogger.com,1999:blog-8629453622037570631.post-63235571749378796322015-07-12T08:42:00.001-07:002015-07-12T08:42:30.485-07:00Plotting a Chart of NumbersWe will design a program that asks user to enter 9 numbers, all less than 50, and plot a horizontal and vertical chart showing the values of these numbers. Also enter width value for row size.<br />
<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgd8b3eG-xAfm20mJvRyxz7PdZItNyEzGYP49p4m3dP7O_Q23u037CjtplxS0ZMhOszm529JeNU_D7bDbJWYFeTM255e6kJ1xeaa23h2vBjcz5jANk4uOKgtUgeEvixKhLOhHLsUsTIuzH7/s1600/console+1.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="203" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgd8b3eG-xAfm20mJvRyxz7PdZItNyEzGYP49p4m3dP7O_Q23u037CjtplxS0ZMhOszm529JeNU_D7bDbJWYFeTM255e6kJ1xeaa23h2vBjcz5jANk4uOKgtUgeEvixKhLOhHLsUsTIuzH7/s400/console+1.png" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">User Enters 9 Number that less than 50 and Width</td></tr>
</tbody></table>
<br />
<br />
After entered these value. Our program looks like below.<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgdcrRUztWW6cgbjrCoC4LrhaqfdodUnHH6RlND-mPJNsxSc8G3QyhOp8Vvr6sHRpcJNjXM84900seEe8EIQwT3_36epnAqIV7JDQVqQ-O74PXyQEe-kedoP6XGuCQKtyPH3MaoK94iyGJ5/s1600/console+1.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgdcrRUztWW6cgbjrCoC4LrhaqfdodUnHH6RlND-mPJNsxSc8G3QyhOp8Vvr6sHRpcJNjXM84900seEe8EIQwT3_36epnAqIV7JDQVqQ-O74PXyQEe-kedoP6XGuCQKtyPH3MaoK94iyGJ5/s400/console+1.png" width="367" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Output of the program</td></tr>
</tbody></table>
<br />
Now shall we speak how to develope this algorithmç Firstly our program must read 9 numbers using <b>scanf. </b>The horizontal chart simply displays the value of each number followed by as many *' chars as the value of the number. The vertical chart displays the same information with '*' chars being printed vertically. The value of the number is printed at the bottom of the chart as illustrated.<br />
<br />
The width of the charts can be 1,3,5 or 7.In this example 3 is chosen.<br />
<br />
Firstly we should write main class.<br />
<br />
<br />
<br />
<pre style="background-color: #eeeeee; border: 1px dashed rgb(153, 153, 153); overflow: auto; padding: 5px; width: 100%;"><code><span style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace;"><span style="font-size: x-small;">int main()
{
int i, max = 0, A[9], width; // Define variables
printf("Enter 9 number (less than 50)");
for (i = 0; i<9; i++)
{
scanf("%d", &A[i]); //Entered numbers assigned to Array
if (A[i]>max) max = A[i];//store max value among the entered values
}
printf("\nEnter width(1,3,5 or 7):");
scanf("%d", &width); // read entered width value inside widht variable
printf("max is:%d\n", max);
horizontal(max, A, width); call method of horizontal with parameters
vertical(max, A, width); call vertical method
getch(); // these for preventing to closing console
return 0;
}
</span></span></code></pre>
<br />
<br />
Now we develope Horizontal method . For parameters we send entered max value, Array of entered integers and width.<br />
<br />
<br />
<br />
<br />
<pre style="background-color: #eeeeee; border: 1px dashed rgb(153, 153, 153); overflow: auto; padding: 5px; width: 100%;"><code><span style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace;"><span style="font-size: x-small;">
int horizontal(int n, int B[9], int w)
{
int i, j, k, m, t;
printf("HORIZONTAL CHART:\n", 0);
for (i = 0; i<9; i++)
{
//root of chart
printf("%7c", 0);//7 char for empty.
printf("+");
for (k = 0; k<n; k++)//for root..
{
printf("-");
}
printf("+\n");
//end of root
//begin of body
for (j = 0; j<w; j++)//loop according to width ( rows size)
if (j == ((w + 1) / 2) - 1)//display entered value in middle of the begin of the shape
{
printf("%4c", 0);
printf("%3d", B[i]);
printf("|");
}
else
{
printf("%7c", 0); // for 7 empty chars
printf("|");
}
for (m = 0; m<B[i]; m++) //loop according to entered numbers (9 integers ) and plot '*' char (column size)
{
printf("*");
}
for (t = B[i]; t<n; t++)
printf(" "); // after '*' chars, write empyt char to end of chart
printf("|");
printf("\n");
}
//end of body
}
////begin floor
printf("%7c", 0);
printf("+");
for (i = 0; i<n; i++)
{
printf("-");
}
printf("+\n");
//end floor
return(0);
}
</span></span></code></pre>
Now you can build vertical chart yourself. Please review above algorithm and try to understand the logic.
Good luck..
Arzu Türkmenhttp://www.blogger.com/profile/11385315485221708959noreply@blogger.com0tag:blogger.com,1999:blog-8629453622037570631.post-50696715744047001582015-06-17T13:52:00.001-07:002015-07-04T06:52:05.902-07:00Shopping Cart with Form Web Application with Asp.Net (Part 1)In this project, we will design a website that displays information and allow user to add products into <b>shopping cart</b>. We willl design four pages that hold product information.<br />
<br />
Firstly we will add a class that's name is <b>Product.cs.(Add New Item -> Class).</b>This file contains information about the products.Let Visual Studio create the <b>App_Code</b> folder for <b>Product.cs.</b><br />
<b><br /></b>
Define a constructor for the <b>Product </b>class<b> </b>which takes all of its member variables as parameter.<br />
<br />
Product class should be like below.<br />
<br />
<pre style="background-color: #eeeeee; border: 1px dashed rgb(153, 153, 153); overflow: auto; padding: 5px; width: 100%;"><code><span style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace;"><span style="font-size: x-small;">
public class Product
{
public int ProductID;
public string Type;
public string Vendor;
public string Model;
public string ImageUrl;
public int globalvar;
public static ArrayList proCopy;
public static int id;
public Product(int ProductID, string Type, string Vendor, string Model, string ImageUrl)
{
this.ProductID = ProductID;
this.Type = Type;
this.Vendor = Vendor;
this.Model = Model;
this.ImageUrl = ImageUrl;
}
public Product()
{
}
public void AddIndex(int n)
{
id = n;
}
public int getIndex()
{
return id;
}
public void copyArray(System.Collections.ArrayList array)
{
proCopy = array;
}
public System.Collections.ArrayList getArray()
{
return proCopy;
}
}
</span></span></code></pre>
<span style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace;"><b>Design Default.aspx</b></span>
<br />
In Default.aspx page check if the user logged in or not.We use <b>cookie </b>check.The cookie should contain only <b>first name</b> and <b>last name</b> of the user. If no such cookie is defined, then should be displayed a message then link to the <b>Login.aspx</b>.
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: left; margin-right: 1em; text-align: left;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj7RqG_gSlQt51J-u0-Y1Jtv-sKWZHpLtGtFMPQegV1ZUeeLvhpI_tdpUb-UxO5z6Z47PFbo9UMQEFKfJ6QjtCBHWZg4jVeM7WO5JYHdPwJiuyD3lwCv17Z_vgDcMOQJsw_Hjx5Vvs_cI0a/s1600/Default.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="312" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj7RqG_gSlQt51J-u0-Y1Jtv-sKWZHpLtGtFMPQegV1ZUeeLvhpI_tdpUb-UxO5z6Z47PFbo9UMQEFKfJ6QjtCBHWZg4jVeM7WO5JYHdPwJiuyD3lwCv17Z_vgDcMOQJsw_Hjx5Vvs_cI0a/s640/Default.png" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Fig. 1 – Default.aspx when user is not logged in.</td></tr>
</tbody></table>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgpzJ0AQH6wR_p9tR5MtM1M1QtYFZMSYklYsW7Pf4E5L7K7-nM_nEGVe_Vhljvr7AZYUf_JUgspwE33nmtG0J6bJfoGrLa2BtBjvb4QoqEP_C05T3qdSUN2wiOHV7kMzfDDHwjmLiAosar1/s1600/Default.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="312" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgpzJ0AQH6wR_p9tR5MtM1M1QtYFZMSYklYsW7Pf4E5L7K7-nM_nEGVe_Vhljvr7AZYUf_JUgspwE33nmtG0J6bJfoGrLa2BtBjvb4QoqEP_C05T3qdSUN2wiOHV7kMzfDDHwjmLiAosar1/s640/Default.png" width="640" /></a></div>
When Login button is clicked, <b>first name</b> and <b>last name</b> will be written into a cookie named <b>UserInfo</b> for <b>one month</b> and will redirect to the left of Default.aspx.
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<pre style="background-color: #eeeeee; border: 1px dashed rgb(153, 153, 153); overflow: auto; padding: 5px; width: 100%;"><code><span style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace;"> In Login.aspx.cs click method.<span style="font-size: x-small;">
protected void btnLogin_Click(object sender, EventArgs e)
{
//Create new cookie
HttpCookie cookie = new HttpCookie("UserInfo");
// add name and lastname to the cookie
cookie["UserInfo"] = txtFirstName.Text+" "+txtLastName.Text;
if (txtFirstName.Text == null || txtLastName.Text == null)
{
//lblLogin.Text = "Please specify valid Name and LastName";
}
else
{
<span style="font-size: x-small;"> //Define cookie for one month
cookie.Expires = DateTime.Now.AddDays(30);
Response.Cookies.Add(cookie);
Response.Redirect("Default.aspx");
}
}</span></span></span></code></pre>
In Default.aspx.cs file we get cookie data with
<code><span style="font-family: 'Andale Mono', 'Lucida Console', Monaco, fixed, monospace;"><b style="font-size: small;">Request.Cookies["UserInfo"]. </b>If cookie is null, redirect to login page.If cookie store data of user info, allow the see<span style="font-size: x-small;"> </span>product information<span style="font-size: x-small;">.</span></span></code>
<br />
<pre style="background-color: #eeeeee; border: 1px dashed rgb(153, 153, 153); overflow: auto; padding: 5px; width: 100%;"><code><span style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace;"><span style="font-size: x-small;">
protected void Page_Load(object sender, EventArgs e)
{
HttpCookie cookie = Request.Cookies["UserInfo"];
if (cookie == null ) // if no cookies
{
lblExistingCookie.Text = "You are not login Please login ";
hyperlink1.Visible = true;
lnkBtnCart. Visible = false;
btnLogout.Visible = false;
linkSamC2.Visible = false;
linkSamE2.Visible = false;
linkToshiba.Visible = false;
linkLenova.Visible = false;
linkAcer.Visible = false;
lblHyper.Visible = false;
}
else
{
// lblExistingCookie.Visible = true;
hyperlink1.Visible = false;
lblExistingCookie.Text = "Welcome " + cookie["UserInfo"] + "!";
lnkBtnCart. Visible = true;
btnLogout.Visible = true;
linkSamC2.Visible = true;
linkSamE2.Visible = true;
linkToshiba.Visible = true;
linkLenova.Visible = true;
linkAcer.Visible = true;
lblHyper.Visible = true;
}
if (!Page.IsPostBack) // first load create five product
{
//create Product objects
Product part1 = new Product(1,"Phone","Samsung","C270","samsung.jpg");
Product part2 = new Product(2,"Phone","Samsung","E250i","samsungE2.jpg");
Product part3 = new Product(3,"Laptop","Toshiba","L500","toshiba.jpg");
Product part4 = new Product(4,"Laptop","Lenova","G550","lenova.jpg");
Product part5 = new Product(5,"Netbook","Acer","FO200","acer.jpg");
//Add objects to the session state
Session["Product1"] = part1;
Session["Product2"] = part2;
Session["Product3"] = part3;
Session["Product4"] = part4;
Session["Product5"] = part5;
}
if(btnLogout.Visible == true)
{
linkSamC2.Visible = true;
linkSamE2.Visible = true;
linkToshiba.Visible = true;
linkLenova.Visible = true;
linkAcer.Visible = true;
lblHyper.Visible = true;
}
}</span></span></code></pre>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: left; font-family: 'Times New Roman'; margin-right: 1em; text-align: left;"><tbody>
<tr><td><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh49DgXeQkpUkIFrrSzI_JTo7eSi2eChJpywGRFWOtS77SngiCnzyOq9W8xb7lFYOdLjC8adPTw6TN0yH2s2Dkz1xL6EkhmijVsvUfk47L8Y911qUpe7PTVwIN1YoprJUv29yDrDpKHXwLZ/s1600/Default.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="246" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh49DgXeQkpUkIFrrSzI_JTo7eSi2eChJpywGRFWOtS77SngiCnzyOq9W8xb7lFYOdLjC8adPTw6TN0yH2s2Dkz1xL6EkhmijVsvUfk47L8Y911qUpe7PTVwIN1YoprJUv29yDrDpKHXwLZ/s640/Default.png" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="font-size: 12.8000001907349px;">Default.aspx file when user entered with name and last name</td></tr>
</tbody></table>
<span style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace;">
</span>
We Design Login.aspx and Default.aspx page. Then we continue to design <b>ProductInfo.aspx page </b>that display information of product.Then design <b>Cart.aspx. </b>It will done for display all products that are added to shopping cart.
See You..
<span style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: x-small;"><span style="font-size: 12px; line-height: 14px;">
</span></span>Arzu Türkmenhttp://www.blogger.com/profile/11385315485221708959noreply@blogger.com0tag:blogger.com,1999:blog-8629453622037570631.post-77983553183706076722015-06-14T02:03:00.001-07:002015-06-14T02:03:23.001-07:00Download multiple files as a Zip file with Asp.NetWhile doing project, you may need load system to multiple files. After saving it, you may need to download them to your PC. You can download them as a Zip by using Asp.Net.<br />
<br />
Initially in View, define button that triggers to download files.<br />
<br />
<blockquote class="tr_bq">
<span style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 12.8000001907349px;"><a href="@Url.Action("</span><wbr style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 12.8000001907349px;"></wbr><span style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 12.8000001907349px;">ControllerMethod", "ControllerName", new {id = 12})</span><wbr style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 12.8000001907349px;"></wbr><span style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 12.8000001907349px;">" class="btn btn-success"><i class="fa fa-download"></i> Export File </a></span></blockquote>
<br />
<ul>
<li>In View, like above, we define button which trigger the method in Controller. In @Url.Action firstly define Controlller method name, after that, define Controller name. If we want to send parameter to controller method, wecan specify it like this 'new {id=12} '. Use <i class="fa fa-download"></i> to get an download icon object on button.</li>
</ul>
<br />
In Controller:<br />
<br />
You can reach parameter value with id which we can specify like this in View. To get Zip file we should include System.IO.Compression namespace and add System.IO.Compression.dll to project.<br />
We will use ZipArchive.CreateEntry method to create an empty entry in the zip archive.<br />
To get more please visit <a href="https://msdn.microsoft.com/en-us/library/system.io.compression.ziparchive.createentry(v=vs.110).aspx" target="_blank">link</a>.<br />
<br />
<pre style="background-color: #eeeeee; border: 1px dashed rgb(153, 153, 153); overflow: auto; padding: 5px; width: 100%;"><code><span style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace;"> <span style="font-size: x-small;">
public ActionResult ControllerMethod(int id)
{
using (var compressedFileStream = new MemoryStream())
{
using (var zipArchive = new ZipArchive(compressedFileStream, ZipArchiveMode.Update, false))
{
//get list of file
var listOfFile = _servis.GetListOfFiles(id);
int i = 1;
//loop all the files which export
foreach (var file in listOfFile )
{
//get file name
string fileName = file.fileName;
var zipEntry11 = zipArchive.CreateEntry(fileName);
if (file != null)
{
//get file content
using (var originalFileStream = new MemoryStream(file.fileContent.ToArray()))
{
using (var zipEntryStream = zipEntry11.Open())
{
await originalFileStream.CopyToAsync(zipEntryStream);
}
}
}
i++;
}
}
//Add multiple file in a zip file
return File(compressedFileStream.ToArray(), "application/zip", "FileName.zip");
}
}
</span><span style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace;"><span style="font-size: 12px; line-height: 14px;">
</span></span></span></code></pre>
Arzu Türkmenhttp://www.blogger.com/profile/11385315485221708959noreply@blogger.com0tag:blogger.com,1999:blog-8629453622037570631.post-57907125006344780022015-06-06T05:46:00.003-07:002015-06-10T14:12:11.927-07:00ViewBag with Multiple SelectList in Asp.Net Mvc<b> ViewBag </b>used as a bag to move data from Controller toView. In my daily software life, use it frequently. In ViewBag you can store string, integer,. vs values or list. In View you can want to select <b>multiple </b>item from the list. Now i want to share how to select multiple items from list which store in ViewBag.<br />
<br />
In Controller, get all personels with the <b>_service.GetPersonel()</b> method.To select multiple personels, should define <b>Multiple </b>before<b> SelectList. </b>If you select only one personel, can define <b>new SelectList(). </b>In ViewBag we shsould store personels' name and surname in <b>Text, idtPersonel </b>in Value.<br />
<br />
<br />
<br />
<br />
<br />
<br />
<li>In Controller</li>
<br />
<pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"><code><span style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 12.8000001907349px; line-height: normal; white-space: normal;"> public ICollection<int> </span><span style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 12.8000001907349px; line-height: normal; white-space: normal;">idtPersonels</span><span style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 12.8000001907349px; line-height: normal; white-space: normal;">{ get; set; }</span></code></pre>
<div>
<pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"><code>
<pre style="background-color: #eeeeee; border: 1px dashed rgb(153, 153, 153); overflow: auto; padding: 5px; width: 100%;"><code><div style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 12.8000001907349px; white-space: normal;">
ViewBag.Personeller = <span style="font-size: 12.8000001907349px;"> new MultiSelectList(</span><span style="font-size: 12.8000001907349px;"> (_service.</span><wbr style="font-size: 12.8000001907349px;"></wbr><span style="font-size: 12.8000001907349px;">GetPersonels(</span><span style="font-size: 12.8000001907349px;">))</span></div>
<div style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 12.8000001907349px; white-space: normal;">
.Select(x => new SelectListItem</div>
<span style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace;">
</span><div style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 12.8000001907349px; white-space: normal;">
{</div>
<span style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace;">
</span><div style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 12.8000001907349px; white-space: normal;">
Text = x.Name+ " " + x.Surname+ " " + x.ID,</div>
<span style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace;">
</span><div style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 12.8000001907349px; white-space: normal;">
Value = x.<span style="font-size: 12.8000001907349px;">idtPersonels</span><span style="font-size: 12.8000001907349px;">.ToString()</span></div>
<span style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace;">
</span><div style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 12.8000001907349px; white-space: normal;">
}), "Value", "Text");<br />
<div>
</div>
</div>
</code></pre>
</code></pre>
<br />
<br />
<br />
In View, users store selected personels in <b>idtPersonels. </b>To use multiple property of <span style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 12.8000001907349px;">DropDownListFor , create class and call select2 and make </span><span style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 12.8000001907349px;"> </span><span style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 12.8000001907349px;">@multiple property true. Please visit what is <a href="https://select2.github.io/" target="_blank">Select2</a> to get more info. </span><br />
<br /></div>
<br />
<br />
<br />
<br />
<li>In View</li>
<br />
<pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"><code><div style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 12.8000001907349px; line-height: normal; white-space: normal;">
<div>
<div class="form-group"></div>
<div>
<span style="font-size: 12.8000001907349px;"> </span></div>
<div>
@Html.DropDownListFor(m => m.<span style="font-size: 12.8000001907349px;">idtPersonels</span>, (MultiSelectList)ViewBag.<span style="font-size: 12.8000001907349px;">Personeller </span>, new { @class = "form-control select2", @multiple = true })</div>
<div>
</div>
<div>
</div></div>
<div>
</div>
</div>
</code></pre>
<span style="color: black; font-size: 12px; line-height: 14px;">
</span>
<br />
<div>
<br />
<br />
<br /></div>
After select multiple personels in View, We can reach these selected personels like this.<br />
<br />
<br />
<br />
<br />
<br />
<li>In Controller</li>
<br />
<pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"><code><div style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 12.8000001907349px; line-height: normal; white-space: normal;">
public ActionResult GetPersonel(FormCollection form<span style="font-size: 12.8000001907349px;">)</span></div>
<div style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 12.8000001907349px; line-height: normal; white-space: normal;">
{ </div>
<div style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 12.8000001907349px; line-height: normal; white-space: normal;">
//in form["<span style="font-size: 12.8000001907349px;">idtPersonels</span><span style="font-size: 12.8000001907349px;">"] store id like : {12,45,85}, and we must split them</span></div>
<div style="background-color: white; font-family: arial, sans-serif; font-size: 12.8000001907349px; line-height: normal; white-space: normal;">
<span style="color: #222222;"> </span></div>
<div style="background-color: white; font-family: arial, sans-serif; font-size: 12.8000001907349px; line-height: normal; white-space: normal;">
<span style="color: #222222;"></span><span style="color: #222222;"> string[] listOfPersonel = form["idtPersonels"].ToString()</span><span class="pun" style="background-color: #eeeeee; border-image-outset: initial; border-image-repeat: initial; border-image-slice: initial; border-image-source: initial; border-image-width: initial; border: 0px; color: black; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; font-size: 13px; margin: 0px; padding: 0px; white-space: inherit;">.</span><span class="pun" style="background-color: #eeeeee; border-image-outset: initial; border-image-repeat: initial; border-image-slice: initial; border-image-source: initial; border-image-width: initial; border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; font-size: 13px; margin: 0px; padding: 0px; white-space: inherit;"><span style="color: #2b91af;">Split</span></span><span class="pun" style="background-color: #eeeeee; border-image-outset: initial; border-image-repeat: initial; border-image-slice: initial; border-image-source: initial; border-image-width: initial; border: 0px; color: black; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; font-size: 13px; margin: 0px; padding: 0px; white-space: inherit;">(</span><span class="kwd" style="background-color: #eeeeee; border-image-outset: initial; border-image-repeat: initial; border-image-slice: initial; border-image-source: initial; border-image-width: initial; border: 0px; color: darkblue; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; font-size: 13px; margin: 0px; padding: 0px; white-space: inherit;">new</span><span class="pln" style="background-color: #eeeeee; border-image-outset: initial; border-image-repeat: initial; border-image-slice: initial; border-image-source: initial; border-image-width: initial; border: 0px; color: black; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; font-size: 13px; margin: 0px; padding: 0px; white-space: inherit;"> </span><span class="kwd" style="background-color: #eeeeee; border-image-outset: initial; border-image-repeat: initial; border-image-slice: initial; border-image-source: initial; border-image-width: initial; border: 0px; color: darkblue; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; font-size: 13px; margin: 0px; padding: 0px; white-space: inherit;">char</span><span class="pun" style="background-color: #eeeeee; border-image-outset: initial; border-image-repeat: initial; border-image-slice: initial; border-image-source: initial; border-image-width: initial; border: 0px; color: black; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; font-size: 13px; margin: 0px; padding: 0px; white-space: inherit;">[]</span><span class="pln" style="background-color: #eeeeee; border-image-outset: initial; border-image-repeat: initial; border-image-slice: initial; border-image-source: initial; border-image-width: initial; border: 0px; color: black; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; font-size: 13px; margin: 0px; padding: 0px; white-space: inherit;"> </span><span class="pun" style="background-color: #eeeeee; border-image-outset: initial; border-image-repeat: initial; border-image-slice: initial; border-image-source: initial; border-image-width: initial; border: 0px; color: black; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; font-size: 13px; margin: 0px; padding: 0px; white-space: inherit;">{</span><span class="pln" style="background-color: #eeeeee; border-image-outset: initial; border-image-repeat: initial; border-image-slice: initial; border-image-source: initial; border-image-width: initial; border: 0px; color: black; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; font-size: 13px; margin: 0px; padding: 0px; white-space: inherit;"> </span><span class="str" style="background-color: #eeeeee; border-image-outset: initial; border-image-repeat: initial; border-image-slice: initial; border-image-source: initial; border-image-width: initial; border: 0px; color: maroon; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; font-size: 13px; margin: 0px; padding: 0px; white-space: inherit;">','</span><span class="pln" style="background-color: #eeeeee; border-image-outset: initial; border-image-repeat: initial; border-image-slice: initial; border-image-source: initial; border-image-width: initial; border: 0px; color: black; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; font-size: 13px; margin: 0px; padding: 0px; white-space: inherit;"> </span><span class="pun" style="background-color: #eeeeee; border-image-outset: initial; border-image-repeat: initial; border-image-slice: initial; border-image-source: initial; border-image-width: initial; border: 0px; color: black; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; font-size: 13px; margin: 0px; padding: 0px; white-space: inherit;">},</span><span class="pln" style="background-color: #eeeeee; border-image-outset: initial; border-image-repeat: initial; border-image-slice: initial; border-image-source: initial; border-image-width: initial; border: 0px; color: black; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; font-size: 13px; margin: 0px; padding: 0px; white-space: inherit;"> </span><span class="typ" style="background-color: #eeeeee; border-image-outset: initial; border-image-repeat: initial; border-image-slice: initial; border-image-source: initial; border-image-width: initial; border: 0px; color: #2b91af; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; font-size: 13px; margin: 0px; padding: 0px; white-space: inherit;">StringSplitOptions</span><span class="pun" style="background-color: #eeeeee; border-image-outset: initial; border-image-repeat: initial; border-image-slice: initial; border-image-source: initial; border-image-width: initial; border: 0px; color: black; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; font-size: 13px; margin: 0px; padding: 0px; white-space: inherit;">.</span><span class="typ" style="background-color: #eeeeee; border-image-outset: initial; border-image-repeat: initial; border-image-slice: initial; border-image-source: initial; border-image-width: initial; border: 0px; color: #2b91af; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; font-size: 13px; margin: 0px; padding: 0px; white-space: inherit;">RemoveEmptyEntries</span><span class="pun" style="background-color: #eeeeee; border-image-outset: initial; border-image-repeat: initial; border-image-slice: initial; border-image-source: initial; border-image-width: initial; border: 0px; color: black; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; font-size: 13px; margin: 0px; padding: 0px; white-space: inherit;">);</span></div>
<div style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 12.8000001907349px; line-height: normal; white-space: normal;">
<span class="pun" style="background-color: #eeeeee; border: 0px; color: black; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; font-size: 13px; margin: 0px; padding: 0px; white-space: inherit;"></span></div>
<div style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: 12.8000001907349px; line-height: normal; white-space: normal;">
}</div>
</code></pre>
Arzu Türkmenhttp://www.blogger.com/profile/11385315485221708959noreply@blogger.com0tag:blogger.com,1999:blog-8629453622037570631.post-26897726661521251002015-05-30T02:42:00.000-07:002015-05-30T02:42:05.239-07:00Moving Files To Disc<div class="MsoNormal">
<span style="font-family: "Arial","sans-serif"; mso-ansi-language: TR; mso-bidi-font-weight: bold; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: "Arial","sans-serif"; mso-ansi-language: TR; mso-bidi-font-weight: bold; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin;"> <span style="font-family: Arial, Helvetica, sans-serif;"> This project is done for log files which make crowd</span></span><span style="font-family: Arial, sans-serif;"> </span><span style="font-family: Arial, sans-serif;">to move</span><span style="font-family: Arial, sans-serif;"> </span><span style="font-family: Arial, sans-serif;"> when they fill <b>the space of disc</b>.Did
this project while working as </span><span style="font-family: Arial, sans-serif;">intern</span><span style="font-family: Arial, sans-serif;">.</span></div>
<div class="MsoNormal">
<span style="font-family: Arial, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Arial, sans-serif;"> They complained about logs which filled the
disc space and crash the system.This project which i did, automatially sorted
logs by creation date. Then they fill them in files and zipped. Then move this
<b>zipped files</b> to desired location.Thanks to this, you never lost log files, and
can reach any of them by looking <b>creation time</b>.</span></div>
<div class="MsoNormal">
<span style="font-family: Arial, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Arial, sans-serif;"> Also you can specify <b>source and
target disc name</b>, and amount of files which will move. Developed with C# Windows Desktop . </span></div>
<div class="MsoNormal">
<span style="font-family: Arial, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Arial, sans-serif;">In Visual Studio when you want to pass parameters to application from outside you can right click the project and add <b>General -> Settings File.</b></span></div>
<div class="MsoNormal">
<span style="font-family: Arial, sans-serif;"><br /></span></div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh3tO8InjLTIUCx2R7r-DUxI_K7beUNNnbtQb-cPhfHNqdT6qNZfX5ETihYlpqQTBV9PBsOn507K6YvCv0-rtAH8EjnLmRs0Gu3_VreU4U5X77M_KeI84Qts3a-trv1kAhIDHAoniX7Qva_/s1600/settings.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="223" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh3tO8InjLTIUCx2R7r-DUxI_K7beUNNnbtQb-cPhfHNqdT6qNZfX5ETihYlpqQTBV9PBsOn507K6YvCv0-rtAH8EjnLmRs0Gu3_VreU4U5X77M_KeI84Qts3a-trv1kAhIDHAoniX7Qva_/s400/settings.png" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Add Settings File<br />
<br /></td></tr>
</tbody></table>
<div class="MsoNormal">
<span style="font-family: Arial, sans-serif;"> After adding Settings File, enter parameter which use in projects.</span></div>
<div class="MsoNormal">
<span style="font-family: Arial, sans-serif;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEil0i1UdOk8clMWQ86XKpMknwqTGA7SAqaaGqr7-K4KWGOldFP7unc9xPpVCBDtn6S9WgVTssGeT44pKTo6LWhRN4z4AVo-so7_zIAfJzCpzA5QegXYDHS8LfJQ2HRFuo4PHfqEqcPGvvKd/s1600/settings.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="223" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEil0i1UdOk8clMWQ86XKpMknwqTGA7SAqaaGqr7-K4KWGOldFP7unc9xPpVCBDtn6S9WgVTssGeT44pKTo6LWhRN4z4AVo-so7_zIAfJzCpzA5QegXYDHS8LfJQ2HRFuo4PHfqEqcPGvvKd/s400/settings.png" width="400" /></a></div>
<div class="MsoNormal">
<span style="font-family: Arial, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Arial, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Arial, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Arial, sans-serif;"><b>SourceFolder</b>: Location of Moving File from it</span></div>
<div class="MsoNormal">
<span style="font-family: Arial, sans-serif;"><b>TargetFolder</b>: Location of Moving File to it</span></div>
<div class="MsoNormal">
<span style="font-family: Arial, sans-serif;"><b>WarningAmountOfFileSize</b>: how much disc size fill the disch and trigger to move</span></div>
<div class="MsoNormal">
<span style="font-family: Arial, sans-serif;"><b>AmountOfPercentForMovingFull </b>: Amount of percent of files which will move</span></div>
<div class="MsoNormal">
<span style="font-family: Arial, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Arial, sans-serif;">In <b>Type </b>specify the type of variables and for <b>Scope </b>choose the <b>Application</b>.</span></div>
<div class="MsoNormal">
<span style="font-family: Arial, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Arial, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Arial, sans-serif;">In <b>Program.cs</b> in <b>Main</b> method you can reach the parameter:</span></div>
<div class="MsoNormal">
<span style="font-family: Arial, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Arial, sans-serif;"> string directoryName = <b>Settings</b>.Default.TargetFolder;</span></div>
<div class="MsoNormal">
<span style="font-family: Arial, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Arial, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Arial, sans-serif;">In main method specify below.</span></div>
<div class="MsoNormal">
<span style="font-family: Arial, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Arial, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<br /></div>
<pre style="background-color: #eeeeee; border: 1px dashed rgb(153, 153, 153); overflow: auto; padding: 5px; width: 100%;"><code><span style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace;">
<span style="font-size: x-small;">
public static void Main(string[] args)
{
Program myProgram= new Program();
//prevent multiple instance of C# application
if (Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName).Length > 1)
{
Console.WriteLine("Only one instance allowed");
Environment.Exit(0);
}
else
{
/*create target directory to store log files*/
DateTime dailyDate = DateTime.Now;
String directoryTargetName = myProgram.GetTargetDirectoryName(dailyDate);
int count = 0;
//listing all files in disk
string[] a1 = Directory.GetFiles(@Settings.Default.SourceFolder);
//get free disk space
string sourceDriverName = Settings.Default.SourceFolder.Split(new char[] { System.IO.Path.DirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries).Last();
string targetDriverName = Settings.Default.TargetFolder.Split(new char[] { System.IO.Path.DirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries).Last();
/*Specify Target Directory and check its availability*/
string _directoryNameS = Settings.Default.TargetFolder + "\\" + directoryTargetName;
myProgram.CheckExistDirectory(_directoryNameS);
Boolean bFlag= myProgram.ControlOfCapacitySourceAndTargetDisc(sourceDriverName,targetDriverName);
//Display all files
Console.WriteLine("-----Files -------");
foreach (string name in a1)
{
Console.WriteLine(name);
}
Console.WriteLine("----Sorted Array by creation date------");
//display sorting array
//sort file by creation date
IComparer fileComparer = new CompareFileByDate();
Array.Sort(a1, fileComparer);
foreach (string f in a1) // count file numbers
{
count++;
Console.WriteLine(f);
}
//Move directories to another disc
string destinationFile = @Settings.Default.TargetFolder; // destination disc
Console.WriteLine("**********************************************");
//calculate amount of moving from source to target disc
decimal AmountOfMoving = Convert.ToDecimal(count) * Settings.Default.AmountOfPercentForMovingFull;
int countSon = Convert.ToInt32(AmountOfMoving);
// control of target disc's free space
decimal division = myProgram.GetDivision(sourceDriverName); // get division
if (bFlag && division <= Settings.Default.WarningAmountOfFullSize) // what percent of disc is moving
{
Console.WriteLine("Warning,80 percent of disk is full");
Console.WriteLine("you must carry move files another free disk");
Console.WriteLine("%d of files are moving " + countSon);
foreach (string f in a1)
{
Console.WriteLine(f);
string lastDirectory = f.Split(new char[] { System.IO.Path.DirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries).Last();
File.Move(f, _directoryNameS + "\\" + lastDirectory); // store in dateTime directory
countSon--;
if (countSon == 0)
{
break;
}
}
}
else
{
Console.WriteLine("You have enough space for saving files..");
}
}
}
</span><span style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace;"><span style="font-size: 12px; line-height: 14px;">
</span></span></span></code></pre>
<pre style="background-color: #eeeeee; border: 1px dashed rgb(153, 153, 153); overflow: auto; padding: 5px; width: 100%;"><code><span style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace;"><span style="font-size: x-small;">
//Check the existence of directory
public void CheckExistDirectory(String directoryName)
{
//check folder exists
if (Directory.Exists(directoryName))
{
Console.WriteLine("Warning !!! This directory is exists ..");
}
else
{
Console.WriteLine("Created Directory successfully ..");
Directory.CreateDirectory(directoryName);
}
}
</span><span style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace;"><span style="font-size: 12px; line-height: 14px;">
</span></span></span></code></pre>
<div>
</div>
<pre style="background-color: #eeeeee; border: 1px dashed rgb(153, 153, 153); overflow: auto; padding: 5px; width: 100%;"><code><span style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace;"><span style="font-size: x-small;">
<summary>
/// Calculate Capacity of Discs
</summary> public Boolean ControlOfCapacitySourceAndTargetDisc(String sourceDriverName, String targetDriverName)
{
/*Calculate amount of logs in Source Driver*/
DriveInfo dS = new DriveInfo(sourceDriverName);
Console.WriteLine("Total size of Source Driver : " + dS.TotalSize);
Console.WriteLine("Total free size of Source Driver: " + dS.TotalFreeSpace);
decimal totalSizeS = dS.TotalSize;
decimal totalFreeSizeS = dS.TotalFreeSpace;
decimal amountOfUsing = totalSizeS - totalFreeSizeS;
Console.WriteLine("önceki gidecek kısım : " + amountOfUsing);
amountOfUsing = amountOfUsing * Settings.Default.AmountOfPercentForMovingFull; // taşınacak miktarın büyüklüğü
Console.WriteLine("tasinacak kısım : " + amountOfUsing);
/*Control of Target Driver Capacity*/
DriveInfo dD = new DriveInfo(targetDriverName);
Console.WriteLine("Total free space of Target Disc: " + dD.TotalFreeSpace);
decimal totalFreeSizeD = dD.TotalFreeSpace;
Console.WriteLine("gidecek kısım : " + amountOfUsing + "yer var var mı : " + totalFreeSizeD);
if (amountOfUsing <= totalFreeSizeD)
{
return true;
}
else
{
Console.WriteLine("Warninng !!! You do not have enough target space for moving ");
return false;
}
}
</span><span style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace;"><span style="font-size: 12px; line-height: 14px;">
</span></span></span></code></pre>
<div>
</div>
<pre style="background-color: #eeeeee; border: 1px dashed rgb(153, 153, 153); overflow: auto; padding: 5px; width: 100%;"><code><span style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace;"><span style="font-size: x-small;">
public class CompareFileByDate : IComparer
{
/// <summary>
/// Metod açıklaması
/// </summary>
/// <param name="a" />param1
/// <param name="b" />param2
/// <returns></returns>
public int Compare(Object a, Object b)
{
FileInfo fia = new FileInfo((string)a);
FileInfo fib = new FileInfo((string)b);
DateTime cta = fia.CreationTime;
DateTime ctb = fib.CreationTime;
return DateTime.Compare(cta, ctb);
}
}
</span><span style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace;"><span style="font-size: 12px; line-height: 14px;">
</span></span></span></code></pre>
<div>
</div>
Arzu Türkmenhttp://www.blogger.com/profile/11385315485221708959noreply@blogger.com0tag:blogger.com,1999:blog-8629453622037570631.post-40574477369220919522015-05-27T15:15:00.000-07:002015-05-27T15:15:14.992-07:00In WebSite Find Online and Total Users CountIn websites we see online users and total user who visit the website. We may want to use this information in our websites. In Asp.net we can do it by using Global.asax to display it<b>. </b>To add it follow this way.<b> </b><span style="background-color: white; color: #333333; font-family: Arial, Helvetica; font-size: 14.7839994430542px; line-height: 19.2192001342773px;"><b>File -> New-> Project-> Asp.net Web Application </b>and add Global.asax.</span><br />
<b><a href="https://msdn.microsoft.com/en-us/library/ms178594(v=vs.140).aspx" target="_blank">Application State</a> </b>can save user counts.More information click link and get more info.<br />
<span style="background-color: white; color: #333333; font-family: Arial, Helvetica; font-size: 14.7839994430542px; line-height: 19.2192001342773px;"><br /></span>
<br />
<pre style="background-color: #eeeeee; border: 1px dashed rgb(153, 153, 153); overflow: auto; padding: 5px; width: 100%;"><code><span style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace;"><span style="font-size: 12px; line-height: 14px;">
</span></span><span style="font-size: 12px; line-height: 14px;"><%@ Application Language="C#" %>
<script runat="server">
public static int count = 0;
void Application_Start(object sender, EventArgs e)
{
Application["TotalUsers"] = count;
Application["OnlineUsers"] = count;
}
void Application_End(object sender, EventArgs e)
{
// Application["users"] = -1;
}
void Application_Error(object sender, EventArgs e)
{
Exception exception = Server.GetLastError();
string message = "Error occurred in - " + Request.Url.ToString() + "and error message is - "
+ exception.Message + " Stack Trace - " + exception.StackTrace.ToString();
}
void Session_Start(object sender, EventArgs e)
{
Application.Lock();
count++;
Application["OnlineUsers"] = count;
Application["TotalUsers"] = count ;
Application.UnLock();
}
void Session_End(object sender, EventArgs e)
{
// count--;
Application.Lock();
Application["OnlineUsers"] = count - 1;
Application.UnLock();
}
</script></span><span style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace;"><span style="font-size: 12px; line-height: 14px;">
</span></span></code></pre>
<div>
<code><br /></code></div>
<pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"></pre>
Arzu Türkmenhttp://www.blogger.com/profile/11385315485221708959noreply@blogger.com0tag:blogger.com,1999:blog-8629453622037570631.post-36880853242866119812015-05-23T07:20:00.001-07:002015-06-02T13:01:51.905-07:00Parallel Sorting With Multithread<span style="background-color: white; font-family: Georgia,Times New Roman,serif; font-size: 13px;"><span style="background-color: white; font-size: 13px;"><br /></span>First we must discuss what is <b><a href="https://computing.llnl.gov/tutorials/pthreads/" target="_blank">thread</a> </b>and why we use it. It means small works and can work multiple with other threads and make paralel working.</span><br />
<span style="font-family: Georgia, Times New Roman, serif;"><span style="background-color: white; font-size: 13px;"><br /></span>
<span style="background-color: white; font-size: 13px;">The important point when using thread is decide to when it should stop. You can use detach or join for it stop.<b>Detach</b>ed thread has continued to run in the backround. <b>Join </b>is a thread waiting to be completed before starting another job.</span></span><br />
<span style="font-family: Georgia, Times New Roman, serif;"><span style="color: #666666;"><span style="background-color: white; font-size: 13px;"><br /></span></span>
In this project you are asked to implement a parallel program using multi-threading: You are given an array A of N unsorted integers , and you are to sort these numbers in parallel.</span><br />
<span style="font-family: Georgia, Times New Roman, serif;"><br /></span>
<span style="font-family: Georgia, Times New Roman, serif;"><span style="background-color: white; font-size: 13px;"><br /></span>In this project you required to solve this problem with 8 threads. Each thread would be responsible for sorting exactly integers of the array as shown in following figure. For example, the first thread T1 would sort the integers in the second thread T2 would sort the integers in and so on. You would then have 8 sorted sub-arrays and you compute the overall sorted array.</span><br />
<br />
Main Thread:<br />
<br />
(1) Check command line arguments for validity. Exit in error.<br />
(2) Allocate space for N integers<br />
(3) Read the integers from the file and close the file<br />
(4) Create 8 worker threads to sort the 8 sub-arrays using qsort.<br />
(5) Start timer (use gettimeofday)<br />
(6) Wait for the termination of the worker threads<br />
(7) Stop the timer (use gettimeofday)<br />
(8) Write the sorted integers to file “sorted.dat”.<br />
(9) Print the execution time, and free up the allocated spaces<br />
<br />
<br />
<br />
<br />
<li>Parallel Sorting</li>
<br />
<pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"><code>
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <time.h>
#include <sys/time.h>
#define NUM_THREADS 8
void *worker_thread1(int *);
void *worker_thread2(int *);
void *worker_thread3(int *);
void *worker_thread4(int *);
void *worker_thread5(int *);
void *worker_thread6(int *);
void *worker_thread7(int *);
void *worker_thread8(int *);
void merge(int , int , int[] , int[], int);
int *A; // N büyüklüğünde bir char array
int base;
int *C;//big array
int k;
int i1=0, i2=0, i3=0, i4=0, i5=0, i6=0, i7=0, i8=0;
pthread_t thread1, thread2, thread3, thread4, thread5, thread6, thread7, thread8;
int compare (const void * , const void * );
int compare (const void * a, const void * b)// compare method to sort of an array
{
return ( *(int*)a - *(int*)b );
}
void* worker_thread1(int * p)// p:start q= end of array
{ //printf("**%d\n",*p);
int i=0;
qsort (&A[0], base/8, sizeof(int), compare); // make qsort the array
//thread2 nin bitmesini bekle
while(i2==0);
pthread_join(thread2, NULL);
merge(base/8,base/8,&A[0],&A[base/8],0);
int g;
for(g=0;g<2*base/8;g++)
{
A[g]=C[g]; // A da T1 ve T2 var
}
//thread3 nin bitmesini bekle
while(i3==0);
pthread_join(thread3, NULL);
merge(base/4,base/4,&A[0],&A[(2*base)/8],0);
int y;
for(y=0;y<base/2;y++)
{
A[y]=C[y]; // Artk A da T1 T2 T3 T4 var
}
//thread5 nin bitmesini bekle
while(i5==0);
pthread_join(thread5, NULL);
merge(base/2,base/2,&A[0],&A[(4*base)/8],0);// Artık Cde hepsi sıralı
i1=1;
return 0;
}
void* worker_thread2(int * p)// p:start q= end of array
{
qsort (&A[base/8], base/8, sizeof(int), compare); // make qsort the array
i2=1;
return 0;
}
void* worker_thread3(int * p)// p:start q= end of array
{
int i=(2*base)/8;
qsort (p, base/8, sizeof(int), compare); // make qsort the array
//thread4 nin bitmesini bekle
while(i4==0);
pthread_join(thread4, NULL);
merge(base/8,base/8,&A[(2*base)/8],&A[(3*base)/8],i);
int f;
for(f=2*base/8;f<4*base/8;f++)
{
A[f]=C[f];// artk a da T3 ve T4 sıralı array var
}
i3=1;
return 0;
}
void* worker_thread4(int * p)// p:start q= end of array
{
qsort (&A[(3*base)/8], base/8, sizeof(int), compare); // make qsort the array
i4=1;
return 0;
}
void* worker_thread5(int * p)// p:start q= end of array
{
int i=(4*base)/8;
qsort (p, base/8, sizeof(int), compare); // make qsort the array
//thread6 nin bitmesini bekle
while(i6==0);
pthread_join(thread6, NULL);
merge(base/8,base/8,&A[(4*base)/8],&A[(5*base)/8],i);
int h;
for(h=(4*base)/8;h<(6*base)/8;h++)
{
A[h]=C[h]; // A da T5 ve T6 var
}
//thread7 nin bitmesini bekle
while(i7==0);
pthread_join(thread7, NULL);
merge(base/4,base/4,&A[(4*base)/8],&A[(6*base)/8],(4*base)/8);
for(h=4*base/8;h<base;h++)
{
A[h]=C[h]; // A da T5 T6 T7 T8 var
}
i5=1;
return 0;
}
void* worker_thread6(int * p)// p:start q= end of array
{
qsort (&A[(5*base)/8], base/8, sizeof(int), compare); // make qsort the array
i6=1;
return 0;
}
void* worker_thread7(int * p)// p:start q= end of array
{
int i=(6*base)/8;
qsort (&A[(6*base)/8], base/8, sizeof(int), compare); // make qsort the array
//thread8 nin bitmesini bekle
while(i8==0);
pthread_join(thread8, NULL);
merge(base/8,base/8,&A[(6*base)/8],&A[(7*base)/8],i);
int h;
for(h=(6*base)/8;h<base;h++) // burada 7 ve 8 i birlestircez
{
A[h]=C[h]; // burada T7 ve T8 var
}
i7=1;
return 0;
}
void* worker_thread8(int * p)// p:start q= end of array
{
qsort (&A[(7*base)/8], base/8, sizeof(int), compare); // make qsort the array
i8=1;
return 0;
}
</code></pre>
<pre style="background-color: #eeeeee; border: 1px dashed rgb(153, 153, 153); color: black; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;">// main method</pre>
<pre style="background-color: #eeeeee; border: 1px dashed rgb(153, 153, 153); color: black; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;">
</pre>
<pre style="background-color: #eeeeee; border: 1px dashed rgb(153, 153, 153); overflow: auto; padding: 5px; width: 100%;"><span style="font-size: 12px; line-height: 14px;">int main(int argc, char *argv[])
{
struct timeval start_time,end_time;
base = (argc > 2) ? atoi(argv[1]) : -1; // convert to string to
if(base == -1){
printf("Yanlis deger girdiniz!!");
exit(0);}
A = (int *)malloc(sizeof(int)*base); // allocate space for a 100 character string
C = (int *)malloc(sizeof(int)*base);
if (A == NULL) {fputs ("Memory error",stderr); exit (2);}
FILE *fp = fopen(argv[2], "rb");
fread(A, sizeof(int), base, fp);
fclose(fp);
int r1=pthread_create(&thread1, NULL,(void *) &worker_thread1,(int *)&A[0]);
int r2=pthread_create(&thread2, NULL,(void *) &worker_thread2,(int *)&A[base/8]);
int r3=pthread_create(&thread3, NULL,(void *) &worker_thread3,(int *)&A[(2*base)/8]);
int r4=pthread_create(&thread4, NULL,(void *) &worker_thread4,(int *)&A[(3*base)/8]);
int r5=pthread_create(&thread5, NULL,(void *) &worker_thread5,(int *)&A[(4*base)/8]);
int r6=pthread_create(&thread6, NULL,(void *) &worker_thread6,(int *)&A[(5*base)/8]);
int r7=pthread_create(&thread7, NULL,(void *) &worker_thread7,(int *)&A[(6*base)/8]);
int r8=pthread_create(&thread8, NULL,(void *) &worker_thread8,(int *)&A[(7*base)/8]);
int x;
gettimeofday(&start_time,NULL); // baslangıc zamanı
//thread1 nin bitmesini bekle
while(i1==0);
pthread_join( thread1, NULL);
gettimeofday(&end_time,NULL); //bitis zamanı
FILE *fx = fopen("sorted.dat", "wb"); // sıralı diziyi dosyaya yazdır
fwrite(&C[0], sizeof(int), base, fx);
fclose(fx);
//print execution time
printf ("Execution time: %ld microseconds \n",((end_time.tv_sec *1000000 + end_time.tv_usec)-(start_time.tv_sec * 1000000 + start_time.tv_usec)));
free(A); // arraylari serbest bırak
free(C);
return 0;
}
void merge(int m, int n, int A[], int B[],int ptr) { // sıralı A ve B arrayini merge yapıp global C arrayine at
int i, j;
i = 0;
j = 0;
while (i < m && j < n) {
if (A[i] <= B[j]) {
C[ptr] = A[i];
i++;
ptr++;
} else {
C[ptr] = B[j];
j++;
ptr++;
}
}
while(i<m && j>=n){
C[ptr] = A[i];
i++;
ptr++;
}
while(j<n && i>=m){
C[ptr] = B[j];
j++;
ptr++;
}
}</span><span style="color: black; font-size: 12px; line-height: 14px;">
</span></pre>
<div>
<br /></div>
Arzu Türkmenhttp://www.blogger.com/profile/11385315485221708959noreply@blogger.com0