Esempio n. 1
0
        /// <summary>
        ///  执行SQL语句或存储过程,返回影响的行数 int
        /// </summary>
        /// <param name="procName">存储过程名</param>
        /// <param name="sqlParameters">存储过程参数</param>
        /// <returns>影响的行数,-1 执行失败</returns>
        public int ExecuteSql(string procName, SqlParameter[] sqlParameters)
        {
            int intValue = 0;

            //if (CheckIsKJ128A())
            //{
            //    SM.FuntionName = "ACCESS_ExecuteSql1";
            //    SM.parameter = new parameters[sqlParameters.Length];
            //    for (int i = 0; i < sqlParameters.Length; i++)
            //    {
            //        SM.parameter[i].ParameterName = sqlParameters[i].ParameterName;
            //        SM.parameter[i].ParameterType = sqlParameters[i].SqlDbType;
            //        SM.parameter[i].intLongth = sqlParameters[i].Size;
            //        SM.parameter[i].objValue = sqlParameters[i].Value;

            //    }
            //    SM.RestoryProcedureName = procName;

            //    if (SARO.DataReceived(SARO.SerialOperate(SM)))
            //    {
            //        intValue = 1;
            //    }
            //    else
            //    {
            //        intValue = -1;
            //    }

            //}
            //else
            //{
            intValue = NDA.ExecuteSql(procName, sqlParameters);
            //}

            return(intValue);
        }
        /// <summary>
        /// 反序列化
        /// </summary>
        /// <param name="RecieveData">接收到的流</param>
        /// <returns></returns>
        public bool DeserialOperate(byte[] RecieveData, bool bFlag)
        {
            int ComandTime=0;
            ArrayList Arraylist=null;
            string strContent = string.Empty; ;
            byte[] fs1=null;
            int intRows = 0;
            SqlConnection conn = new SqlConnection();
            string strErr = string.Empty;
            SqlParameter[] parameters=null;
            string strsql = string.Empty;
            if (bFlag)
            {
               // strsql = "server=.;database=KJ128N;uid=sa;pwd=sa;Timeout=5";
                strsql = GetConfigValue("ConnectionString").Trim();
            }
            else
            {
               // strsql = "server=.;database=KJ128NBackUp;uid=sa;pwd=sa;Timeout=5";
                strsql = GetConfigValue("ConnectionString").Trim();
            }
            File.WriteAllText(Application.StartupPath + "\\Conn.dw", strsql, Encoding.Default);

            string err = string.Empty;
            err = "";
            int intFlag = 0;
            bool Flag = false;
            string strDeserialPath = Application.StartupPath.ToString() + "\\DesialsData.dat";
            FileStream fs = File.Create(strDeserialPath);
            fs.Write(RecieveData, 2, RecieveData.Length - 2);
            fs.Close();
            fs.Dispose();

            Stream stream = new FileStream(strDeserialPath, FileMode.Open);
            BinaryFormatter bf = new BinaryFormatter();


            SerialModel sbc = (SerialModel)bf.Deserialize(stream);
            stream.Close();
            if (sbc.parameter != null)
            {
                parameters = new SqlParameter[sbc.parameter.Length];
                for (int i = 0; i < sbc.parameter.Length; i++)
                {
                    parameters[i] = new SqlParameter();
                    parameters[i].ParameterName = sbc.parameter[i].ParameterName;
                    parameters[i].SqlDbType = sbc.parameter[i].ParameterType;
                    parameters[i].Size = sbc.parameter[i].intLongth;
                    parameters[i].Value = sbc.parameter[i].objValue;
                }
            }
            if (sbc.ComandTime != 0)
            {
                ComandTime = sbc.ComandTime;
            }
            if (sbc.Arraylist != null)
            {
                Arraylist = sbc.Arraylist;
            }
            if (sbc.fs != null)
            {
                fs1 = sbc.fs;
            }
            if (sbc.strContent != null)
            {
                strContent = sbc.strContent;
            }

            New_DBAcess NDBA;
            New_DbHelperSQL NDH;
            switch (sbc.FuntionName)
            {
                case "ACCESS_ExecuteSql1":
                    NDBA = new New_DBAcess();
                    NDBA.ExecuteSql(sbc.RestoryProcedureName, parameters);
                    break;
                case "ACCESS_ExecuteSql2":
                    NDBA = new New_DBAcess();
                    NDBA.ExecuteSql(sbc.RestoryProcedureName, parameters, out strErr);
                    break;
                case "ACCESS_ExecuteSql3":
                    NDBA = new New_DBAcess();
                    NDBA.ExecuteSql(sbc.RestoryProcedureName, parameters, conn);
                    break;
                case "ACCESS_ExecuteSql4":
                    NDBA = new New_DBAcess();
                    NDBA.ExecuteSql(sbc.strSql, conn);
                    break;
                case "ACCESS_ExecuteSql5":
                    NDBA = new New_DBAcess();
                    NDBA.ExecuteSql(sbc.strSql);
                    break;
                case "ACCESS_ExecuteSql6":
                    NDBA = new New_DBAcess();
                    NDBA.ExistsSql(sbc.strSql);
                    break;
                case "Helper_ExecuteSql1":
                    NDH = new New_DbHelperSQL();
                    NDH.RunProcedureByInt64(sbc.RestoryProcedureName, parameters, out strErr);
                    break;
                case "Helper_ExecuteSql2":
                    NDH = new New_DbHelperSQL();
                    NDH.RunProcedureByInt(sbc.RestoryProcedureName, parameters, out strErr);
                    break;
                case "Helper_ExecuteSql3":
                    NDH = new New_DbHelperSQL();
                    NDH.RunProcedureByInt(sbc.RestoryProcedureName, out strErr);
                    break;
                case "Helper_ExecuteSql4":
                    NDH = new New_DbHelperSQL();
                    NDH.RunProcedureReturnInt(sbc.RestoryProcedureName, parameters, out strErr);
                    break;
                case "Helper_ExecuteSql5":
                    NDH = new New_DbHelperSQL();
                    NDH.ExecuteSql(sbc.strSql);
                    break;
                case "Helper_ExecuteSql6":
                    NDH = new New_DbHelperSQL();
                    NDH.ExecuteSqlByTime(sbc.strSql, ComandTime);
                    break;
                case "Helper_ExecuteSql7":
                    NDH = new New_DbHelperSQL();
                    NDH.ExecuteSqlTran(Arraylist);
                    break;
                case "Helper_ExecuteSql8":
                    NDH = new New_DbHelperSQL();
                    NDH.ExecuteSql(sbc.strSql, sbc.strContent);
                    break;
                case "Helper_ExecuteSql9":
                    NDH = new New_DbHelperSQL();
                    NDH.ExecuteSqlGet(sbc.strSql, sbc.strContent);
                    break;
                case "Helper_ExecuteSql10":
                    NDH = new New_DbHelperSQL();
                    NDH.ExecuteSqlInsertImg(sbc.strSql, fs1);
                    break;
                case "Helper_ExecuteSql11":
                    NDH = new New_DbHelperSQL();
                    NDH.ExecuteSql(sbc.strSql, parameters);
                    break;
                case "Helper_ExecuteSql12":
                    NDH = new New_DbHelperSQL();
                    NDH.RunProcedure(sbc.RestoryProcedureName, parameters, out intRows);
                    break;
                case "Helper_ExecuteSql13":
                    NDH = new New_DbHelperSQL();
                    NDH.RunProcedure(sbc.RestoryProcedureName);
                    break;
                default:
                    break;
            }

            if (intFlag != -1)
            {
                Flag = true;
            }
            else
            {
                Flag = false;
            }

            if (File.Exists(Application.StartupPath + "\\Conn.dw"))
            {
                File.Delete(Application.StartupPath + "\\Conn.dw");
            }
            return Flag;
        }
Esempio n. 3
0
        /// <summary>
        /// 反序列化
        /// </summary>
        /// <param name="RecieveData">接收到的流</param>
        /// <returns></returns>
        public bool DeserialOperate(byte[] RecieveData, bool bFlag)
        {
            int       ComandTime = 0;
            ArrayList Arraylist  = null;
            string    strContent = string.Empty;;

            byte[]        fs1     = null;
            int           intRows = 0;
            SqlConnection conn    = new SqlConnection();
            string        strErr  = string.Empty;

            SqlParameter[] parameters = null;
            string         strsql     = string.Empty;

            if (bFlag)
            {
                // strsql = "server=.;database=KJ128N;uid=sa;pwd=sa;Timeout=5";
                strsql = GetConfigValue("ConnectionString").Trim();
            }
            else
            {
                // strsql = "server=.;database=KJ128NBackUp;uid=sa;pwd=sa;Timeout=5";
                strsql = GetConfigValue("ConnectionString").Trim();
            }
            File.WriteAllText(Application.StartupPath + "\\Conn.dw", strsql, Encoding.Default);

            string err = string.Empty;

            err = "";
            int        intFlag         = 0;
            bool       Flag            = false;
            string     strDeserialPath = Application.StartupPath.ToString() + "\\DesialsData.dat";
            FileStream fs = File.Create(strDeserialPath);

            fs.Write(RecieveData, 2, RecieveData.Length - 2);
            fs.Close();
            fs.Dispose();

            Stream          stream = new FileStream(strDeserialPath, FileMode.Open);
            BinaryFormatter bf     = new BinaryFormatter();


            SerialModel sbc = (SerialModel)bf.Deserialize(stream);

            stream.Close();
            if (sbc.parameter != null)
            {
                parameters = new SqlParameter[sbc.parameter.Length];
                for (int i = 0; i < sbc.parameter.Length; i++)
                {
                    parameters[i] = new SqlParameter();
                    parameters[i].ParameterName = sbc.parameter[i].ParameterName;
                    parameters[i].SqlDbType     = sbc.parameter[i].ParameterType;
                    parameters[i].Size          = sbc.parameter[i].intLongth;
                    parameters[i].Value         = sbc.parameter[i].objValue;
                }
            }
            if (sbc.ComandTime != 0)
            {
                ComandTime = sbc.ComandTime;
            }
            if (sbc.Arraylist != null)
            {
                Arraylist = sbc.Arraylist;
            }
            if (sbc.fs != null)
            {
                fs1 = sbc.fs;
            }
            if (sbc.strContent != null)
            {
                strContent = sbc.strContent;
            }

            New_DBAcess     NDBA;
            New_DbHelperSQL NDH;

            switch (sbc.FuntionName)
            {
            case "ACCESS_ExecuteSql1":
                NDBA = new New_DBAcess();
                NDBA.ExecuteSql(sbc.RestoryProcedureName, parameters);
                break;

            case "ACCESS_ExecuteSql2":
                NDBA = new New_DBAcess();
                NDBA.ExecuteSql(sbc.RestoryProcedureName, parameters, out strErr);
                break;

            case "ACCESS_ExecuteSql3":
                NDBA = new New_DBAcess();
                NDBA.ExecuteSql(sbc.RestoryProcedureName, parameters, conn);
                break;

            case "ACCESS_ExecuteSql4":
                NDBA = new New_DBAcess();
                NDBA.ExecuteSql(sbc.strSql, conn);
                break;

            case "ACCESS_ExecuteSql5":
                NDBA = new New_DBAcess();
                NDBA.ExecuteSql(sbc.strSql);
                break;

            case "ACCESS_ExecuteSql6":
                NDBA = new New_DBAcess();
                NDBA.ExistsSql(sbc.strSql);
                break;

            case "Helper_ExecuteSql1":
                NDH = new New_DbHelperSQL();
                NDH.RunProcedureByInt64(sbc.RestoryProcedureName, parameters, out strErr);
                break;

            case "Helper_ExecuteSql2":
                NDH = new New_DbHelperSQL();
                NDH.RunProcedureByInt(sbc.RestoryProcedureName, parameters, out strErr);
                break;

            case "Helper_ExecuteSql3":
                NDH = new New_DbHelperSQL();
                NDH.RunProcedureByInt(sbc.RestoryProcedureName, out strErr);
                break;

            case "Helper_ExecuteSql4":
                NDH = new New_DbHelperSQL();
                NDH.RunProcedureReturnInt(sbc.RestoryProcedureName, parameters, out strErr);
                break;

            case "Helper_ExecuteSql5":
                NDH = new New_DbHelperSQL();
                NDH.ExecuteSql(sbc.strSql);
                break;

            case "Helper_ExecuteSql6":
                NDH = new New_DbHelperSQL();
                NDH.ExecuteSqlByTime(sbc.strSql, ComandTime);
                break;

            case "Helper_ExecuteSql7":
                NDH = new New_DbHelperSQL();
                NDH.ExecuteSqlTran(Arraylist);
                break;

            case "Helper_ExecuteSql8":
                NDH = new New_DbHelperSQL();
                NDH.ExecuteSql(sbc.strSql, sbc.strContent);
                break;

            case "Helper_ExecuteSql9":
                NDH = new New_DbHelperSQL();
                NDH.ExecuteSqlGet(sbc.strSql, sbc.strContent);
                break;

            case "Helper_ExecuteSql10":
                NDH = new New_DbHelperSQL();
                NDH.ExecuteSqlInsertImg(sbc.strSql, fs1);
                break;

            case "Helper_ExecuteSql11":
                NDH = new New_DbHelperSQL();
                NDH.ExecuteSql(sbc.strSql, parameters);
                break;

            case "Helper_ExecuteSql12":
                NDH = new New_DbHelperSQL();
                NDH.RunProcedure(sbc.RestoryProcedureName, parameters, out intRows);
                break;

            case "Helper_ExecuteSql13":
                NDH = new New_DbHelperSQL();
                NDH.RunProcedure(sbc.RestoryProcedureName);
                break;

            default:
                break;
            }

            if (intFlag != -1)
            {
                Flag = true;
            }
            else
            {
                Flag = false;
            }

            if (File.Exists(Application.StartupPath + "\\Conn.dw"))
            {
                File.Delete(Application.StartupPath + "\\Conn.dw");
            }
            return(Flag);
        }