Here you can find sample code, parts of programs, software tricks and ways to optimize code. Articles are shown parts of the codes used in our projects. If someone wishes can use the free parts of code. We welcome your comments on various articles, solutions and improvements to the proposed code.

Read entry from directory handle

June 21st, 2009 wiley No comments

Howto read entry from directory handle.
In my QCube project i use php readdir function to read all i18n languages files.
Foreach language file, i create one button with label of current language and an Action to change current language on my site.

// function to check all i18n language files
protected function  agregateLanguage(){
$i = 0;
if ($handle = opendir(__QCUBED__ . '/i18n')){
while (false !== ($file = readdir($handle))){
$filearr = explode('.',$file);
if (end($filearr) === 'po'){
$this->btnLang[$i] = new QButton($this);
$this->btnLang[$i]->Text = $filearr[0];
$this->btnLang[$i]->ActionParameter = $filearr[0];
$this->btnLang[$i++]->AddAction(new QClickEvent(), new  QAjaxAction('btnLang_Click'));
}
}
}
}

// Function to change current language on my site
public function btnLang_Click($strFormId, $strControlId, $strParameter){
$_SESSION['language_code'] = $strParameter;
QApplication::Redirect('');
}

This code is used QCube my project but can be used with some changes for other php scripts.


Unique visitors to post: 2

Categories: PHP, QCube Tags: , ,

MySQL LIMIT Clause

June 19th, 2009 wiley No comments

The LIMIT clause can be used to constrain the number of rows returned by the SELECT statement. LIMIT takes one or two numeric arguments, which must both be nonnegative integer constants.

With one argument:

SELECT * FROM tbl LIMIT 10;     # Retrieve first 10 rows

With one argument, the value specifies the number of rows to return from the beginning of the result set.

With two arguments:

SELECT * FROM tbl LIMIT 2,20;  # Retrieve rows from 3 to 22

With two arguments, the first argument specifies the offset of the first row to return, and the second specifies the maximum number of rows to return. The offset of the initial row is 0 (not 1).


Unique visitors to post: 11

Categories: MySQL Tags: ,

Find remote user hostname

June 18th, 2009 wiley No comments

I used c# code like this to find the remote user hostname and address:

string userHostAddress = "";
userHostAddress = Request.UserHostAddress + " -- " + Request.UserHostName;

Unique visitors to post: 5

Categories: ASP Tags: , ,

Xerox PE220 tech mode

June 16th, 2009 wiley No comments

To input Tech mode press:

MENU # 1934


Unique visitors to post: 11

What development tools you prefered

June 7th, 2009 wiley No comments


Unique visitors to post: 0

Categories: utils Tags: ,

How to obtain current directory

June 5th, 2009 wiley No comments

C# how to obtain current direntory of the executing process:

System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
[/c-sharp]


Unique visitors to post: 0

Categories: C#, utils Tags: ,

Change cell formatting on DataGridView

June 4th, 2009 wiley No comments

How to change the visual presentation of the scope of DataGridView. If in a particular field of the table in the database have such a unix timestamp value like visualizing it as a standard date and time. Add EventHandler CellFormating for the DataGridView.

private void dgvActiveUsers_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
  try
  {
    if (dgvActiveUsers.Columns[e.ColumnIndex].Name.Equals("logindate"))
    {
      DateTime origin = new DateTime(1970, 1, 1, 0, 0, 0, 0);
      e.Value = origin.AddSeconds(double.Parse(e.Value.ToString())).ToShortDateString() + " - " + origin.AddSeconds(double.Parse(e.Value.ToString())).ToShortTimeString();
     }
   }
   catch (Exception)
   {
   }
}

This method can give an idea and many other types of formatting values.


Unique visitors to post: 5

Categories: C# Tags: , ,

Programaticaly opening folder

June 3rd, 2009 wiley No comments

A method to programaticaly opening folder with explorer:

string folderToOpen = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + @"\archive";
string windir = Environment.GetEnvironmentVariable("SystemRoot");
System.Diagnostics.Process proccess = new System.Diagnostics.Process();
proccess.StartInfo.FileName = windir + @"\explorer.exe";
proccess.StartInfo.Arguments = folderToOpen;
proccess.Start();
[/c-sharp]

String variable folderToOpen contains path to “archive” folder under this folder in which the program works.
proccess.StartInfo.FileName contains path to “windows explorep”.


Unique visitors to post: 0

Categories: C#, utils Tags: , ,

Create ZIP file

May 29th, 2009 wiley No comments

A class to create ZIP file from another file.
This class uses the free C# ZIP library (http://www.icsharpcode.net/OpenSource/SharpZipLib/Download.aspx) is great for reading and creating ZIP files.
The parameter source is full path to source file.
The parameter destination is full path to destination result zip file.

using System;
using System.IO;
using ICSharpCode.SharpZipLib.Checksums;
using ICSharpCode.SharpZipLib.Zip;

namespace Tools
{
  public class Zip
  {
   public static void create(string source, string destination, string comment)
    {
      Crc32 crc = new Crc32();
      ZipOutputStream s = new ZipOutputStream(File.Create(@destination));
      s.SetLevel(9); // 0 - store only to 9 - means best compression
      FileStream fs = File.OpenRead(@source);
      byte[] buffer = new byte[fs.Length];
      fs.Read(buffer, 0, buffer.Length);
      ZipEntry entry = new ZipEntry(ZipEntry.CleanName(@source));
      entry.DateTime = DateTime.Now;
      entry.Comment = comment;
      entry.ZipFileIndex = 1;
      entry.Size = fs.Length;
      fs.Close();
      crc.Reset();
      crc.Update(buffer);
      entry.Crc = crc.Value;
      s.PutNextEntry(entry);
      s.Write(buffer, 0, buffer.Length);
      s.Finish();
      s.Close();
    }
  }
}

Unique visitors to post: 4

Categories: C#, utils Tags: ,

Execute batch file

May 29th, 2009 wiley No comments

A function to executing the batch file from C#
The value of the first argument [batchFileName] is full path to batch file.
The value of the second argument [argumentsToBatchFile] is array of argument if exist, sending to batch file.

protected bool ExecuteBatchFile(string batchFileName, string[] argumentsToBatchFile)
{
string argumentsString = string.Empty;
try
{
if (argumentsToBatchFile != null)
{
for (int count = 0; count < argumentsToBatchFile.Length; count++)
{
argumentsString += " ";
argumentsString += argumentsToBatchFile[count];
}
}

System.Diagnostics.ProcessStartInfo DBProcessStartInfo = new  System.Diagnostics.ProcessStartInfo(batchFileName, argumentsString);

DBProcessStartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
DBProcessStartInfo.UseShellExecute = true;

System.Diagnostics.Process dbProcess;
dbProcess = System.Diagnostics.Process.Start(DBProcessStartInfo);

while (!dbProcess.HasExited)
dbProcess.WaitForExit(2000);

return true;
}
catch (SqlException ex)
{
MessageBox.Show(ex.Message);
return false;
}
}

Unique visitors to post: 2

Categories: C#, utils Tags: , , ,
Google Analytics integration offered by Wordpress Google Analytics Plugin