コード例 #1
0
        //GetNumClient
        //GetTaskByOrder

        /// <summary>
        /// Get user password for a given ID
        /// </summary>
        public string STPROC_GetUserPwd(UInt32 PersID_UL)
        {
            SqlParameter Pwd_O  = null;
            string       Pwd_ST = null;

            if (mConnected_b)
            {
                // 1. create a command object identifying the stored procedure
                SqlCommand SqlCommand_O = new SqlCommand("GetUserPwd", mSqlConnection_O);

                // 2. set the command object so it knows to execute a stored procedure
                SqlCommand_O.CommandType = CommandType.StoredProcedure;

                // 3. add parameter to command, which will be passed to the stored procedure
                SqlCommand_O.Parameters.Add(new SqlParameter("@PersID", (int)PersID_UL));

                Pwd_O           = SqlCommand_O.Parameters.Add("@Pwd", SqlDbType.VarChar, 20);
                Pwd_O.Direction = ParameterDirection.Output;

                // execute the command
                try
                {
                    SqlCommand_O.ExecuteNonQuery();
                    Pwd_ST = Pwd_O.Value.ToString();
                }
                catch (SqlException Error_O)
                {
                    System.Diagnostics.Debug.WriteLine("Cannot execute stored procedure GetUserPwd SQL exception.\r\n" + Error_O.ToString());
                }
            }

            return(Pwd_ST);
        }
コード例 #2
0
        //CreatePointageGlobal

        //CreatePointageMachine
        public UInt32 STPROC_CreatePointageMachine(UInt32 ComJobEtapeID_UL, UInt32 MachineID_UL, float NbrHMachine_f)
        {
            SqlParameter NewID_O  = null;
            UInt32       NewID_UL = 0;

            if (mConnected_b)
            {
                // 1. create a command object identifying the stored procedure
                SqlCommand SqlCommand_O = new SqlCommand("CreatePointageMachine", mSqlConnection_O);

                // 2. set the command object so it knows to execute a stored procedure
                SqlCommand_O.CommandType = CommandType.StoredProcedure;

                // 3. add parameter to command, which will be passed to the stored procedure
                SqlCommand_O.Parameters.Add(new SqlParameter("@ComJobEtapeID", (int)ComJobEtapeID_UL));
                SqlCommand_O.Parameters.Add(new SqlParameter("@MachineID", (int)MachineID_UL));
                SqlCommand_O.Parameters.Add(new SqlParameter("@NbrHMachine", NbrHMachine_f));

                NewID_O           = SqlCommand_O.Parameters.Add("@newID", SqlDbType.Int);
                NewID_O.Direction = ParameterDirection.Output;

                // execute the command
                try
                {
                    SqlCommand_O.ExecuteNonQuery();
                    if (!(UInt32.TryParse(NewID_O.Value.ToString(), out NewID_UL)))
                    {
                        System.Diagnostics.Debug.WriteLine("Error in stored procedure CreatePointageMachine : ID returned is not integer type.\r\n");
                    }
                }
                catch (SqlException Error_O)
                {
                    System.Diagnostics.Debug.WriteLine("Cannot execute stored procedure CreatePointageMachine SQL exception.\r\n" + Error_O.ToString());
                }
            }

            return(NewID_UL);
        }
コード例 #3
0
        //DeleteComJob
        //DeleteComJobEtape
        //DeleteDepPref
        //DeleteJobDep

        //DeleteMsg
        public void STPROC_DeleteMsg(UInt32 MsgID_UL)
        {
            if (mConnected_b)
            {
                // 1. create a command object identifying the stored procedure
                SqlCommand SqlCommand_O = new SqlCommand("DeleteMsg", mSqlConnection_O);

                // 2. set the command object so it knows to execute a stored procedure
                SqlCommand_O.CommandType = CommandType.StoredProcedure;

                // 3. add parameter to command, which will be passed to the stored procedure
                SqlCommand_O.Parameters.Add(new SqlParameter("@MsgID", (int)MsgID_UL));

                // execute the command
                try
                {
                    SqlCommand_O.ExecuteNonQuery();
                }
                catch (SqlException Error_O)
                {
                    System.Diagnostics.Debug.WriteLine("Cannot execute stored procedure DeleteMsg SQL exception.\r\n" + Error_O.ToString());
                }
            }
        }
コード例 #4
0
        //CreateCertif

        // CreateFullCertif
        public UInt32 STPROC_CreateFullCertif(UInt32 NoteEnvoiID_UL, String Matiere_st, String Lot_st, String TTherm_st, String TSurf_st, String Conforme_st, String PathCertif_st, String Rem_st)
        {
            SqlParameter NewID_O  = null;
            UInt32       NewID_UL = 0;

            if (mConnected_b)
            {
                // 1. create a command object identifying the stored procedure
                SqlCommand SqlCommand_O = new SqlCommand("CreateFullCertif", mSqlConnection_O);

                // 2. set the command object so it knows to execute a stored procedure
                SqlCommand_O.CommandType = CommandType.StoredProcedure;

                // 3. add parameter to command, which will be passed to the stored procedure
                SqlCommand_O.Parameters.Add(new SqlParameter("@NoteEnvoiID", (int)NoteEnvoiID_UL));
                SqlCommand_O.Parameters.Add(new SqlParameter("@Matiere", Matiere_st));
                SqlCommand_O.Parameters.Add(new SqlParameter("@Lot", Lot_st));
                SqlCommand_O.Parameters.Add(new SqlParameter("@TTherm", TTherm_st));
                SqlCommand_O.Parameters.Add(new SqlParameter("@TSurf", TSurf_st));
                SqlCommand_O.Parameters.Add(new SqlParameter("@Conforme", Conforme_st));
                SqlCommand_O.Parameters.Add(new SqlParameter("@PathCertif", PathCertif_st));
                SqlCommand_O.Parameters.Add(new SqlParameter("@Rem", Rem_st));

                NewID_O           = SqlCommand_O.Parameters.Add("@newid", SqlDbType.Int);
                NewID_O.Direction = ParameterDirection.Output;

                // execute the command
                try
                {
                    SqlCommand_O.ExecuteNonQuery();
                    if (!(UInt32.TryParse(NewID_O.Value.ToString(), out NewID_UL)))
                    {
                        System.Diagnostics.Debug.WriteLine("Error in stored procedure CreateFullCertif : ID returned is not integer type.\r\n");
                    }
                }
                catch (SqlException Error_O)
                {
                    System.Diagnostics.Debug.WriteLine("Cannot execute stored procedure CreateFullCertif SQL exception.\r\n" + Error_O.ToString());
                }
            }

            return(NewID_UL);
        }
コード例 #5
0
        //CreateNE

        // CreateFullNE
        public UInt32 STPROC_CreateFullNE(UInt32 ComJobID_UL, float QteNE_f, DateTime DateExpedition_O, bool ChkPartiel_b, String PathNE_st, String JobLib_st, String NumCmdClient_st, String Obs_st)
        {
            SqlParameter NewID_O  = null;
            UInt32       NewID_UL = 0;

            if (mConnected_b)
            {
                // 1. create a command object identifying the stored procedure
                SqlCommand SqlCommand_O = new SqlCommand("CreateFullNE", mSqlConnection_O);

                // 2. set the command object so it knows to execute a stored procedure
                SqlCommand_O.CommandType = CommandType.StoredProcedure;

                // 3. add parameter to command, which will be passed to the stored procedure
                SqlCommand_O.Parameters.Add(new SqlParameter("@ComJobID", (int)ComJobID_UL));
                SqlCommand_O.Parameters.Add(new SqlParameter("@QteNE", QteNE_f));
                SqlCommand_O.Parameters.Add(new SqlParameter("@DateExpedition", DateExpedition_O));
                SqlCommand_O.Parameters.Add(new SqlParameter("@ChkPartiel", ChkPartiel_b));
                SqlCommand_O.Parameters.Add(new SqlParameter("@PathNE", PathNE_st));
                SqlCommand_O.Parameters.Add(new SqlParameter("@JobLib", JobLib_st));
                SqlCommand_O.Parameters.Add(new SqlParameter("@NumCmdClient", NumCmdClient_st));
                SqlCommand_O.Parameters.Add(new SqlParameter("@Obs", Obs_st));

                NewID_O           = SqlCommand_O.Parameters.Add("@newID", SqlDbType.Int);
                NewID_O.Direction = ParameterDirection.Output;

                // execute the command
                try
                {
                    SqlCommand_O.ExecuteNonQuery();
                    if (!(UInt32.TryParse(NewID_O.Value.ToString(), out NewID_UL)))
                    {
                        System.Diagnostics.Debug.WriteLine("Error in stored procedure CreateFullNE : ID returned is not integer type.\r\n");
                    }
                }
                catch (SqlException Error_O)
                {
                    System.Diagnostics.Debug.WriteLine("Cannot execute stored procedure CreateFullNE SQL exception.\r\n" + Error_O.ToString());
                }
            }

            return(NewID_UL);
        }
コード例 #6
0
ファイル: FunctionManager.cs プロジェクト: ATGfx/MMSoft
        //CountPointageHoursOnJob
        public float SCFNC_CountPointageHoursOnJob(UInt32 JobID_UL)
        {
            float SumHours_f = 0.0f;

            SqlCommand   SqlCommand_O;
            SqlParameter JobID_O;

            if (mConnected_b)
            {
                SqlCommand_O = new SqlCommand("SELECT dbo.CountPointageHoursOnJob(@JobID)", mSqlConnection_O);
                JobID_O      = new SqlParameter("@JobID", SqlDbType.Int);

                SqlCommand_O.Parameters.Add(JobID_O);

                JobID_O.Value = JobID_UL;

                try
                {
                    SumHours_f = (float)Convert.ToDecimal(SqlCommand_O.ExecuteScalar()); // Brutal cast in float because Execute Scalar method returns object
                }
                catch (SqlException Error_O)
                {
                    System.Diagnostics.Debug.WriteLine("Cannot execute function CountPointageHoursOnJob SQL exception.\r\n" + Error_O.ToString());
                }
                catch (Exception Error_O)
                {
                    System.Diagnostics.Debug.WriteLine("Cannot cast in float returned value of function CountPointageHoursOnJob.\r\n" + Error_O.ToString());
                }
            }

            return(SumHours_f);
        }
コード例 #7
0
        //CountPlanByName

        //CountTask
        public UInt32 STPROC_CountTask(UInt32 ComJobID_UL)
        {
            SqlParameter Sum_O  = null;
            UInt32       Sum_UL = 0;

            if (mConnected_b)
            {
                // 1. create a command object identifying the stored procedure
                SqlCommand SqlCommand_O = new SqlCommand("CountTask", mSqlConnection_O);

                // 2. set the command object so it knows to execute a stored procedure
                SqlCommand_O.CommandType = CommandType.StoredProcedure;

                // 3. add parameter to command, which will be passed to the stored procedure
                SqlCommand_O.Parameters.Add(new SqlParameter("@JobID", (int)ComJobID_UL));

                Sum_O           = SqlCommand_O.Parameters.Add("@sum", SqlDbType.Int);
                Sum_O.Direction = ParameterDirection.Output;

                // execute the command
                try
                {
                    SqlCommand_O.ExecuteNonQuery();
                    if (!(UInt32.TryParse(Sum_O.Value.ToString(), out Sum_UL)))
                    {
                        System.Diagnostics.Debug.WriteLine("Error in stored procedure CountTask : ID returned is not integer type.\r\n");
                    }
                }
                catch (SqlException Error_O)
                {
                    System.Diagnostics.Debug.WriteLine("Cannot execute stored procedure CountTask SQL exception.\r\n" + Error_O.ToString());
                }
            }

            return(Sum_UL);
        }
コード例 #8
0
        /// <summary>
        /// Execute a request command on the database
        /// </summary>
        /// <param name="SqlCmd_st">String of Sql command</param>
        /// /// <param name="ParamList_O">List of parameters name of Sql command</param>
        /// /// <param name="ValueList_O">Value oif parameters as object type. Implicit conversion is done between .net type and sql type.</param>
        /// <returns>Returns the associated SqlDataReader of request. Reader is null if command fails</returns>
        public bool ExecuteRequest(String SqlCmd_st, List <String> ParamList_O = null, List <Object> ValueList_O = null)
        {
            SqlCommand SqlCommand_O;

            bool Succeed_b = false;

            if (mConnected_b)
            {
                using (SqlCommand_O = new SqlCommand())
                {
                    SqlCommand_O.Connection  = mSqlConnection_O;
                    SqlCommand_O.CommandText = SqlCmd_st;

                    if (ParamList_O != null && ValueList_O != null)
                    {
                        for (int i = 0; i < ParamList_O.Count; i++)
                        {
                            SqlCommand_O.Parameters.AddWithValue(ParamList_O[i], ValueList_O[i]);
                        }
                    }

                    try
                    {
                        SqlCommand_O.ExecuteNonQuery();
                        Succeed_b = true;
                    }
                    catch (SqlException Error_O)
                    {
                        System.Diagnostics.Debug.WriteLine("Cannot execute select request on database due to SQL exception.\r\n" + Error_O.ToString() + "\r\nQuerry : " + SqlCommand_O.CommandText);
                    }
                    catch (InvalidOperationException Error_O)
                    {
                        System.Diagnostics.Debug.WriteLine("Cannot execute update request on database due to invalid operation exception.\r\n" + Error_O.ToString() + "\r\nQuerry : " + SqlCommand_O.CommandText);
                    }
                }
            }

            return(Succeed_b);
        }
コード例 #9
0
        /// <summary>
        ///  Connect to database with provided connection string that contains information about the Database and credentials
        /// </summary>
        /// <param name="ConnectionString_S"> Default string for connection in format (Persist Info Security; Data Source; Integrated Security; Inital Catalog)\n
        /// - Persist Security Info : security-sensitive information, such as the password, is not returned as part of the connection
        /// - Data Source :	identifies the server, it could be local machine, machine domain name, or IP Address.\n
        /// - Initial Catalog : is Database name on provided Database server.\n
        /// - Integrated Security : set to SSPI to make connection with user's Windows login\n
        /// - User ID : name of user configured in SQL Server.\n
        /// - Password : password matching SQL Server User ID.
        ///</param>
        ///<example>Persist Security Info=False; Data Source=(local)\\SQLEXPRESS; Integrated Security=SSPI; Initial Catalog=MMSoft;UserID = toto; Password = 1234;</example>
        /// <returns>true if connexion between server and client is established, and update internal state such that this object knows its connexion state</returns>
        public bool ConnectDatabase(String ConnectionString_S)
        {
            if (!mConnected_b)
            {
                try
                {
                    // Connect to database
                    mSqlConnection_O = new SqlConnection(ConnectionString_S);
                    mSqlConnection_O.Open();
                    mConnected_b = true;

                    // Get instance name
                    String[] ConnectionInfos_ST = ConnectionString_S.Split(';');

                    for (int i = 0; i < ConnectionInfos_ST.Length; i++)
                    {
                        if (ConnectionInfos_ST[i].Contains("Initial Catalog") && ConnectionInfos_ST[i].Split('=').Length >= 2)
                        {
                            mDBInstanceName_ST = ConnectionInfos_ST[i].Split('=')[1];
                        }
                    }

                    bool DateFormatChanged_b = ExecuteRequest("SET DATEFORMAT dmy;");

                    if (!DateFormatChanged_b)
                    {
                        MessageBox.Show("Le format de date n'a pas été enregistré par le serveur, le programme se comportera de façon instable au niveau des dates " +
                                        "et il n'est pas conseillé d'aller plus loin", "Attention !", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }

                    // Create internal stored procedure manager
                    mStoredProcedureManager_O = new StoredProcedureManager(mConnected_b, mSqlConnection_O);

                    // Create internal function manager
                    mFunctionManager_O = new FunctionManager(mConnected_b, mSqlConnection_O);
                }
                catch (InvalidOperationException Error_O)
                {
                    mSqlConnection_O = null;
                    System.Diagnostics.Debug.WriteLine("Cannot open database due to invalid operation exception.\r\n" + Error_O.ToString());
                }
                catch (SqlException Error_O)
                {
                    mSqlConnection_O = null;
                    System.Diagnostics.Debug.WriteLine("Cannot open database due to SQL exception.\r\n" + Error_O.ToString());
                }
                catch (ArgumentException Error_O)
                {
                    mSqlConnection_O = null;
                    System.Diagnostics.Debug.WriteLine("Cannot open database due to argument exception.\r\n" + Error_O.ToString());
                }
            }

            return(mConnected_b);
        }
コード例 #10
0
        /// <summary>
        /// Close the previously opened connection to a database
        /// </summary>
        /// <returns>true if the disconnection was executed successfuly</returns>
        public bool DisconnectDatabase()
        {
            if (mConnected_b)
            {
                try
                {
                    mSqlConnection_O.Close();
                    mConnected_b       = false;
                    mDBInstanceName_ST = null;
                }
                catch (SqlException Error_O)
                {
                    System.Diagnostics.Debug.WriteLine("Cannot close database due to SQL excpetion.\r\n" + Error_O.ToString());
                }
            }

            // returns inverse of mConnected_b to know if method succeeded, if not connected at method calling, the method considered disconnection as successful
            return(!mConnected_b);
        }
コード例 #11
0
        /// <summary>
        /// Execute a select command on the database
        /// </summary>
        /// <param name="SqlSelect_S">String of Sql SELECT command</param>
        /// <returns>Returns the associated SqlDataReader of request. Reader is null if command fails</returns>
        public SqlDataReader Select(String SqlSelect_S)
        {
            SqlCommand    SqlCommand_O = new SqlCommand();
            SqlDataReader SqlReader_O  = null;

            if (mConnected_b)
            {
                SqlCommand_O.Connection  = mSqlConnection_O;
                SqlCommand_O.CommandText = SqlSelect_S;

                try
                {
                    SqlReader_O = SqlCommand_O.ExecuteReader();
                }
                catch (SqlException Error_O)
                {
                    System.Diagnostics.Debug.WriteLine("Cannot execute select request on database due to SQL exception.\r\n" + Error_O.ToString());
                }
                catch (InvalidOperationException Error_O)
                {
                    System.Diagnostics.Debug.WriteLine("Cannot execute select request on database due to invalid operation exception.\r\n" + Error_O.ToString());
                }
            }

            return(SqlReader_O);
        }
コード例 #12
0
ファイル: FunctionManager.cs プロジェクト: ATGfx/MMSoft
        //CountJobAchatReel
        //CountJobCost
        //CountJobFact

        //CountJobInCom
        public UInt32 SCFNC_CountJobInCom(UInt32 ComID_UL)
        {
            UInt32 NbJobs_UL = 0;

            SqlCommand   SqlCommand_O;
            SqlParameter ComID_O;

            if (mConnected_b)
            {
                SqlCommand_O = new SqlCommand("SELECT dbo.CountJobInCom(@ComID)", mSqlConnection_O);
                ComID_O      = new SqlParameter("@ComID", SqlDbType.Int);

                SqlCommand_O.Parameters.Add(ComID_O);

                ComID_O.Value = (int)ComID_UL;
                try
                {
                    object StoredProcValue_O = SqlCommand_O.ExecuteScalar();

                    if (StoredProcValue_O.GetType() != typeof(DBNull))
                    {
                        NbJobs_UL = (UInt32)Convert.ToInt32(StoredProcValue_O); // Brutal cast in int32 because Execute Scalar method returns object
                    }
                }
                catch (SqlException Error_O)
                {
                    System.Diagnostics.Debug.WriteLine("Cannot execute function CountJobInCom SQL exception.\r\n" + Error_O.ToString());
                }
                catch (Exception Error_O)
                {
                    System.Diagnostics.Debug.WriteLine("Cannot cast in int32 returned value of function CountJobInCom.\r\n" + Error_O.ToString());
                }
            }

            return(NbJobs_UL);
        }
コード例 #13
0
ファイル: FunctionManager.cs プロジェクト: ATGfx/MMSoft
        /****************************/
        /** Table-valued functions **/
        /****************************/
        //GetCumulTable
        //GetCumulTableView
        //GetDetailedCumulTableView
        //GetPersTotHoursPerMonth

        /*****************************/
        /** Scalar-valued functions **/
        /*****************************/
        /// <summary>
        /// Count the estimated value of all the purchase made on a job
        /// </summary>
        /// <param name="JobID_i">The ID of the job</param>
        /// <returns>The sum of estimated value of purchases. If there is a connection problem (client not connected) the method returns -1</returns>
        public float SCFNC_CountJobAchatEstim(int JobID_i)
        {
            float JobAchatEstim_f = -1.0f;

            SqlCommand   SqlCommand_O;
            SqlParameter JobIdParam_O;

            if (mConnected_b)
            {
                SqlCommand_O = new SqlCommand("SELECT dbo.CountJobAchatEstim(@jobID)", mSqlConnection_O);
                JobIdParam_O = new SqlParameter("@jobID", SqlDbType.Int);
                SqlCommand_O.Parameters.Add(JobIdParam_O);
                JobIdParam_O.Value = JobID_i;
                try
                {
                    JobAchatEstim_f = (float)Convert.ToDecimal(SqlCommand_O.ExecuteScalar()); // Brutal cast in float because Execute Scalar method returns object
                }
                catch (SqlException Error_O)
                {
                    System.Diagnostics.Debug.WriteLine("Cannot execute function CountJobAchatEstim SQL exception.\r\n" + Error_O.ToString());
                }
                catch (Exception Error_O)
                {
                    System.Diagnostics.Debug.WriteLine("Cannot cast in float returned value of function CountJobAchatEstim.\r\n" + Error_O.ToString());
                }
            }

            return(JobAchatEstim_f);
        }
コード例 #14
0
ファイル: FunctionManager.cs プロジェクト: ATGfx/MMSoft
        //GetMaxFournNumber
        public UInt32 SCFNC_GetMaxProviderNumber()
        {
            UInt32 MaxID_UL = 0;

            SqlCommand SqlCommand_O;

            if (mConnected_b)
            {
                SqlCommand_O = new SqlCommand("SELECT dbo.GetMaxFournNumber()", mSqlConnection_O);

                try
                {
                    MaxID_UL = (UInt32)Convert.ToUInt32(SqlCommand_O.ExecuteScalar()); // Brutal cast in UInt32 because Execute Scalar method returns object
                }
                catch (SqlException Error_O)
                {
                    System.Diagnostics.Debug.WriteLine("Cannot execute function GetMaxFournNumber SQL exception.\r\n" + Error_O.ToString());
                }
                catch (Exception Error_O)
                {
                    System.Diagnostics.Debug.WriteLine("Cannot cast in float returned value of function GetMaxFournNumber.\r\n" + Error_O.ToString());
                }
            }

            return(MaxID_UL);
        }
コード例 #15
0
        //SetNumInterne
        //SetTaskOrder
        //UpdateAllNonCorrectedHours
        //UpdateClient
        //UpdateCom
        //UpdateComJob
        //UpdateCorrectedHours
        //UpdateCP
        //UpdateDepName
        //UpdateFourn
        //UpdateHeuresTotOnJobs
        //UpdateHourscorrected
        //UpdateJobStatus

        //UpdateJobSumHours
        public bool STPROC_UpdateJobSumHours(UInt32 ComJobID_UL)
        {
            bool Rts_b = false;

            if (mConnected_b)
            {
                // 1. create a command object identifying the stored procedure
                SqlCommand SqlCommand_O = new SqlCommand("UpdateJobSumHours", mSqlConnection_O);

                // 2. set the command object so it knows to execute a stored procedure
                SqlCommand_O.CommandType = CommandType.StoredProcedure;

                // 3. add parameter to command, which will be passed to the stored procedure
                SqlCommand_O.Parameters.Add(new SqlParameter("@ComJobID", (int)ComJobID_UL));

                // execute the command
                try
                {
                    Rts_b = (SqlCommand_O.ExecuteNonQuery() == 1);
                }
                catch (SqlException Error_O)
                {
                    System.Diagnostics.Debug.WriteLine("Cannot execute stored procedure UpdateJobSumHours SQL exception.\r\n" + Error_O.ToString());
                }
            }

            return(Rts_b);
        }
コード例 #16
0
ファイル: FormConnexion.cs プロジェクト: ATGfx/MMSoft
        /// <summary>
        /// Method initializing the connection to the database's server. This method assume that the configuration file is correct. If the method cannot connect to the server,
        /// a message box pop to prevent the user that there is a problem with its connection.
        /// </summary>
        private bool InitializeConnection()
        {
            string ConnectionString_ST = "";
            bool   Connected_b;

            try
            {
                ConnectionString_ST += "User ID=" + mUserConnexionInfo_O.mUserName_st + "; ";
                ConnectionString_ST += "Persist Security Info=" + mUserConnexionInfo_O.mPersistSecurityInfo_b.ToString() + "; ";
                ConnectionString_ST += "Data Source=" + mUserConnexionInfo_O.mDataSource_st + "; ";
                ConnectionString_ST += "Integrated Security=" + mUserConnexionInfo_O.mIntegratedSecurity_st + "; ";
                ConnectionString_ST += "Initial Catalog=" + mUserConnexionInfo_O.mInitialCatalog_st + "; ";
                ConnectionString_ST += "MultipleActiveResultSets=" + mUserConnexionInfo_O.mMultipleActiveResultSets_b.ToString() + ";";

                mDBManager_O.ConnectDatabase(ConnectionString_ST);
                Connected_b = mDBManager_O.mConnected_b;
            }
            catch (IOException Error_O)
            {
                Connected_b = false;
                System.Diagnostics.Debug.WriteLine("Cannot open connection configuration file.\r\n" + Error_O.ToString());
                MessageBox.Show("Impossible de se connecter au serveur de base de données MMSoft. Veuillez vérifier votre fichier de configuration de connexion " + USER_CONNECTION_CONFIG_FILE + ". Si le fichier de configuration était inexistant il sera recréé.");
            }

            return(Connected_b);
        }
コード例 #17
0
        //UpdatePathCertif
        //UpdatePathNE
        //UpdatePers
        //UpdatePersStatus
        //UpdateSubDepName
        //UpdateTask
        //UpdateTypeSoc



        /// <summary>
        /// Verify if the username exists in database and if password match with it. If it is not the case, the default ID returned is 0 (meaning an error occured).
        /// </summary>
        public UInt32 STPROC_VerifyUser(string Username_ST, string Pwd_ST, out UInt32 UserID_UL, out bool IsManager_b)
        {
            SqlParameter UserID_O    = null;
            SqlParameter IsManager_O = null;

            UserID_UL   = 0;
            IsManager_b = false;

            if (mConnected_b)
            {
                // 1. create a command object identifying the stored procedure
                SqlCommand SqlCommand_O = new SqlCommand("VerifyUser", mSqlConnection_O);

                // 2. set the command object so it knows to execute a stored procedure
                SqlCommand_O.CommandType = CommandType.StoredProcedure;

                // 3. add parameter to command, which will be passed to the stored procedure
                SqlCommand_O.Parameters.Add(new SqlParameter("@UserLogin", Username_ST));
                SqlCommand_O.Parameters.Add(new SqlParameter("@Pwd", Pwd_ST));

                UserID_O           = SqlCommand_O.Parameters.Add("@PersId", SqlDbType.Int);
                UserID_O.Direction = ParameterDirection.Output;

                IsManager_O           = SqlCommand_O.Parameters.Add("@IsManager", SqlDbType.Bit);
                IsManager_O.Direction = ParameterDirection.Output;

                // execute the command
                try
                {
                    SqlCommand_O.ExecuteNonQuery();
                    UInt32.TryParse(UserID_O.Value.ToString(), out UserID_UL);
                    bool.TryParse(IsManager_O.Value.ToString(), out IsManager_b);
                }
                catch (SqlException Error_O)
                {
                    System.Diagnostics.Debug.WriteLine("Cannot execute stored procedure VerifyUser SQL exception.\r\n" + Error_O.ToString());
                }
            }

            return(UserID_UL);
        }
コード例 #18
0
ファイル: FunctionManager.cs プロジェクト: ATGfx/MMSoft
        //CountNbrH
        //CountNbrHCorr
        //CountPersHourInDay
        public float SCFNC_CountPersHourInDay(DateTime Date_O, UInt32 PersID_UL)
        {
            float SumHours_f = 0.0f;

            SqlCommand   SqlCommand_O;
            SqlParameter DayParam_O, MonthParam_O, YearParam_O, PersIDParam_O;

            if (mConnected_b)
            {
                SqlCommand_O  = new SqlCommand("SELECT dbo.CountPersHourInDay(@day, @month, @year, @PersID)", mSqlConnection_O);
                DayParam_O    = new SqlParameter("@day", SqlDbType.Int);
                MonthParam_O  = new SqlParameter("@month", SqlDbType.Int);
                YearParam_O   = new SqlParameter("@year", SqlDbType.Int);
                PersIDParam_O = new SqlParameter("@PersID", SqlDbType.Int);

                SqlCommand_O.Parameters.Add(DayParam_O);
                SqlCommand_O.Parameters.Add(MonthParam_O);
                SqlCommand_O.Parameters.Add(YearParam_O);
                SqlCommand_O.Parameters.Add(PersIDParam_O);

                DayParam_O.Value    = Date_O.Day;
                MonthParam_O.Value  = Date_O.Month;
                YearParam_O.Value   = Date_O.Year;
                PersIDParam_O.Value = PersID_UL;
                try
                {
                    object StoredProcValue_O = SqlCommand_O.ExecuteScalar();

                    if (StoredProcValue_O.GetType() != typeof(DBNull))
                    {
                        SumHours_f = (float)Convert.ToDecimal(StoredProcValue_O); // Brutal cast in float because Execute Scalar method returns object
                    }
                }
                catch (SqlException Error_O)
                {
                    System.Diagnostics.Debug.WriteLine("Cannot execute function CountPersHourInDay SQL exception.\r\n" + Error_O.ToString());
                }
                catch (Exception Error_O)
                {
                    System.Diagnostics.Debug.WriteLine("Cannot cast in float returned value of function CountPersHourInDay.\r\n" + Error_O.ToString());
                }
            }

            return(SumHours_f);
        }