Skip to content

Instantly share code, notes, and snippets.

View longtth's full-sized avatar

Long NguyenX longtth

View GitHub Profile
foreach (string folder in folders)
{
Check1Folder(ref totalFiles, ref totalError, folder);
}
private void Check1Folder(ref int totalFiles, ref int totalError, string folder)
{
string[] files = Directory.GetFiles(folder,"*.txt");
totalFiles += files.Length;
foreach (string file in files)
@longtth
longtth / RandomEnum.cs
Created June 10, 2018 10:15
Get an random value from enum
static T RandomEnumValue<T> ()
{
var v = Enum.GetValues (typeof (T));
return (T) v.GetValue (new Random ().Next(v.Length));
}
//-------------------------------------------
//Test:
for (int i = 0; i < 10; i++) {
var value = RandomEnumValue<System.DayOfWeek> ();
Console.WriteLine (value.ToString ());
foreach (KeyValuePair<string, string> entry in parameters)
{
sc.Parameters.AddWithValue(entry.Key, entry.Value);
}
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using ClosedXML.Excel;
using DataEntryDAL;
namespace DataEntryDAL.DAO
{
public class ReportDAO
@echo OFF
REM FOR /F "TOKENS=1-4 DELIMS=/ " %%A IN ('DATE/T') DO SET tg=%%D%%B%%C
REM set tg=%date:/=%
SET Today=%Date: =0%
SET Year=%Today:~-4%
SET Month=%Today:~-10,2%
SET Day=%Today:~-7,2%
SET tg=%Year%%Month%%Day%
/// <summary>
/// Determines a text file's encoding by analyzing its byte order mark (BOM).
/// Defaults to ASCII when detection of the text file's endianness fails.
/// </summary>
/// <param name="filename">The text file to analyze.</param>
/// <returns>The detected encoding.</returns>
public static Encoding GetEncoding(string filename)
{
// Read the BOM
var bom = new byte[4];
@longtth
longtth / TextToImage.cs
Created July 1, 2018 08:51 — forked from naveedmurtuza/TextToImage.cs
Converting text to image (png) C#
/// <summary>
/// Converting text to image (png).
/// </summary>
/// <param name="text">text to convert</param>
/// <param name="font">Font to use</param>
/// <param name="textColor">text color</param>
/// <param name="maxWidth">max width of the image</param>
/// <param name="path">path to save the image</param>
public static void DrawText(String text, Font font, Color textColor,int maxWidth,String path)
{
string[] array = new string[2]; // creates array of length 2, default values
string[] array = new string[] { "A", "B" }; // creates populated array of length 2
string[] array = { "A" , "B" }; // creates populated array of length 2
string[] array = new[] { "A", "B" }; // created populated array of length 2
@longtth
longtth / StringExtension.cs
Last active July 1, 2018 15:18
1 cái Extension Method để extend cái class String, vẫn chép từ SO
// You can use an extension method:
public static class StringExtension
{
public static string GetLast(this string source, int tail_length)
{
if(tail_length >= source.Length)
return source;
return source.Substring(source.Length - tail_length);
}
@longtth
longtth / DataGridViewLoopCell.cs
Created July 5, 2018 02:30
Chạy qua tất cả các cell trong GridView để xử lý với nó.
foreach(DataGridViewRow row in yourDataGridView.Rows)
{
foreach(DataGridViewCell cell in row.Cells)
{
//do operations with cell
}
}