WCF – VB.NET – Envoyer / uploader un fichier en WCF

WEB.Config :

<?xml version=”1.0″ encoding=”utf-8″?>

<!–
Pour plus d’informations sur la configuration de votre application ASP.NET, consultez
http://go.microsoft.com/fwlink/?LinkId=169433
–>

<configuration>
<system.web>
<compilation debug=”true” strict=”false” explicit=”true” targetFramework=”4.0″ />
<httpModules>
<add name=”ApplicationInsightsWebTracking” type=”Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web” />
</httpModules>
<!– ajouté–>
<httpRuntime executionTimeout=”90″ maxRequestLength=”1000000000″ />

</system.web>
<system.webServer>

<!– ajouté–>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength=”2147483648″ />
</requestFiltering>
</security>

<validation validateIntegratedModeConfiguration=”false” />
<modules>
<remove name=”ApplicationInsightsWebTracking” />
<add name=”ApplicationInsightsWebTracking” type=”Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web” preCondition=”managedHandler” />
</modules>
</system.webServer>

<runtime>

<assemblyBinding xmlns=”urn:schemas-microsoft-com:asm.v1″>
<dependentAssembly>
<assemblyIdentity name=”System.Runtime” publicKeyToken=”b03f5f7f11d50a3a” culture=”neutral” />
<bindingRedirect oldVersion=”0.0.0.0-2.6.8.0″ newVersion=”2.6.8.0″ />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name=”System.Threading.Tasks” publicKeyToken=”b03f5f7f11d50a3a” culture=”neutral” />
<bindingRedirect oldVersion=”0.0.0.0-2.6.8.0″ newVersion=”2.6.8.0″ />
</dependentAssembly>
</assemblyBinding>

</runtime>

<system.serviceModel>
<!– ajouté–>
<bindings    >
<basicHttpBinding  >
<binding   transferMode=”Streamed”  maxReceivedMessageSize=”2147483647″ maxBufferSize=”2147483647″ maxBufferPoolSize=”2147483647″>
<readerQuotas maxDepth=”64″ maxArrayLength=”2147483647″ maxStringContentLength=”2147483647″/>
</binding>
</basicHttpBinding>
</bindings>

<behaviors>
<serviceBehaviors   >
<behavior name=””   >
<serviceMetadata httpGetEnabled=”true”       />
<serviceDebug includeExceptionDetailInFaults=”false”       />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled=”true”      />
</system.serviceModel>
</configuration>

 

Interface du wcf :
<OperationContract()>
Sub setExe(ByVal fichierStream As Stream)

Source .VB du wcf : 

Public Sub setExe(fichier As Stream) Implements ISvcCyrus.setExe
Dim fileStream = New FileStream(“\\data\CyrusApplication\developpement\maj\Cyrus2.exe”, FileMode.Create, FileAccess.Write)
fichier.CopyTo(fileStream)
fileStream.Dispose()
End Sub

Client  pour envoyer le fichier :

Dim service As New ServiceReference1.MonServiceClient
service.Endpoint.Address = New ServiceModel.EndpointAddress(“http://x.x.x.x/monService.svc&#8221;)

Dim stream As FileStream = File.OpenRead(cheminFichier)
service.setExe(stream)
 

VB.NET – Masque de saisie de date dans un datagridview en winform

Sub New()

‘ Cet appel est requis par le concepteur.
InitializeComponent()

Dim dt As New DataTable
dt.Columns.Add(“a”)
dt.Columns.Add(“Date”)

Dim dr1 As DataRow = dt.NewRow
dr1.Item(“Date”) = “10/03/2013”
Dim dr2 As DataRow = dt.NewRow
dr2.Item(“Date”) = “10/03/2013”

dt.Rows.Add(dr1)
dt.Rows.Add(dr2)

MDataGridView1.DataSource = dt
afficheDataGrid(MDataGridView10, False)

maskedTextBox2 = New MaskedTextBox
With maskedTextBox2
.Mask = “00/00/0000”
.Visible = False
End With
MDataGridView10.Controls.Add(maskedTextBox2)

End Sub

Const nomColonne As String = “Date”
Private WithEvents maskedTextBox2 As MaskedTextBox

Private Sub MyDataGridView1_CellBeginEdit(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellCancelEventArgs) Handles MDataGridView10.CellBeginEdit
If (Me.MDataGridView10.Columns(e.ColumnIndex).Name = nomColonne) Then
Dim rect2 As Rectangle = Me.MDataGridView10.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, True)
Me.maskedTextBox2.Size = rect2.Size
Me.maskedTextBox2.Location = rect2.Location
If (Me.MDataGridView10.CurrentCell.Value IsNot Nothing) Then
Me.maskedTextBox2.Text = Me.MDataGridView10.CurrentCell.FormattedValue.ToString()
End If
Me.maskedTextBox2.Visible = True
End If
End Sub

Private Sub MyDataGridView1_CellEndEdit(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles MDataGridView10.CellEndEdit
If (Me.MDataGridView10.Columns(e.ColumnIndex).Name = nomColonne) Then
Me.MDataGridView10.CurrentCell.Value = maskedTextBox2.Text
Me.maskedTextBox2.Visible = False
End If
End Sub

Private IsHandleAdded2 As Boolean

Private Sub MyDataGridView1_EditingControlShowing(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles MDataGridView10.EditingControlShowing
If Not IsHandleAdded2 And (Me.MDataGridView10.Columns(Me.MDataGridView10.CurrentCell.ColumnIndex).Name = nomColonne) Then
Dim tx As TextBox = CType(e.Control, TextBox)
AddHandler tx.KeyPress, AddressOf Me.tx_KeyPress
IsHandleAdded2 = True
End If
End Sub

Private Sub tx_KeyPress(ByVal sender As Object, ByVal e As KeyPressEventArgs)
If (Me.MDataGridView10.Columns(Me.MDataGridView10.CurrentCell.ColumnIndex).Name = nomColonne) Then
e.Handled = True
Me.maskedTextBox2.Focus()
If (Char.IsNumber(e.KeyChar)) Then
Me.maskedTextBox2.Text = e.KeyChar.ToString()
Else
Me.maskedTextBox2.SelectAll()
End If
End If
End Sub

VB.NET – Multi Thread

Background worker :

If not bw.IsBusy Then
bw.RunWorkerAsync()
End If

Friend WithEvents bw As New System.ComponentModel.BackgroundWorker

Private Sub bw_DoWork(sender As System.Object, e As System.ComponentModel.DoWorkEventArgs) Handles bw.DoWork
End Sub

Private Sub bw_RunWorkerCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles bw.RunWorkerCompleted

Dim mForm As New Form1()
mForm.BringToFront()
mForm.TopMost = True
mForm.Owner = Me
mForm.Show()

End Sub

 

Delegate :

Dim deleg1 As SomeWorkDelegate = New SomeWorkDelegate(AddressOf AfficherDelegate)
FaireDelegate(deleg1)

Public Delegate Sub SomeWorkDelegate(ByVal strSomeString As String)

Sub AfficherDelegate()
End Sub

Public Sub FaireDelegate(ByVal someDelegateFunc As SomeWorkDelegate)
Dim mFormChrono As New TempsPasse()
mFormChrono.BringToFront()
mFormChrono.TopMost = True
mFormChrono.Owner = Me
mFormChrono.Show()
End Sub

 

VB.NET – Liste déroulante dans un datagrid, problème plusieurs cliques

 

Sur l’événement CellClick du datagrid :

 

dg.BeginEdit(True)

If dg.Rows(e.RowIndex).Cells(“NomDeLaCOlonne”).Selected = True Then

If dg.EditingControl IsNot Nothing Then

If dg.EditingControl.ToString().Contains(“System.Windows.Forms.DataGridViewComboBoxEditingControl”) Then

DirectCast(dg.EditingControl, DataGridViewComboBoxEditingControl).DroppedDown = True

End If

End If

End If

Python – Débuter – Les bases

# -*- coding:Latin-1 -*-

n = 7

msg = coucou

#une boucle while

a=0

while(a<5):

a = a + 1

#une condition if

if a == 2 :

print(tu es arrivé a : “ , a)

print(a)

print(“\n”)

#len() retourne la longueur de la chaine de caractère

print(print(le mot \”fini\” contient, len(fini), caractères.”))

#un tableau

jour = [lundi, mardi, mercredi, 1800, 20.357, jeudi, vendredi]

print(jour, “\n”)

#boucle for d’un tableau d’objet

for i in jour:

print(str(i))

 

Python – Débuter avec le mode graphique / form / GUI

Création d’une fenêtre qui en ouvre une autre grâce à l’appel d’un classe

—————– PROGRAMME PRINCIPALE ——————-

Créer _main.py

from tkinter import *

from fenetre2 import *

#cree la fenetre principale

_main = Tk()

_main.geometry(‘1000×700’)

#cree les controles (bouton, label, textbox ..)

lb1 = Label(_main, text =mon champ :’)

tb1 = Entry(_main)

btnOuvrir = Button(_main, text=ouvrir, command=fenetre2().initFenetre )

btnFermer = Button(_main, text=Fermer, command=_main.destroy )

#position les controles sur la grid

lb1.grid(row =2, sticky = E)

tb1.grid(row =2, column = 2 )

btnOuvrir.grid(row=0, column = 0)

btnFermer.grid(row=0, column = 1)

#demarre le programme

_main.mainloop()

 

—————–CLASSE DE LA FENETRE 2——————-

Créer fenetre2.py

from tkinter import *

class fenetre2():

#Fonction d’initialisation de la fenêtre

def initFenetre(self):

_fenetre2 = Tk()

_fenetre2.geometry(‘400×400’)

VB.NET – fonction de séparateur de millier sur le Leave malgré la région

Function separateurDeMillier(entree As String) As String

Dim al As New ArrayList

For Each s In entree

al.Add(s)

Next

Dim resultat As String = “”

Dim count As Integer = 0

For i = al.Count – 1 To 0 Step -1

resultat = resultat.Insert(0, al(i))

If al(i) <> “,” And al(i) <> “.” Then

Select Case count

Case 3

resultat = resultat.Insert(0, ” “)

count = 0

End Select

Else

count = 0

End If

If count <= 3 Then

count += 1

End If

Next

Return resultat

End Function

VB.NET – Créer une instance / classe depuis son nom

Dim mUserControl As UserControl = Nothing

If mExist = False Then

mUserControl = New UserControl

Dim mUserControlName As String = “nomSolution.nomClasse”

Dim T As Type = Type.GetType(mUserControlName, False, True)

Dim pParam As New Object

pParam = New Object() {mParent, mParent.getIdAffaire, mParent.getConn}

mUserControl = CType(Activator.CreateInstance(T, pParam), Object)