Monday

vba code samples for outlook



Sub AssignCategoryAndMoveBasedOnSubject(Item As Outlook.MailItem)
If InStr(1, Item.Subject, "error") > 0 Then
Item.Categories = "Error"
Item.Subject = "Error:" + Item.Subject
Item.Save

Set myNameSpace = GetNamespace("MAPI")
Set myInBox = myNameSpace.GetDefaultFolder(olFolderInbox)
Set mydestFolder = FindOrCreateFolder(myInBox, "Text")
Item.Move mydestFolder
End If
End Sub


Function FindOrCreateFolder(inputFolder As Variant, folderName As String) As Outlook.MAPIFolder
Dim curFolder As Outlook.MAPIFolder
For Each curFolder In inputFolder.Folders
If folderName = curFolder.Name Then
Set FindOrCreateFolder = curFolder
Exit Function
End If
Next curFolder
Set FindOrCreateFolder = inputFolder.Folders.Add(folderName)
End Function

more...

vba code : access sql server from outlook



'Access SQL server from oputlook
Sub AccessSQLServer(Item As Outlook.MailItem)
Set con = CreateObject("ADODB.Connection")
con.Open "driver={SQL Server};Uid=sa;server=myserv;pwd=mypass;database=mydb;"
Set rs = CreateObject("ADODB.Recordset")
rs.ActiveConnection = con
rs.Open "SELECT * FROM MyTable"
Do While Not rs.EOF
MsgBox rs("id")
rs.MoveNext
Loop
End Sub


more...

Friday

C#(csharp) how to resize array (shrink) by Array.Copy

 

/// <summary>
/// Emails addresses creating.
/// </summary>
/// <param name="incom">The incoming array</param>
/// <returns></returns>
private EmailAddressType[] EmailAddressCreate(string[] incom) {
if (incom == null) return null;
EmailAddressType[] ret = new EmailAddressType[incom.Length];
EmailAddressType[] rt;
int i = 0;
foreach (string s in incom) {
if (!string.IsNullOrEmpty(s))
{
ret[i] = new EmailAddressType();
ret[i].EmailAddress = s;
i++;
}
}
// change size of array
if (i < incom.Length)
{
rt = new EmailAddressType[incom.Length];
Array.Copy(rt, ret, i);
}else
{
rt=ret;
}

return rt;
}

more...

Sunday

ASP.NET uploading files directly to a SQL database in C#

asp-page-source
 <form id="form1" runat="server">
Please upload file:<br />
<asp:Literal ID="lit_Status" runat="server" /><br />
<b>Name:</b>
<asp:TextBox ID="FileName" runat="server" />
<br />
<b>File:</b>
<asp:FileUpload ID="FileToUpload" runat="server" />
<br />
<asp:Button ID="btn_Upload" runat="server" Text="Upload" onclick="btn_Upload_Click" />
</form>


Code-behind source
 using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Data.SqlClient;
using System.Configuration;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}

protected void btn_Upload_Click(object sender, EventArgs e)
{
if (FileToUpload.PostedFile == null || String.IsNullOrEmpty(FileToUpload.PostedFile.FileName) || FileToUpload.PostedFile.InputStream == null)
{
lit_Status.Text = "
Error - unable to upload file. Please try again.
";
}
else
{
using (SqlConnection Conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString))
{
try
{
const string SQL = "INSERT INTO [BinaryTable] ([FileName], [DateTimeUploaded], [MIME], [BinaryData]) VALUES (@FileName, @DateTimeUploaded, @MIME, @BinaryData)";
SqlCommand cmd = new SqlCommand(SQL, Conn);
cmd.Parameters.AddWithValue("@FileName", FileName.Text.Trim());
cmd.Parameters.AddWithValue("@MIME", FileToUpload.PostedFile.ContentType);

byte[] imageBytes = new byte[FileToUpload.PostedFile.InputStream.Length + 1];
FileToUpload.PostedFile.InputStream.Read(imageBytes, 0, imageBytes.Length);
cmd.Parameters.AddWithValue("@BinaryData", imageBytes);
cmd.Parameters.AddWithValue("@DateTimeUploaded", DateTime.Now);

Conn.Open();
cmd.ExecuteNonQuery();
lit_Status.Text = "
File successfully uploaded - thank you.
";
Conn.Close();
}
catch
{
Conn.Close();
}
}
}
}
}



more...

howto put file into varbinary (OPENROWSET,BULK,SINGLE_BLOB) on MS SQLServer


CREATE TABLE [cmp].[tblCMPEmailAttachements](
[AttachmentID] [int] IDENTITY(1,1) NOT NULL,
[EmailID] [int] NOT NULL,
[FileName] [nvarchar](50) NULL,
[CreatedDate] [datetime] NULL,
[FileBody] [varbinary](max) NULL
) ON [PRIMARY]



Declare @attID int
Insert into cmp.tblCMPEmailAttachements (EmailID,FileName,CreatedDate) values (1,'1.gif',GETDATE())
SET @attID = SCOPE_IDENTITY();
update cmp.tblCMPEmailAttachements set
[FileBody] = (SELECT * FROM OPENROWSET(BULK 'C:\1.gif', SINGLE_BLOB)AS [FileBody] ) WHERE AttachmentID=@attID

more...

Monday

android links

http://code.google.com/p/andro… - Android Scripting Environment brings scripting languages to Android.
http://developer.motorola.com/… - Motorola Developer Studio
http://eclipse.org/ - Eclipse, open development platform
http://developer.android.com/s… - Google Android SDK
http://androidforums.ru/ - русское сообщество ОС Android. Форум по Android
http://www.quattrowireless.com… и http://www.smaato.com/ - размещение рекламы на мобильных устройствах
http://slideme.org/ - альтернативный распространитель ПО

Вдогонку: http://sites.google.com/site/o… - пишем Hello World.

Thursday

Gvim editor new tips



da< - Delete the HTML tag the cursor is currently inside of the whole tag, regardless of just where the cursor is.
ci" -Change the content of a doublequote-delimited string.

da[ - Delete the [] region around your cursor
vi' - Visual select everything inside '' string
ya( - Yank all text from ( to )

See :help text-objects.

:e! - Reopen the current file, getting rid of any unsaved changes
gg=G - AMAZING If you're coding, gg will bring you to the top of the file, and =G will auto indent (=) everything to the bottom of the file (G)
gq - reset the entire selection to be wrapped correctly.
=% - Indents the block between two braces/#ifdefs
== - Indents current line
d% - delete till parrent - cursor can be not on opening tag
ft - move to the next occurrence of t and
tt - to move to the char before t

Macros are stored in registers, these are the same registers that can be used
for copy paste. So say you record a macro to register q you can paste it into a
document with "qp, edit it, then select it and cut it back into the register
with "qd.




more...

ГК стадии

стадии
0 - реклама. Для вас ничего не поменяется.
I - LC. Для вас ничего не меняется, кроме возможности продления H-1 за пределы 6 лет.
II - I-140 - Аналогично но начинаете указывать им намерения в анкете ну и по прежнему можете продлевать H-1. Если 140 аппрувлена но категория EB-3 (бакалавр) то продлевать можете сразу на 3 года за пределы 6-ти лет
III - I-485 (+ AP + EAD) - получаете нормальный документ для выезда (AP) и нормальный документ для внутренних нужд (EAD). Жена и дети получают возможность работать и иметь SSN.
III + 6 месяцев - можно менять работу.
ГК - не нужно больше суетиться и дети могут получать федеральную помошь на учебу и федеральные кредиты на учебу.

Если категория визы EB-2 или EB-1 то стадии II и III файлятся (все еще?) одновременно. Если EB-3 то между ними будет года 3 ожидания (все у того же работодателя и на визе).


Все правильно кроме, пожалуй, последнего. Время между непредсказуемо в случае Еб-3 - сейчас срок 7 лет исходя из бюллетеня, данные УСЦИС неполные и противоречивые, бэклог они посчитать не могут.


Дело в том, что начиная с 2006 года примерно поток EB-3 резко иссяк. И движение по оным годам будет очень нелинейным. Хотя... полный срок плавал от 2 до 5-ти лет, исходя из этого - срок по EB-3 вряд ли уедет за больше 6 - 7 лет (причем этот срок считается с подачи LC а не с подачи I-140, то есть если сейчас начнут, то и срок начнет отсчитываться), и вряд ли станет меньше 2 - 3 лет (сразу толпы набегут)...


imagemagic add text to image

rem different types of text annotations on existing images rem cyan yellow orange gold rem -gravity SouthWest rem draw text and anno...