Showing posts from April, 2012

IIS, DLL and Exhange

Catch Enter on ASP Form example

1st thing u must know - u cant do it directly like any other controls.OnTextChange
therefor the good lord gave us JS!
put this script on:
   document.onkeypress = function() {
if (window.event.keyCode==13){
          alert(window.event.keyCode); //to see that it works

This on the aspx page :

and on the cs page:
protectedvoid Page_Load(object sender, EventArgs e)
    if (Hidden1.Value == "true")
TextBox1.Text = "We Got an Enter to the Server Side";
         TextBox1.Text = "just a page load, no enter";
//put a TextBox with width 300, run the page and press enter :)

Access: Call a Func from another Form with example

the main points are:
1 - make the func public (daa but we forget) and "As Variant"
2 - actualy find the damn form and how to call the func
when u have that u have it (double daa)
and for the example
call a func in a subform from the main form
the func:
Public Function Call_payment_date_AfterUpdate() As Variant
End Function
from the main form (in a func o/c)
Forms!ei_main_form![ei_purchase subsubform].Form.Call_payment_date_AfterUpdate

from a stand alone form call a func in another form
the func
Public Function Call_Refresh_From_ei_main() As Variant    Me.Refresh
End Function
the call

תקשורת על גבי רשת האינטרנט מאת ALEXSUH

כל התודות לאלכס מפורום תפוז שהשקיע בנו כ"כ, הכל מועתק ללא שינוי

מה שאתה מדבר עליו נקרא פרוטוקול SOAP לתקשורת על גבי רשת האינטרנט.
זה פרוטוקול מקובל בד"כ אם אתה שולט הן בצד השרת וצד הלקוח .
סיומת ASMX מקובלת במימוש הפרוטוקול על גבי שרתי MISCROSOFT מסוג ASP.NET אך הפוטוקול אינו ייחודי ל MIcrosoft וניתן לשתמש בכל סיומת כל עוד עומדים בתקנים של הפרוטוקול.
בעולם האמיתי לא תמיד ניתן לקבל שירות נוח של קליק וגמרנו ומדי פעם צריך לבצע קצת עבודה ע"מ לקבל את הנתונים.
במקרה הנ"ל אין מדובר בשרות מסוג SOAP אלא בקובץ XML רגיל אשר מתעדכן אחת לכמה זמן (לדעתי פעמיים שלוש ביום) וניתן להורדה ישירה תוך שימוש בפרוטוקול HTTP רגיל.

קצת רקע
עוד מידע על לפרוטוקול SOAP

פרוטוקול HTTP עליו פרוטוקול SOAP מבוסס

פרוטוקולים נוספים המבוססים על HTTP
XML-RPC (המיושן אך עדיין נפוץ בפינות נשכחות של האינטרנט)


Ajax Image Asp example

1st we need a source to return a requested img, i'll use an ASP page like this (ASPX part doesnt matter, u may not touch it), lets call it ReturnPic.aspx
protectedvoid Page_Load(object sender, EventArgs e)
    System.Drawing.Image img = System.Drawing.Image.FromFile(         Request.QueryString["file"].ToString());
    //u have to use the system.drawing or ull get the we.ui.image    string ext = Path.GetExtension(Request.QueryString["file"].ToString());
    if (ext == "jpg")
ext = "jpeg";
   *MemoryStream ms = newMemoryStream();
    img.Save(ms, System.Drawing.Imaging.
byte[] content = ms.ToArray();
Response.ContentType = "image/" + ext;
u can always use ImageConverter

now here is my default page, i used 2 method to return the pic by ajax, one with UpdatePanel and the other with WebMethod both explained in my po…

Linq Vs Mysql

the answer - mysql (and i guess any sql kind) is about 500-1000 times faster
BUT, yes we have a HUGE but - this is only for the query time the SQL query himself from the DB.
then we have transportation - there, the bigger the data requested is the more u might be better using Linq, AND we have a BUT here too - Linq depends on ur computer resources so...

anyway on my job's machine i did a query from a table with 300K+ rows.
when the answer was less than 100 rows the mysql was that fast.
when i tried something with 60k+ rows and another with 250K rows the Linq became 60%+ faster.
*!this does not include the initial query of all the 300K lines

Soooo...   for me it means that if i am gonna query something alot it might be better a Linq or even 2 querys on something with 60K+ rows

on 4K they r the same
20K Linq is faster by about 20%+
again my machine my router speed...

my conclusion:
*Linq is better when u query at least 3-5 times and more AND were talking about 10K+ rows a que…

DataSource a Linq(ed) DataTable example

if u ever tried to query with Linq a datatable and then assign it to a DataGridView (and other stuff i guess) then u might have noticed that the grid shows the properties of the DataRow(s).
And if you tried to select the ItemArray, again a mess.
Sooo... its so simple i laugh at myself but i must:

var query =
from data in tblAllData.AsEnumerable()
where data.Field<DateTime>("Start").Month == (int)cmbMonths.SelectedValue
select data;
if (query.Count() > 0)
    dgvMain.DataSource = query.CopyToDataTable();


Winforms ComboBox Text & Value example

the really simple way, and goes for the rest of the winform controls
you could also put a list of any class and choose 2 properties

DataTable tblMonths = newDataTable();
tblMonths.Columns.Add(newDataColumn("Name", typeof(string)));
tblMonths.Columns.Add(newDataColumn("Value", typeof(int)));
for (int i = 1; i <= 12; i++)
string month = DateTimeFormatInfo.CurrentInfo.GetMonthName(i);
    newobject[] { month, i });
cmbMonths.DataSource = tblMonths;
cmbMonths.ValueMember = "Value";
cmbMonths.DisplayMember = "Name";
cmbMonths.SelectedValue =

mysql Count the Distinct example

I want select like this:
ari     3
dani  1
SELECT   my_column,
COUNT(*)AS num
FROM my_table
GROUPBY  my_column
thanks stack overflow

WinForms Bypass Cross Thread Update Error example

we can do 2 things
the 1st, not everybody loves it (and i guess that in large slns  u should avoid it) is the
CheckForIllegalCrossThreadCalls  prop:.

public Form1()
{     InitializeComponent();
Form1.CheckForIllegalCrossThreadCalls = false;
privatevoid button1_Click(object sender, EventArgs e)
Thread t = newThread(newThreadStart(target));
privatevoid target()
this.Text = "ddddd";

the other way is to use a delegate:

delegate voidSetTextCallback(string text);
privatevoid SetText(string text)
// InvokeRequired required compares the thread ID of the
// calling thread to the thread ID of the creating thread.
// If these threads are different, it returns true.
if (this.textBox1.InvokeRequired)
      SetTextCallback d = newSetTextCallback(SetText);
this.Invoke(d, newobject[] { text });
this.textBox1.Text = textBox1.Text + text;
p.s. - thanks to rabi dot net and stack overflow

Ease of WebRequest example

this is and example of a generic method to execute POST WebRequests, and in this case login into a site, don't worry, the values are fake.

the 1st part is a secondary example, how to call MakeWebRequest method itself, which is the main thing in this post.

System.Collections.Specialized; - ns for NameValueCollection
NameValueCollection parameters = newNameValueCollection();
parameters.Add("textBox1", "422");
parameters.Add("textBox2", "gensearch");
parameters.Add("textBoxUserName", "UserName");
parameters.Add("textBoxPassword", "mode matchallpartial");
string strRes = "";
string url = "\jsp\php\ect.";
CookieContainer cookie = newCookieContainer();

MakeWebRequest(url, "POST", ref cookie, parameters, ref strRes);
//and strRes is our response, either html or csv or whatever the resposne is
//if you dont send any params then parameter…

Paralel Events example

So you wanna have 2 events running at the same time (parallel)?
nope - they will run as a stack, we need , threads!
so typically I would recommend using the TPL library but sometimes its not exactly what you need, and sometimes you work with .Net 3.5.

If we just start new thread in WinForms we also get cross trread exception... - this is solved with delegates!

Here is my code for 2 textboxes with doubleClick event to write to a 3rd textbox, 1st textbox by an event, the other textbox by a thread.

note that the event are still in a stack although they get a different class.
the threads should work without a class but this is a pattern for "heavier" work:

publicpartialclassEventer : Form
int id = 10;
     public Eventer()

privatevoid txtEnter_DoubleClick(object sender, EventArgs e)
cWriter cw = newcWriter(id++);
         cw.SendBack += newcWriter.BackToTextBox(cw_SendBack);

Ajax - the 3 simple ways example

the most easy way to do ajax, if you're developing with .Net, is to use the AjaxUpdatePanel. tp use it you must add a script manager to your page, preferred in you master page if you have one, and from there on all your standard logic and fields and whatever inside the Content Template

<asp:ScriptManagerID="ScriptManager1"runat="server"> </asp:ScriptManager>
 <!-- html tags -->
      <%-- server tags --%>