Example #1
0
        public static void ComboFill(string SSql, ComboBox aList, ref OleDbConnection ConSql)
        {
            OleDbDataReader LeRs;
            ArrayList       LaListe = new ArrayList();

            aList.DataSource = null;
            aList.Items.Clear();
            LeRs = SqlLit(SSql, ref ConSql);
            while (LeRs.Read())
            {
                LaListe.Add(new ListItem(LeRs.GetInt32(0), LeRs.GetString(1)));
            }
            LeRs.Close();
            aList.DisplayMember = "Txt";
            aList.ValueMember   = "Val";
            aList.DataSource    = LaListe;
        }
Example #2
0
        //Function FormVerif(f As Windows.Forms.Control, erp As Windows.Forms.ErrorProvider) As Boolean
        //    Dim b As Boolean = True
        //    For Each c In f.Controls
        //        Try
        //            If TypeOf(c) Is Windows.Forms.GroupBox Then
        //               If Not FormVerif(c, erp) Then b = False

        //           End If

        //           If c.tag<> "" Then
        //               If c.tag.ToString.Contains(",") Then
        //                   If c.tag.ToString.Split(",")(1).Contains("o") Then
        //                       If TypeOf(c) Is Windows.Forms.TextBox Then
        //                          If c.text = "" Then
        //                              erp.SetError(c, "Obligatoire")
        //                                b = False
        //                            End If
        //                        End If
        //                        If TypeOf(c) Is Windows.Forms.ComboBox Then
        //                           If c.tag.ToString.Contains(",t") Then
        //                               If c.text = "" Then
        //                                   erp.SetError(c, "Obligatoire")
        //                                    b = False
        //                                End If
        //                            Else
        //                                If c.selectedindex< 0 Then
        //                                    erp.SetError(c, "Obligatoire")
        //                                    b = False
        //                                End If
        //                            End If

        //                        End If
        //                    End If
        //                End If
        //            End If
        //        Catch ex As Exception
        //            MsgBox(ex.Message)
        //            Throw New Exception(ex.Message)
        //        End Try
        //    Next
        //    Return b
        //End Function

        public static int FormEnreg(Control LeControl, string LaTable, ref OleDbConnection LaConnect)
        {
            string LidChamp     = "";
            int    LidVal       = 0;
            string SSqlAjoutChp = "";
            string SSqlAjoutVal = "";
            string SSqlModif    = "";
            string SSql         = "";

            //recupere les champs
            List <Common.SQLchamp> LesChamps = new List <SQLchamp>(Common.FormRecupereChamp(LeControl));

            //créer les chaines sql en ajout et modif en meme temps et mémorise l'ID
            foreach (Common.SQLchamp C in (LesChamps))
            {
                if (C.champTyp == "k")
                {
                    LidChamp = C.champNom;
                    if (C.champVal != "")
                    {
                        LidVal = (int)Txt2Num(C.champVal.Replace("'", ""));
                    }
                }
                else
                {
                    if (C.champVal != "")
                    {
                        SSqlAjoutChp += C.champNom + ",";
                        SSqlAjoutVal += C.champVal + ",";
                    }
                    SSqlModif += C.champNom + "=" + C.champVal + ",";
                }
            }

            //supprime la derniere virgule de chaque chaine SQL
            SSqlModif    = SSqlModif.Remove(SSqlModif.Length - 1, 1);
            SSqlAjoutChp = SSqlAjoutChp.Remove(SSqlAjoutChp.Length - 1, 1);
            SSqlAjoutVal = SSqlAjoutVal.Remove(SSqlAjoutVal.Length - 1, 1);

            //execute la requete
            if (LidVal != 0)
            {
                SSql = " update " + LaTable + " set " + SSqlModif + " where " + LidChamp + "=" + LidVal;
            }
            else
            {
                SSql = "insert into " + LaTable + " (" + SSqlAjoutChp + ") values (" + SSqlAjoutVal + ")";
            }
            //MessageBox.Show(SSql);
            SqlDo(SSql, ref LaConnect);

            //  recupere l'id du nouvel enreg
            if (LidVal == 0)
            {
                OleDbDataReader LeRs;
                SSql = "select max(" + LidChamp + ") M from " + LaTable;
                LeRs = Common.SqlLit(SSql, ref LaConnect);
                while (LeRs.Read())
                {
                    LidVal = LeRs.GetInt32(0);
                }
                LeRs.Close();
            }
            return(LidVal);
        }
Example #3
0
        public static void FormRempli(Control b, string sSql, ref OleDbConnection consql)
        {
            OleDbDataReader LeRs;

            LeRs = SqlLit(sSql, ref consql);
            while (LeRs.Read())
            {
                foreach (Control c in (b.Controls))
                {
                    if ((string)(Nz(c.Tag, "")) != "")
                    {
                        try
                        {
                            string LaValeur = "";
                            if (LeRs.GetFieldType(LeRs.GetOrdinal(c.Tag.ToString().Split(',')[0])).Name.Contains("Int32"))
                            {
                                LaValeur = LeRs.GetInt32(LeRs.GetOrdinal(c.Tag.ToString().Split(',')[0])).ToString();
                            }
                            if (LeRs.GetFieldType(LeRs.GetOrdinal(c.Tag.ToString().Split(',')[0])).Name.Contains("String"))
                            {
                                LaValeur = LeRs.GetString(LeRs.GetOrdinal(c.Tag.ToString().Split(',')[0]));
                            }


                            if (c.GetType().ToString().Contains("TextBox"))
                            {
                                c.Text = LaValeur;
                            }

                            if (c.GetType().ToString().Contains("Label"))
                            {
                                c.Text = LaValeur;
                            }

                            if (c.GetType().ToString().Contains("CheckBox"))
                            {
                                ((CheckBox)c).Checked = (bool)Nz(LeRs.GetBoolean(LeRs.GetOrdinal(c.Tag.ToString().Split(',')[0])), false);
                            }

                            if (c.GetType().ToString().Contains("ComboBox"))
                            {
                                //LeRs.GetFieldType(3).Name
                                ComboSetVal(LaValeur, (ComboBox)c);
                            }
                        } catch (Exception ex)
                        {
                            MessageBox.Show(c.Name + "-" + ex.Message);
                        }
                    }

                    //TODO: date
                    //                    If TypeOf(c) Is Windows.Forms.DateTimePicker Then
                    //                       If Nz(lers(c.tag), "") = "" Then
                    //                           c.value = CDate("31/12/2100")
                    //                            If c.showcheckbox Then c.checked = False
                    //                        Else
                    //                            c.value = lers(c.tag)
                    //                            c.enabled = True
                    //                            If c.showcheckbox Then c.checked = True
                    //                        End If
                    //                    End If



                    //            End If
                }
            }
            LeRs.Close();
            //    lers.Close()
        }