コード例 #1
0
ファイル: clsCommonTest.cs プロジェクト: Quanghai32/CFP
        /// <summary>
        /// Writing a value to setting file which is same location with EXE
        ///     +Para1 (13): File name want to write
        ///     +Para2 (14): Section name want to write
        ///     +Para3 (15): keyname want to write
        ///     +Para4 (16): Option to get auto index (0: add, 1: No add)
        ///     +Para5 (17): Value to write
        /// </summary>
        /// <param name="lstlstobjInput"></param>
        /// <param name="lstlstobjOutput"></param>
        /// <returns></returns>
        public object PluginCommonTestFuncID4(List <List <object> > lstlstobjInput, out List <List <object> > lstlstobjOutput)
        {
            lstlstobjOutput = new List <List <object> >();
            var lstobjTemp = new List <object>();

            //1. Check if file is exist or not
            string strAppPath  = lstlstobjInput[0][0].ToString();
            string iniFileName = @"\" + lstlstobjInput[0][13].ToString();
            string strFileName = strAppPath + iniFileName;

            //Check file exist
            nspFileHandle.ChkExist clsTest = new nspFileHandle.ChkExist();
            if (clsTest.CheckFileExist(strFileName) == false)
            {
                //MessageBox.Show("'" + lstPara[0] + "' file does not exist! Please check!", "CommonFunctionID002() error");
                return("Error: File is not exist"); //File not exist code
            }


            string strKeyName = "";

            //Calculate string file name
            int intProcessID = 0;

            if (int.TryParse(lstlstobjInput[0][1].ToString(), out intProcessID) == false)
            {
                return("error");
            }

            if (lstlstobjInput[0][16].ToString().ToUpper() == "1") //No Auto
            {
                strKeyName = lstlstobjInput[0][15].ToString();
            }
            else //Auto - Default
            {
                strKeyName = lstlstobjInput[0][15].ToString() + (intProcessID + 1).ToString();
            }


            //Write to ini file the value desired
            long lngTemp = 0;

            lngTemp = nspFileHandle.WriteFiles.IniWriteValue(strFileName, lstlstobjInput[0][14].ToString(), strKeyName, lstlstobjInput[0][17].ToString());

            if (lngTemp == 9999) //Error
            {
                return("Error: Cannot write to ini file!");
            }

            //If everything is OK, return 0
            return("0");
        }
コード例 #2
0
ファイル: HoangLibVer01.cs プロジェクト: Quanghai32/CFP
        //Write to ini file
        public static long IniWriteValue(string strFileFullPath, string strSectionName, string strItemName, string strDataToWrite)
        {
            // If string greater than 254 characters (255th spot is null-terminator),
            // string will be truncated.
            nspFileHandle.ChkExist clsTest = new nspFileHandle.ChkExist();

            if (clsTest.CheckFileExist(strFileFullPath) == false)
            {
                MessageBox.Show(strFileFullPath + " file not exist!", "GetPrivateProfile() Error");
                return(9999); //Error Code
            }
            else
            {
                long lngret = 0;
                lngret = nspApiDeclare.ApiDeclaration.WritePrivateProfileString(strSectionName, strItemName, strDataToWrite, strFileFullPath);
                return(lngret);
            }
        }
コード例 #3
0
ファイル: HoangLibVer00.cs プロジェクト: Quanghai32/CFP
        //*********************************************************************************************************
        public static string IniReadValue(string Section, string Key, string strFileFullPath)
        {
            // If string greater than 254 characters (255th spot is null-terminator),
            // string will be truncated.
            nspFileHandle.ChkExist clsTest = new nspFileHandle.ChkExist();

            if (clsTest.CheckFileExist(strFileFullPath) == false)
            {
                MessageBox.Show(strFileFullPath + " file not exist!", "GetPrivateProfile() Error");
                return("error"); //Error Code
            }
            else
            {
                const int     capacity = 1023;
                StringBuilder temp     = new StringBuilder(capacity);
                int           i        = nspApiDeclare.ApiDeclaration.GetPrivateProfileString(Section, Key, "error", temp, capacity, strFileFullPath);
                return(temp.ToString());
            }
        }
コード例 #4
0
ファイル: clsSavingData.cs プロジェクト: Quanghai32/CFP
        public void SavingDataIni()
        {
            //1. Check if Data folder is exist or not. If not, then create new data folder for saving
            try
            {
                var clsTemp = new nspFileHandle.ChkExist();
                if (clsTemp.CheckFolderExist(this.strDataSavePath) == false)
                {
                    Directory.CreateDirectory(this.strDataSavePath);
                }
                //2. Each day create 1 csv file to store checking data if not exist
                //   File format: "Year_Month_Date.csv" . Example: 2014_9_6.csv
                string   strDataFileName = "";
                DateTime _Now            = DateTime.Now;
                strDataFileName = _Now.Year.ToString() + "_" + _Now.Month.ToString() + "_" + _Now.Day.ToString() + ".csv";

                string strDataFileFullName = this.strDataSavePath + @"\" + strDataFileName;
                //MessageBox.Show(strDataFileName);
                if (clsTemp.CheckFileExist(strDataFileFullName) == false)
                {
                    File.Create(strDataFileFullName).Close();
                }
                //3. Create File Header
                CreateFileHeader(strDataFileFullName);

                //4. Find out some Information of PC
                this.strMacAddress = nspMyFunc.clsMyFunc.GetMACAddress();
                this.strIPAddress  = nspMyFunc.clsMyFunc.GetIPv4Address();
                this.strPCName     = nspMyFunc.clsMyFunc.GetPcName();
            }
            catch //(Exception ex)
            {
                MessageBox.Show("Can not create folder [" + this.strDataSavePath + "] to save data! The Drive is not exist? Please check!", "SavingDataIni()");
                Environment.Exit(0);
            }
        }
コード例 #5
0
ファイル: clsCommonTest.cs プロジェクト: Quanghai32/CFP
        /// <summary>
        /// Writing a value to setting file which is different location with EXE
        ///     +Para1 (13): File name in same location with exe file, which show where file want to write info to
        ///     +Para2 (14): Section name (file which contents info)
        ///     +Para3 (15): keyname (file which contents info)
        ///     +Para4 (16): Section Name of target file
        ///     +Para5 (17): Key Name of target file
        ///     +Para6 (18): Option to get auto index (0: add, 1: No add)
        ///     +Para7 (19): Value to write
        /// </summary>
        /// <param name="lstlstobjInput"></param>
        /// <param name="lstlstobjOutput"></param>
        /// <returns></returns>
        public object PluginCommonTestFuncID5(List <List <object> > lstlstobjInput, out List <List <object> > lstlstobjOutput)
        {
            lstlstobjOutput = new List <List <object> >();
            var lstobjTemp = new List <object>();

            //1. Check if file is exist or not
            string strAppPath  = lstlstobjInput[0][0].ToString();
            string iniFileName = @"\" + lstlstobjInput[0][13].ToString();
            string strFileName = strAppPath + iniFileName;

            //Check file exist
            nspFileHandle.ChkExist clsTest = new nspFileHandle.ChkExist();
            if (clsTest.CheckFileExist(strFileName) == false)
            {
                //MessageBox.Show("'" + lstPara[0] + "' file does not exist! Please check!", "CommonFunctionID002() error");
                return("Error: Info File is not exist"); //File not exist code
            }

            string strTmp = "";

            //Reading value in key name
            strTmp = nspFileHandle.ReadFiles.IniReadValue(lstlstobjInput[0][14].ToString(), lstlstobjInput[0][15].ToString(), strFileName);
            if (strTmp.ToLower() == "error")
            {
                //MessageBox.Show("Error: cannot find '" + lstPara[2] + "' config in '" + lstPara[1] + "' of " + strFileName + " file!", "CommonFunctionID002() error");
                return("Error: fail to read file"); //Getting key value fail
            }

            //Assign new value for Target file
            strFileName = strTmp;
            //Check file exist or not
            if (clsTest.CheckFileExist(strFileName) == false)
            {
                return("Error: Target File is not exist"); //File not exist code
            }

            //Calculate key name
            string strKeyName   = "";
            int    intProcessID = 0;

            if (int.TryParse(lstlstobjInput[0][1].ToString(), out intProcessID) == false)
            {
                return("error");
            }

            if (lstlstobjInput[0][18].ToString().ToUpper() == "1") //No Auto
            {
                strKeyName = lstlstobjInput[0][17].ToString();
            }
            else //Auto - Default
            {
                strKeyName = lstlstobjInput[0][17].ToString() + (intProcessID + 1).ToString();
            }

            //Write to ini file the value desired
            long lngTemp = 0;

            lngTemp = nspFileHandle.WriteFiles.IniWriteValue(strFileName, lstlstobjInput[0][16].ToString(), strKeyName, lstlstobjInput[0][19].ToString());

            if (lngTemp == 9999) //Error
            {
                return("Error: Cannot write to target file!");
            }

            //If everything is OK, return 0
            return("0");
        }
コード例 #6
0
ファイル: clsCommonTest.cs プロジェクト: Quanghai32/CFP
        /// <summary>
        /// For Reading a value in setting file and return
        ///     +Para1 (13): File name
        ///     +Para2 (14): Section name
        ///     +Para3 (15): Key name
        ///     +Para4 (16): optional to add auto index: 0 - Add. 1 - No Add.
        ///     +Para5 (17): optional to return: 0 - Return "0" if everything is OK (with user return string)
        ///                                      1 - Convert to Numeric (Double format) and return under string format (with user return string)
        /// User Return command: "ReadIni"
        /// </summary>
        /// <param name="lstlstobjInput"></param>
        /// <param name="lstlstobjOutput"></param>
        /// <returns></returns>
        public object PluginCommonTestFuncID2(List <List <object> > lstlstobjInput, out List <List <object> > lstlstobjOutput)
        {
            lstlstobjOutput = new List <List <object> >();
            var lstobjTemp = new List <object>();

            //1. Check if file is exist or not
            string strAppPath  = lstlstobjInput[0][0].ToString();
            string iniFileName = @"\" + lstlstobjInput[0][13].ToString();
            string strFileName = strAppPath + iniFileName;

            //Check file exist
            nspFileHandle.ChkExist clsTest = new nspFileHandle.ChkExist();
            if (clsTest.CheckFileExist(strFileName) == false)
            {
                //MessageBox.Show("'" + lstPara[0] + "' file does not exist! Please check!", "CommonFunctionID002() error");
                return("Error: File is not exist"); //File not exist code
            }

            string strTmp     = "";
            string strKeyName = "";

            //Calculate string file name
            int intProcessID = 0;

            if (int.TryParse(lstlstobjInput[0][1].ToString(), out intProcessID) == false)
            {
                return("error");
            }

            if (lstlstobjInput[0][16].ToString().ToUpper() == "1") //No Auto
            {
                strKeyName = lstlstobjInput[0][15].ToString();
            }
            else //Auto - Default
            {
                strKeyName = lstlstobjInput[0][15].ToString() + (intProcessID + 1).ToString();
            }

            //Reading value in key name
            strTmp = nspFileHandle.ReadFiles.IniReadValue(lstlstobjInput[0][14].ToString(), strKeyName, strFileName);
            if (strTmp.ToLower() == "error")
            {
                //MessageBox.Show("Error: cannot find '" + lstPara[2] + "' config in '" + lstPara[1] + "' of " + strFileName + " file!", "CommonFunctionID002() error");
                return("Error: fail to read file"); //Getting key value fail
            }

            //If everything is OK, the create a User Return structure
            lstobjTemp = new List <object>();
            lstobjTemp.Add("ReadIni");
            lstobjTemp.Add(strTmp);
            lstlstobjOutput.Add(lstobjTemp);

            //Decide what to return
            string strOptReturn = "";

            strOptReturn = lstlstobjInput[0][17].ToString().Trim().ToUpper();
            if (strOptReturn == "1") //Convert to numeric and return
            {
                double dblRet;
                if (double.TryParse(strTmp, out dblRet) == false)
                {
                    return("Error: cannot convert " + strTmp + "to numeric.");
                }
                return(strTmp); //If OK, then return result
            }

            return("0"); //if everything ok, return OK code "0"
        }
コード例 #7
0
ファイル: clsSavingData.cs プロジェクト: Quanghai32/CFP
        public void RecordTestData()
        {
            // "Item No" - "PreInfo 1" - ... - "PreInfo n" - "Time" - "Result" - "Error Message" - "Step 1" - ...."Step n" - "AfterInfo 1" - ... - "AfterInfo n"

            //Before saving data, checking needing create new file or not (when enter a new day)
            //Each day create 1 csv file to store checking data if not exist
            //   File format: "Year_Month_Date.csv" . Example: 2014_9_6.csv
            string   strDataFileName = "";
            DateTime _Now            = DateTime.Now;

            strDataFileName = _Now.Year.ToString() + "_" + _Now.Month.ToString() + "_" + _Now.Day.ToString() + ".csv";

            string strDataFileFullName = this.strDataSavePath + @"\" + strDataFileName;
            var    clsTemp             = new nspFileHandle.ChkExist();

            if (clsTemp.CheckFileExist(strDataFileFullName) == false) //Need to create new file
            {
                //Create new file
                File.Create(strDataFileFullName).Close();
                //Create header for file
                CreateFileHeader(strDataFileFullName);
            }
            //Start to saving data
            int    i                 = 0;
            int    j                 = 0;
            int    intTemp           = 0;
            string strItemRecordData = "";

            for (i = 0; i < this.lstChildProcessModel.Count; i++)
            {
                strItemRecordData = "";
                //PC Info
                strItemRecordData = strItemRecordData + strPCName + ",";
                strItemRecordData = strItemRecordData + strIPAddress + ",";
                strItemRecordData = strItemRecordData + strMacAddress + ",";

                //Item Number
                strItemRecordData = strItemRecordData + "Item" + (i + 1).ToString() + ",";
                //PreInfo
                for (j = 0; j < this.lstChildProcessModel[i].lststrUserPreInfo.Count; j++)
                {
                    strItemRecordData = strItemRecordData + this.lstChildProcessModel[i].lststrUserPreInfo[j].Replace(",", ";") + ",";
                }
                //Checking Time
                strItemRecordData = strItemRecordData + _Now.ToString() + ",";
                //Checking Result
                string strResult = "";
                if (this.lstChildProcessModel[i].clsItemInfo.blItemCheckingResult == true)
                {
                    strResult         = "PASS";
                    strItemRecordData = strItemRecordData + strResult + ",";
                    //Error Message (Clear if PASS)
                    strItemRecordData = strItemRecordData + "" + ",";
                    //If result is PASS, then record all step
                    for (j = 0; j < this.lstChildProcessModel[i].lstChildTotal.Count; j++)
                    {
                        if (this.lstChildProcessModel[i].lstChildTotal[j].strUnitName.ToUpper() != "H") //Not Hexa format
                        {
                            strItemRecordData = strItemRecordData + this.lstChildProcessModel[i].clsItemInfo.lstdblStepCheckingData[j].ToString() + ",";
                        }
                        else //Hexa format
                        {
                            //Try to convert to Hexa format
                            if (int.TryParse(Math.Round(this.lstChildProcessModel[i].clsItemInfo.lstdblStepCheckingData[j], 0).ToString(), out intTemp) == true) //Integer => can convert to hexa
                            {
                                strItemRecordData = strItemRecordData + intTemp.ToString("X") + ",";
                            }
                            else
                            {
                                strItemRecordData = strItemRecordData + "Error: cannot convert to Hexa [" + this.lstChildProcessModel[i].clsItemInfo.lstdblStepCheckingData[j].ToString() + "],";
                            }
                        }
                    }
                }
                else
                {
                    strResult         = "FAIL";
                    strItemRecordData = strItemRecordData + strResult + ",";
                    //Error Message (Record if FAIL)
                    string strErrMsg = "";
                    //Looking for error message
                    for (j = 0; j < this.lstChildProcessModel[i].lstChildTotal.Count; j++)
                    {
                        int intStepPos = 0;
                        intStepPos = this.lstChildProcessModel[i].lstChildThreadCheck[j].intTestPos;
                        if ((this.lstChildProcessModel[i].clsItemInfo.lstblStepResult[intStepPos] == false) && (this.lstChildProcessModel[i].lstChildTotal[intStepPos].intTestClass == 3))
                        {
                            strErrMsg = "Step" + this.lstChildProcessModel[i].lstChildTotal[intStepPos].intTestNumber.ToString() + ": ";
                            strErrMsg = strErrMsg + this.lstChildProcessModel[i].clsItemInfo.lststrStepErrMsg[intStepPos];
                            strErrMsg = strErrMsg.Replace(",", ";");
                            break;
                        }
                    }
                    strItemRecordData = strItemRecordData + strErrMsg + ",";
                    //If result is FAIL, then record all pass step, until reach the first fail step
                    for (j = 0; j < this.lstChildProcessModel[i].lstChildTotal.Count; j++)
                    {
                        //strItemRecordData = strItemRecordData + Program.lstChkInfo[i].clsChildProcess.clsItemResult.lstdblStepCheckingData[j].ToString() + ",";

                        if (this.lstChildProcessModel[i].lstChildTotal[j].strUnitName.ToUpper() != "H") //Not Hexa format
                        {
                            strItemRecordData = strItemRecordData + this.lstChildProcessModel[i].clsItemInfo.lstdblStepCheckingData[j].ToString() + ",";
                        }
                        else //Hexa format
                        {
                            //Try to convert to Hexa format
                            if (int.TryParse(Math.Round(this.lstChildProcessModel[i].clsItemInfo.lstdblStepCheckingData[j], 0).ToString(), out intTemp) == true) //Integer => can convert to hexa
                            {
                                strItemRecordData = strItemRecordData + intTemp.ToString("X") + ",";
                            }
                            else
                            {
                                strItemRecordData = strItemRecordData + "Error: cannot convert to Hexa [" + this.lstChildProcessModel[i].clsItemInfo.lstdblStepCheckingData[j].ToString() + "],";
                            }
                        }


                        if ((this.lstChildProcessModel[i].clsItemInfo.lstblStepResult[j] == false) &&
                            (this.lstChildProcessModel[i].lstChildTotal[j].intTestClass == 3))
                        {
                            break;
                        }
                    }
                    //For all remaining step, just save "" (nothing) character
                    for (int k = j + 1; k < this.lstChildProcessModel[i].lstChildTotal.Count; k++)
                    {
                        strItemRecordData = strItemRecordData + "" + ",";
                    }
                }

                //AfterInfo
                for (j = 0; j < this.lstChildProcessModel[i].lststrUserAfterInfo.Count; j++)
                {
                    strItemRecordData = strItemRecordData + this.lstChildProcessModel[i].lststrUserAfterInfo[j].Replace(",", ";") + ",";
                }
                //Record to csv file
                AppendCsvFile(strDataFileFullName, strItemRecordData);

                //After saving data we have to clear all user Pre-Info & After-Info
                for (j = 0; j < this.lstChildProcessModel[i].lststrUserPreInfo.Count; j++)
                {
                    this.lstChildProcessModel[i].lststrUserPreInfo[j] = "";
                }

                for (j = 0; j < this.lstChildProcessModel[i].lststrUserAfterInfo.Count; j++)
                {
                    this.lstChildProcessModel[i].lststrUserAfterInfo[j] = "";
                }
            } //End for i
        }     //End RecordTestData() method