Forráskód Böngészése

接口项目修改

callm 2 hónapja
szülő
commit
8245a0d036

+ 1189 - 0
TestProject/DataHelper.cs

@@ -0,0 +1,1189 @@
+using Oracle.ManagedDataAccess.Client;
+using System;
+using System.Data;
+using System.Text;
+using System.Collections;
+using System.Collections.Generic;
+
+namespace TestProject
+{
+    public class DataHelper
+    {
+
+        ////富为外网地址
+        //private readonly string ConnectionStrings = "Data Source=richwell.3322.org/orcl;User ID=DATACENTER;PassWord=select!#%*(";
+        //private readonly string InnerConnectionStrings = "Data Source=richwell.3322.org/orcl;User ID=DATACENTER;PassWord=select!#%*(";
+        ////富为ERP地址
+        //public static readonly string ERPAddesss = "http://richwellgroup.com.cn:8099/ERP/";
+        ////富为FTP
+        //public static readonly string FTPAdress = "ftp://richwell.3322.org|printuser|printuser";
+        ////Oracle端口
+        //public static readonly string OraclePort = "1521";
+        ////需要显示的账套
+        //public static readonly string Masters = "JDTSY,FW_JDT,N_DATACENTER,FY_TEST,JD_TEST,XY_TEST,FW_TEST,DATACENTER,FW,XY,FY";
+
+
+        ////怡海能达外网地址
+        private readonly string ConnectionStrings = "Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=MES_ZZ;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=117.25.180.218)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
+
+        private readonly string InnerConnectionStrings = "Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=DATACENTER;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.1.200)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
+
+        //怡海能达ERP地址
+        public static readonly string ERPAddesss = "http://sz.hi-mantech.com:8099/ERP/";
+        //怡海能达FTP
+        public static readonly string FTPAdress = "ftp://sz.hi-mantech.com:46688|yhndftp|Stga28ytG8";
+        //Oracle端口
+        public static readonly string OraclePort = "1521";
+        //需要显示的账套
+        public static readonly string Masters = "YHND_SZ,YHND_HK,DATACENTER,YITOA_ZX,T_YHND_HK";
+
+        public static string DBConnectionString;
+        static OracleConnection connection = null;
+        static OracleCommand command = null;
+        /// <summary>
+        /// 重置连接的次数
+        /// </summary>
+        int ReconnectTime = 0;
+        /// <summary>
+        /// 执行构造函数的时候打开数据库的链接
+        /// </summary>
+        public DataHelper()
+        {
+            try
+            {
+                //如果选择的是默认数据则直接用配置文件的信息连接,否则选择数据库的账套信息
+                if (DBConnectionString == null || DBConnectionString == ConnectionStrings)
+                {
+                    DBConnectionString = ConnectionStrings;
+                    try
+                    {
+                        connection = new OracleConnection(ConnectionStrings);
+                        connection.Open();
+                    }
+                    catch (Exception)
+                    {
+                        connection = new OracleConnection(InnerConnectionStrings);
+                        connection.Open();
+                    }
+                }
+                else
+                {
+                    connection = new OracleConnection(DBConnectionString);
+                    connection.Open();
+                }
+              
+            }
+            catch (Exception e) {}
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        public void Dispose()
+        {
+            connection.Dispose();
+        }
+
+        /// <summary>
+        /// 根据表名获取该表字段数据类型
+        /// </summary>
+        public DataTable GetColumnDataType(string TableName)
+        {
+            DataTable dt = new DataTable();
+            command = new OracleCommand("select Column_Name,Data_Type from cols where TABLE_name=upper('" + TableName + "')", connection);
+            OracleDataAdapter ad = new OracleDataAdapter(command);
+            ad.Fill(dt);
+            ad.Dispose();
+            command.Dispose();
+            return dt;
+        }
+
+        public object GetLabelParam(string sql)
+        {
+            DataTable dt = new DataTable();
+            command = new OracleCommand(sql, connection);
+            OracleDataAdapter ad = new OracleDataAdapter();
+            ad.SelectCommand = command;
+            ad.Fill(dt);
+            if (dt.Rows.Count > 0)
+            {
+                ad.Dispose();
+                command.Dispose();
+                return dt.Rows[0][0];
+            }
+            else { command.Dispose(); return ""; }
+        }
+
+        /// <summary>
+        /// 获取第一行第一列的信息
+        /// </summary>
+        public object getFieldDataByCondition(string TableName, string Field, string Condition)
+        {
+            DataTable dt = new DataTable();
+            string sql = "select " + Field + " from " + TableName + " where " + Condition;
+            command = new OracleCommand(sql, connection);
+            OracleDataAdapter ad = new OracleDataAdapter();
+            ad.SelectCommand = command;
+            try
+            {
+                ad.Fill(dt);
+                ReconnectTime = 0;
+            }
+            catch (Exception)
+            {
+                if (ReconnectTime == 0)
+                {
+                    ReconnectTime++;
+                    connection = new OracleConnection(DBConnectionString);
+                    //成功执行后将重复连接数置为0
+                    dt = (DataTable)getFieldDataByCondition(TableName, Field, Condition);
+                }
+            }
+
+            if (dt.Rows.Count > 0)
+            {
+                ad.Dispose();
+                command.Dispose();
+                return dt.Rows[0][0];
+            }
+            else
+            {
+                ad.Dispose();
+                command.Dispose();
+                return "";
+            }
+        }
+
+        /// <summary>
+        /// 执行打印的SQL
+        /// </summary>
+        /// <param name="SQL">SQL语句</param>
+        /// <param name="Parameters">动态添加的参数,主要根据条码枪扫描获取</param>
+        /// <returns></returns>
+        public object ExecutePrintSQL(string SQL, params string[] Parameters)
+        {
+            //按照?拆分数据,然后以:Param替换问号,同时添加参数
+            string[] Param = SQL.Split('?');
+            int ParamNum = Param.Length - 1;
+            //条码打印必然存在需要维护的参数
+            if (ParamNum > 0)
+            {
+                StringBuilder sb = new StringBuilder();
+                for (int i = 0; i < ParamNum; i++)
+                {
+                    sb.Append(Param[i] + ":Param" + i);
+                }
+                command = new OracleCommand(sb.ToString(), connection);
+
+                for (int i = 0; i < ParamNum; i++)
+                {
+                    command.Parameters.Add("Param" + i, OracleDbType.Varchar2, Parameters[i], ParameterDirection.Input);
+                }
+
+                OracleDataAdapter ad = new OracleDataAdapter(command);
+                DataTable dt = new DataTable();
+                ad.Fill(dt);
+                ad.Dispose();
+                command.Dispose();
+                return dt;
+            }
+            return "参数错误,请检查SQL语句";
+        }
+
+        /// <summary>
+        /// 获取指定表的记录的条数 ,带条件
+        /// </summary>
+        /// <returns></returns>
+        public int getRowCount(string TableName, string Condition)
+        {
+            DataTable dt = new DataTable();
+            string sql = "select count(1) from " + TableName + " where " + Condition;
+            command = new OracleCommand(sql, connection);
+            OracleDataAdapter ad = new OracleDataAdapter(command);
+            ad.Fill(dt);
+            int count = int.Parse(dt.Rows[0][0].ToString());
+            command.Dispose();
+            return count;
+        }
+
+        /// <summary>
+        /// 获取指定表的记录的条数 ,不带条件
+        /// </summary>
+        /// <param name="TableName"></param>
+        /// <returns></returns>
+        public int getRowCount(string TableName)
+        {
+            DataTable dt = new DataTable();
+            string sql = "select count(1) from " + TableName;
+            command = new OracleCommand(sql, connection);
+            OracleDataAdapter ad = new OracleDataAdapter(command);
+            ad.Fill(dt);
+            int count = int.Parse(dt.Rows[0][0].ToString());
+            command.Dispose();
+            return count;
+        }
+
+        /// <summary>
+        /// 通过表名和获取单行的记录
+        /// </summary>
+        public DataTable getFieldsDataByCondition(string TableName, string[] Fields, string Condition)
+        {
+            DataTable dt = new DataTable();
+            string sql = "select ";
+            sql += AddField(Fields);
+            sql += " from " + TableName + " where " + Condition + " and rownum=1";
+            command = new OracleCommand(sql, connection);
+            OracleDataAdapter ad = new OracleDataAdapter(command);
+            ad.Fill(dt);
+            command.Dispose();
+            return dt;
+        }
+
+        /// <summary>
+        /// 通过表名和获取单行的记录
+        /// </summary>
+        public DataTable getFieldsDatasByCondition(string sql)
+        {
+            Console.WriteLine(sql);
+            DataTable dt = new DataTable();
+            command = new OracleCommand(sql, connection);
+            OracleDataAdapter ad = new OracleDataAdapter(command);
+            ad.Fill(dt);
+            command.Dispose();
+            return dt;
+        }
+
+        /// <summary>
+        /// 将DataTable导入到指定的表中
+        /// </summary>
+        /// <param name="DataTable"></param>
+        /// <param name="TableName"></param>
+        public void InsertDataTable(DataTable DataTable, string TableName)
+        {
+            for (int i = 0; i < DataTable.Rows.Count; i++)
+            {
+                for (int j = 0; j < DataTable.Columns.Count; j++)
+                {
+
+                }
+            }
+        }
+
+        /// <summary>
+        /// 按分页获取数据
+        /// </summary>
+        /// <param name="TableName">表名</param>
+        /// <param name="Fields">查询字段</param>
+        /// <param name="CurrentPage">当前页面</param>
+        /// <param name="PageSize">页面展示条数</param>
+        /// <param name="Caller"></param>
+        /// <returns></returns>
+        // SELECT * FROM (SELECT   A.*  FROM (SELECT* FROM datalist) A WHERE ROWNUM <= 50) WHERE ROWNUM >= 21
+        public DataTable getFieldsDatasByPageing(string TableName, string Fields, int CurrentPage, int PageSize, string Caller, params string[] condition)
+        {
+            DataTable dt = new DataTable();
+            StringBuilder sql = new StringBuilder();
+            //先查询出配置出去的列
+            //获取查询的列
+            string[] caption = GetCaptionFromField(Fields);
+            //获取对应列的描述
+            string[] field = GetField(Fields);
+            sql.Append(" select * from (select RowNum RN, A.* from (select ");
+            sql.Append(AddField(caption));
+            if (condition.Length > 0)
+            {
+                if (condition[0].Trim() != "")
+                {
+                    sql.Append(" from " + TableName + " where " + condition[0] + " ) A where ROWNUM <=" + CurrentPage * PageSize + ") where RN>" + (CurrentPage - 1) * PageSize);
+                }
+                else
+                {
+                    sql.Append(" from " + TableName + ") A where ROWNUM <= " + CurrentPage * PageSize + ") where RN> " + (CurrentPage - 1) * PageSize);
+                }
+            }
+            command = new OracleCommand(sql.ToString(), connection);
+            OracleDataAdapter ad = new OracleDataAdapter(command);
+            ad.Fill(dt);
+            dt.Columns.RemoveAt(0);
+            foreach (DataColumn dc in dt.Columns)
+            {
+                dc.ColumnName = field[dt.Columns.IndexOf(dc)];
+                dc.Caption = caption[dt.Columns.IndexOf(dc)];
+            }
+            command.Dispose();
+            return dt;
+        }
+
+        /// <summary>
+        /// 通过表名,字段和条件获取DataTable类型的数据
+        /// </summary>
+        public DataTable getFieldsDatasByCondition(string TableName, string[] Fields, string Condition)
+        {
+            DataTable dt = new DataTable();
+            string sql = "select ";
+            sql += AddField(Fields);
+            sql += " from " + TableName + " where " + Condition;
+            command = new OracleCommand(sql, connection);
+            OracleDataAdapter ad = new OracleDataAdapter(command);
+            ad.Fill(dt);
+            command.Dispose();
+            return dt;
+        }
+
+        /// <summary>
+        /// 通过表名,字段获取DataTable类型的数据
+        /// </summary>
+        public string[] getFieldsDatas(string TableName, string Fields)
+        {
+            ArrayList arr = new ArrayList();
+            DataTable dt = new DataTable();
+            string sql = "select ";
+            sql += Fields;
+            sql += " from " + TableName;
+            command = new OracleCommand(sql, connection);
+            OracleDataAdapter ad = new OracleDataAdapter(command);
+            ad.SelectCommand = command;
+            ad.Fill(dt);
+            foreach (DataRow dc in dt.Rows)
+            {
+                arr.Add(dc[Fields]);
+            }
+            ad.Dispose();
+            command.Dispose();
+            return (string[])arr.ToArray(typeof(string));
+        }
+
+        /// <summary>
+        /// 通过表名,字段获取DataTable类型的数据
+        /// </summary>
+        public string[] getFieldsDatas(string TableName, string Fields, string Condition)
+        {
+            ArrayList arr = new ArrayList();
+            DataTable dt = new DataTable();
+            string sql = "select ";
+            sql += Fields;
+            sql += " from " + TableName + " where " + Condition;
+            command = new OracleCommand(sql, connection);
+            OracleDataAdapter ad = new OracleDataAdapter(command);
+            ad.SelectCommand = command;
+            ad.Fill(dt);
+            foreach (DataRow dc in dt.Rows)
+            {
+                arr.Add(dc[Fields]);
+            }
+            ad.Dispose();
+            command.Dispose();
+            return (string[])arr.ToArray(typeof(string));
+        }
+
+        /// <summary>
+        /// 根据DataTable和指定的表名更新数据,如果需要保存新增的数据则需要传递一条Insert的SQL
+        /// </summary>
+        /// <param name="DataTable"></param>
+        /// <param name="TableName"></param>
+        /// <param name="Condition"></param>
+        public void UpDateTableByCondition(DataTable DataTable, string TableName, string PrimaryKey, params string[] sql)
+        {
+            if (DataTable == null)
+            {
+                return;
+            }
+            StringBuilder sb = new StringBuilder();
+            //预防插入的DataTable中存在不属于该表的列,在进行下一步操作之前全部剔除
+            DataTable data = (DataTable)ExecuteSql("select Column_Name,Data_Type from cols where TABLE_name=upper('" + TableName + "')", "select");
+            //将所有的字段拼接起来
+            for (int i = 0; i < data.Rows.Count; i++)
+            {
+                sb.Append("#" + data.Rows[i]["Column_Name"].ToString());
+            }
+            //移除掉所有不属于该表的列
+            for (int i = DataTable.Columns.Count - 1; i >= 0; i--)
+            {
+                if (!sb.ToString().Contains(DataTable.Columns[i].ColumnName.ToUpper()))
+                {
+                    DataTable.Columns.RemoveAt(i);
+                }
+            }
+            sb.Clear();
+            //计算有多少个是新加的行,根据主键为空来进行判断
+            int NewRowCount = 0;
+            for (int i = 0; i < DataTable.Rows.Count; i++)
+            {
+                if (DataTable.Rows[i][PrimaryKey] == null || DataTable.Rows[i][PrimaryKey].ToString() == "")
+                {
+                    NewRowCount = NewRowCount + 1;
+                }
+            }
+            if (sql.Length > 0)
+            {
+                if (NewRowCount > 0)
+                {
+                    //获取参数的个数
+                    int paramsNum = sql[0].Split(':').Length - 1;
+
+                    //解析参数的数据
+                    string[] param = GetParamFromSQL(sql[0]);
+                    //新建一个二维数组去
+                    string[][] param_array = new string[paramsNum][];
+                    //实例化每个一维数组
+                    for (int i = 0; i < paramsNum; i++)
+                    {
+                        param_array[i] = new string[NewRowCount];
+                    }
+                    //设置每列参数的索引
+                    int num = 0;
+                    //变量所有的行,如果有主键为空的则移除,不为空的进行参数的拼接
+                    for (int i = DataTable.Rows.Count - 1; i >= 0; i--)
+                    {
+                        if (DataTable.Rows[i][PrimaryKey] == null || DataTable.Rows[i][PrimaryKey].ToString() == "")
+                        {
+                            //当为新添加行的时候才去设置参数,设置过后索引+1
+                            for (int j = 0; j < paramsNum; j++)
+                            {
+                                param_array[j][num] = DataTable.Rows[i][param[j]].ToString();
+                            }
+                            DataTable.Rows.RemoveAt(i);
+                            num++;
+                        }
+                    }
+                    BatchInsertDataTable(sql[0], param, param_array);
+                }
+            }
+            //不是新增行的启用更新的方法
+            sb.Append("update " + TableName + " set ");
+            //拼接语句,特殊处理日期
+            foreach (DataColumn dc in DataTable.Columns)
+            {
+                if (!dc.DataType.ToString().Equals("System.DateTime"))
+                {
+                    sb.Append(dc.Caption + "=:" + dc.Caption + ",");
+                }
+                else
+                {
+                    sb.Append(dc.Caption + "=:" + dc.Caption + ",");
+                }
+            }
+            sb.Remove(sb.Length - 1, 1);
+            sb.Append(" where " + PrimaryKey + "=:" + PrimaryKey);
+            command = new OracleCommand(sb.ToString(), connection);
+            OracleDataAdapter ad = new OracleDataAdapter(command);
+
+            // 参数的长度是DataTable的行数决定的
+            command.ArrayBindCount = DataTable.Rows.Count;
+            //默认全部是Varchar2类型的
+            OracleDbType ob = OracleDbType.Varchar2;
+            for (int i = 0; i < DataTable.Columns.Count; i++)
+            {
+                object[] param = new object[DataTable.Rows.Count];
+                for (int j = 0; j < DataTable.Rows.Count; j++)
+                {
+                    DateTime dt = DateTime.Now;
+                    //if (DateTime.TryParse(DataTable.Rows[j][i].ToString(), out dt))
+                    //{
+                    //    param[j] = dt;
+                    //    ob = OracleDbType.Date;
+                    //}
+                    //else
+                    //{
+                    ob = OracleDbType.Varchar2;
+                    param[j] = DataTable.Rows[j][i];
+                    //}
+                }
+                //添加批量更新的参数
+                command.Parameters.Add(new OracleParameter(DataTable.Columns[i].Caption, ob, param, ParameterDirection.Input));
+            }
+            ad.UpdateCommand = command;
+            ad.Update(DataTable);
+            command.Dispose();
+            ad.Dispose();
+        }
+
+        public void SaveDataTable(DataTable dt, string TableName, string ID, params string[] sql)
+        {
+            if (dt == null)
+            {
+                return;
+            }
+            StringBuilder sb = new StringBuilder();
+            //预防插入的DataTable中存在不属于该表的列,在进行下一步操作之前全部剔除
+            DataTable data = (DataTable)ExecuteSql("select Column_Name,Data_Type from cols where TABLE_name=upper('" + TableName + "')", "select");
+            //将所有的字段拼接起来
+            for (int i = 0; i < data.Rows.Count; i++)
+            {
+                sb.Append("#" + data.Rows[i]["Column_Name"].ToString());
+            }
+            //移除掉所有不属于该表的列
+            for (int i = dt.Columns.Count - 1; i >= 0; i--)
+            {
+                if (!sb.ToString().Contains(dt.Columns[i].ColumnName.ToUpper()))
+                {
+                    dt.Columns.RemoveAt(i);
+                }
+            }
+            sb.Clear();
+            //计算有多少个是新加的行,根据主键为空来进行判断
+            int NewRowCount = 0;
+            for (int i = 0; i < dt.Rows.Count; i++)
+            {
+                if (dt.Rows[i][ID] == null || dt.Rows[i][ID].ToString() == "")
+                {
+                    NewRowCount = NewRowCount + 1;
+                }
+            }
+            if (sql.Length > 0)
+            {
+                if (NewRowCount > 0)
+                {
+                    //获取参数的个数
+                    int paramsNum = sql[0].Split(':').Length - 1;
+
+                    //解析参数的数据
+                    string[] param = GetParamFromSQL(sql[0]);
+                    //新建一个二维数组去
+                    string[][] param_array = new string[paramsNum][];
+                    //实例化每个一维数组
+                    for (int i = 0; i < paramsNum; i++)
+                    {
+                        param_array[i] = new string[NewRowCount];
+                    }
+                    //设置每列参数的索引
+                    int num = 0;
+                    //变量所有的行,如果有主键为空的则移除,不为空的进行参数的拼接
+                    for (int i = dt.Rows.Count - 1; i >= 0; i--)
+                    {
+                        if (dt.Rows[i][ID] == null || dt.Rows[i][ID].ToString() == "")
+                        {
+                            //当为新添加行的时候才去设置参数,设置过后索引+1
+                            for (int j = 0; j < paramsNum; j++)
+                            {
+                                param_array[j][num] = dt.Rows[i][param[j]].ToString();
+                            }
+                            dt.Rows.RemoveAt(i);
+                            num++;
+                        }
+                    }
+                    BatchInsertDataTable(sql[0], param, param_array);
+                }
+            }
+            sb.Clear();
+            sb.Append("update " + TableName + " set ");
+            int ColumnCount = dt.Columns.Count;
+            int RowCount = dt.Rows.Count;
+            //存数据的参数
+            List<string[]> Parameter = new List<string[]>();
+            //存参数名的参数
+            string[] ParName = new string[ColumnCount];
+            for (int i = 0; i < ColumnCount; i++)
+            {
+                ParName[i] = dt.Columns[i].ColumnName;
+                if (i == dt.Columns.Count - 1)
+                    sb.Append(dt.Columns[i].ColumnName + "=:" + dt.Columns[i].ColumnName);
+                else
+                    sb.Append(dt.Columns[i].ColumnName + "=:" + dt.Columns[i].ColumnName + ",");
+            }
+            sb.Append(" where " + ID + " =:" + ID);
+            //先添加参数
+            Parameter.Add(ParName);
+            //添加参数的具体内容
+            for (int i = 0; i < ColumnCount; i++)
+            {
+                string[] par = new string[RowCount];
+                for (int j = 0; j < RowCount; j++)
+                {
+                    par[j] = dt.Rows[j][i].ToString();
+                }
+                Parameter.Add(par);
+            }
+            BatchInsert(sb.ToString(), Parameter.ToArray());
+        }
+
+        /// <summary>
+        /// 获取DbFind的数据的DataTable的结构
+        /// </summary>
+        /// <param name="field"></param>
+        /// <param name="caller"></param>
+        /// <returns></returns>
+        public DataTable GetDbFindDataTable(string field, string caller)
+        {
+            string sql = "select * from dbfindsetui where ds_caller='" + caller + "' and ds_whichui='" + field + "'";
+            DataTable dt = (DataTable)ExecuteSql(sql, "select");
+            if (dt.Rows.Count != 0)
+            {
+                //通过#号分割字段
+                string[] dbfield = dt.Rows[0]["ds_findtoui"].ToString().Split('#');
+                string[] cnfield = dt.Rows[0]["ds_dbcaption"].ToString().Split('#');
+                //获取查询要查询的Table
+                string dbtable = dt.Rows[0]["ds_tables"].ToString();
+                //拼接查询的字段
+                for (int i = 0; i < dbfield.Length; i++)
+                {
+                    dbfield[i] = dbfield[i].Split(',')[0];
+                }
+                //新建一个空的DataTable
+                DataTable dt1 = new DataTable();
+                //往空的DataTable添加结构,ColumnName是中文,Caption是实际的字段名称
+                for (int i = 0; i < cnfield.Length; i++)
+                {
+                    dt1.Columns.Add(cnfield[i]);
+                    dt1.Columns[i].Caption = dbfield[i];
+                }
+                //返回一个带有结构的空的DataTable
+                // DbFind.BindTable1 = dbtable;
+                return dt1;
+            }
+            else
+            {
+                return null;
+            }
+        }
+
+        /// <summary>
+        ///  获取配置列表中的数据,支持DaatList,Form,DetailGrid
+        /// </summary>
+        /// <param name="Caller"></param>
+        /// <param name="Type"></param>
+        /// <param name="condition"></param>
+        /// <returns></returns>
+        public DataTable GetConfigureData(string Caller, string Type, string condition)
+        {
+            DataTable dt = new DataTable();
+            //用于拼接SQL语句
+            StringBuilder Sql = new StringBuilder();
+            //用于设置不同Type时设置对应表的字段
+            string getField = "";
+            string getCaption = "";
+            string getTable = "";
+            switch (Type.ToUpper())
+            {
+                case "DATALIST":
+                    getField = "dld_field"; getCaption = "dld_caption"; getTable = "dld_table";
+                    Sql.Append("select * from datalistdetail where dld_caller='" + Caller + "'");
+                    break;
+                case "FORM":
+                    getField = "fd_field"; getCaption = "fd_caption"; getTable = "fd_table";
+                    Sql.Append("select * from formdetail where fd_foid=( select fo_id from form where fo_caller='" + Caller + "')");
+                    break;
+                case "DETAILGRID":
+                    getField = "dg_field"; getCaption = "dg_caption"; getTable = "dg_table";
+                    Sql.Append("select * from detailgrid  where dg_caller='" + Caller + "'");
+                    break;
+            }
+            command = new OracleCommand(Sql.ToString(), connection);
+            OracleDataAdapter ad = new OracleDataAdapter(command);
+            ad.Fill(dt);
+            //清除掉之前的内容重新拼接
+            Sql.Clear();
+            Sql.Append("select ");
+            string[] field = new string[dt.Rows.Count];
+            string[] caption = new string[dt.Rows.Count];
+            DataTable dt1 = new DataTable();
+            //记录描述和字段名称
+            foreach (DataRow dr in dt.Rows)
+            {
+                field[dt.Rows.IndexOf(dr)] = dr[getCaption].ToString();
+                caption[dt.Rows.IndexOf(dr)] = dr[getField].ToString();
+                Sql.Append(dr[getField] + ",");
+            }
+            //调用substring是为了去除之前拼接多出来的一个逗号
+            string sql = Sql.Remove(Sql.Length - 1, 1).ToString() + " from " + dt.Rows[0][getTable] + " where " + condition;
+            //调用一个新的构造DataTable用来存放返回的数据
+            dt1 = (DataTable)ExecuteSql(sql, "select");
+            //给DataTable加上列名和描述,列名是中文字段,描述是数据库实际的字段名称
+            for (int i = 0; i < field.Length; i++)
+            {
+                dt1.Columns[i].ColumnName = field[i];
+                dt1.Columns[i].Caption = caption[i];
+            }
+            //返回的第一条数据是SQL,后面的是实际的列名
+            command.Dispose();
+            return dt1;
+        }
+
+        /// <summary>
+        /// 查询配置的字段,Type是查询DataList,Form还是DetailGrid
+        /// </summary>
+        /// <param name="Caller"></param>
+        /// <param name="Type"></param>
+        /// <returns></returns>
+        public DataTable GetConfigureData(string Caller, string Type)
+        {
+            DataTable dt = new DataTable();
+            //用于拼接SQL语句
+            StringBuilder Sql = new StringBuilder();
+            //用于设置不同Type时设置对应表的字段
+            string getField = "";
+            string getCaption = "";
+            string getTable = "";
+            switch (Type.ToUpper())
+            {
+                case "DATALIST":
+                    getField = "dld_field"; getCaption = "dld_caption"; getTable = "dld_table";
+                    Sql.Append("select * from datalistdetail where dld_caller='" + Caller + "'");
+                    break;
+                case "FORM":
+                    getField = "fd_field"; getCaption = "fd_caption"; getTable = "fd_table";
+                    Sql.Append("select * from formdetail where fd_foid=( select fo_id from form where fo_caller='" + Caller + "')");
+                    break;
+                case "DETAILGRID":
+                    getField = "dg_field"; getCaption = "dg_caption"; getTable = "dg_table";
+                    Sql.Append("select * from detailgrid  where dg_caller='" + Caller + "'");
+                    break;
+            }
+            command = new OracleCommand(Sql.ToString(), connection);
+            OracleDataAdapter ad = new OracleDataAdapter(command);
+            ad.Fill(dt);
+            //清除掉之前的内容重新拼接
+            Sql.Clear();
+            Sql.Append("select ");
+            //用于记录实际的列名,+1的目的是为了存放SQL
+            string[] field = new string[dt.Rows.Count];
+            string[] caption = new string[dt.Rows.Count];
+            DataTable dt1 = new DataTable();
+            foreach (DataRow dr in dt.Rows)
+            {
+                field[dt.Rows.IndexOf(dr)] = dr[getCaption].ToString();
+                caption[dt.Rows.IndexOf(dr)] = dr[getField].ToString();
+                Sql.Append(dr[getField] + ",");
+            }
+            string sql = Sql.Remove(Sql.Length - 1, 1).ToString() + " from " + dt.Rows[0][getTable];
+            dt1 = (DataTable)ExecuteSql(sql, "select");
+            //设置DataTable的列名和描述
+            for (int i = 0; i < field.Length; i++)
+            {
+                dt1.Columns[i].ColumnName = field[i];
+                dt1.Columns[i].Caption = caption[i];
+            }
+            ad.Dispose();
+            command.Dispose();
+            return dt1;
+        }
+
+        /// <summary>
+        /// 检测内容是否存在
+        /// </summary>
+        /// <param name="TableName"></param>
+        /// <param name="Condition"></param>
+        /// <returns></returns>
+        public bool CheckExist(string TableName, string Condition)
+        {
+            string sql = "select count(1) from " + TableName + " where " + Condition;
+            command = new OracleCommand(sql, connection);
+            OracleDataAdapter ad = new OracleDataAdapter(command);
+            DataTable dt = new DataTable();
+            ad.Fill(dt);
+            if (int.Parse(dt.Rows[0][0].ToString()) > 0)
+            {
+                command.Dispose();
+                ad.Dispose();
+                return true;
+            }
+            else
+            {
+                command.Dispose();
+                ad.Dispose();
+                return false;
+            }
+        }
+
+        /// <summary>
+        /// 直接执行SQL,同时传入SQL的类型
+        /// </summary>
+        /// <param name="SQL"></param>
+        /// <param name="Type"></param>
+        /// <returns></returns>
+        public object ExecuteSql(string SQL, string Type, params object[] names)
+        {
+            object result = null;
+            command = new OracleCommand(SQL, connection);
+            //用来拼接参数的
+            if (names.Length > 0)
+            {
+                string[] par = SQL.Split(':');
+                //用来存参数的数组
+                StringBuilder[] addpar = new StringBuilder[par.Length - 1];
+                for (int i = 0; i < par.Length - 1; i++)
+                {
+                    //新建一个char类型的数组用来存储每个字节的变量
+                    char[] c = par[i + 1].ToCharArray();
+                    addpar[i] = new StringBuilder();
+                    for (int j = 0; j < c.Length; j++)
+                    {
+                        if (c[j] != ' ' && c[j] != ',' && c[j] != ')')
+                        {
+                            addpar[i].Append(c[j]);
+                        }
+                        else
+                        {
+                            break;
+                        }
+                    }
+                }
+                for (int i = 0; i < addpar.Length; i++)
+                {
+                    command.Parameters.Add(new OracleParameter(addpar[i].ToString(), OracleDbType.Varchar2, names[i], ParameterDirection.Input));
+                }
+            }
+            switch (Type.ToUpper())
+            {
+                case "SELECT":
+                    OracleDataAdapter ad = new OracleDataAdapter(command);
+                    result = new DataTable();
+                    try
+                    {
+                        ad.Fill((DataTable)result);
+                    }
+                    catch (Exception)
+                    {
+                        connection = new OracleConnection(DBConnectionString);
+                        connection.Open();
+                        command = new OracleCommand(SQL, connection);
+                        ad = new OracleDataAdapter();
+                        ad.SelectCommand = command;
+                        ad.Fill((DataTable)result);
+                    }
+                    //成功执行后将重复连接数置为0
+                    break;
+                case "DELETE":
+                    result = command.ExecuteNonQuery();
+                    break;
+                case "UPDATE":
+                    result = command.ExecuteNonQuery();
+                    break;
+                case "INSERT":
+                    command.ExecuteNonQuery();
+                    break;
+            }
+
+            command.Dispose();
+            return result;
+        }
+
+        /// <summary>
+        /// 为了同步BS端的条码维护,检测时允许问号的存在,在检测时默认将问号换成:Param参数
+        /// </summary>
+        /// <param name="SQL"></param>
+        public bool CheckSQL(string SQL, out string ErrorMessage)
+        {
+            ErrorMessage = "";
+            try
+            {
+                SQL = SQL.Replace("?", ":Param");
+                command = new OracleCommand(SQL, connection);
+                command.ExecuteNonQuery();
+                command.Dispose();
+                return true;
+            }
+            catch (Exception e)
+            {
+                command.Dispose();
+                ErrorMessage = e.Message;
+                return false;
+            }
+        }
+
+
+
+        public int GetDistinctRowCount(string TableName, string Field)
+        {
+            DataTable dt = new DataTable();
+            string sql = "select distinct count('" + Field + "') from " + TableName;
+            OracleDataAdapter ad = new OracleDataAdapter(new OracleCommand(sql, connection));
+            ad.Fill(dt);
+            command.Dispose();
+            return int.Parse(dt.Rows[0][0].ToString());
+        }
+
+        /// <summary>
+        /// 根据Caller获取流水号
+        /// </summary>
+        /// <param name="Caller"></param>
+        /// <returns></returns>
+        public string GetSerialNumberByCaller(string Caller)
+        {
+            string SerialNumber = getFieldDataByCondition("MaxNumbers", "mn_number", "mn_tablename='" + Caller + "'").ToString();
+            UpdateByCondition("MaxNumbers", "mn_number=mn_number+1", "mn_tablename='" + Caller + "'");
+            return SerialNumber;
+        }
+
+        /// <summary>
+        /// 根据主键ID删除表的数据
+        /// </summary>
+        /// <param name="TableName">表名</param>
+        /// <param name="ID">主键</param>
+        /// <param name="DeleteID">需要删除主键ID的数组</param>
+        public void DeleteDataByID(string TableName, string ID, string[] DeleteID)
+        {
+            string sql = "delete from " + TableName + " where " + ID + " =:DeleteID";
+            command = new OracleCommand(sql, connection);
+            command.ArrayBindCount = DeleteID.Length;
+            command.Parameters.Add(new OracleParameter("DeleteID", OracleDbType.Long, DeleteID, ParameterDirection.Input));
+            command.ExecuteNonQuery();
+            command.Dispose();
+        }
+
+        /// <summary>
+        /// 通过序列的名称获取序列
+        /// </summary>
+        /// <param name="SeqName"></param>
+        /// <returns></returns>
+        public string GetSEQ(string SeqName)
+        {
+            DataTable dt = new DataTable();
+            dt = (DataTable)ExecuteSql("SELECT " + SeqName + ".NEXTVAL FROM DUAL", "select");
+            return dt.Rows[0][0].ToString();
+        }
+
+        /// <summary>
+        /// 批量通过SQL来执行插入操作 ,参数的第一个数一个string[]数组,用来传递需要添加的参数的名称
+        /// 之后的是名称参数数组对应的 ,所有的插入参数数据长度必须是一致的
+        /// </summary>
+        /// <param name="sql"></param>
+        /// <param name="names"></param>
+        public void BatchInsert(string sql, params object[][] names)
+        {
+            command = new OracleCommand(sql, connection);
+            command.ArrayBindCount = names[1].Length;
+            //因为第一个数组保存的是参数的名称,所以循环从1而不是0开始
+            //将第一个数组的下标固定为0作为循环添加的参数的名称
+            for (int i = 1; i <= names[0].Length; i++)
+            {
+                command.Parameters.Add(new OracleParameter(names[0][i - 1].ToString(), OracleDbType.Varchar2, names[i], ParameterDirection.Input));
+            }
+            command.ExecuteNonQuery();
+            command.Dispose();
+        }
+
+        public void BatchInsertDataTable(string sql, string[] param, params object[][] param1)
+        {
+            command = new OracleCommand(sql, connection);
+            command.ArrayBindCount = param1[0].Length;
+            //因为第一个数组保存的是参数的名称,所以循环从1而不是0开始
+            //将第一个数组的下标固定为0作为循环添加的参数的名称
+            for (int i = 0; i < param.Length; i++)
+            {
+                command.Parameters.Add(new OracleParameter(param[i].ToString(), OracleDbType.Varchar2, param1[i], ParameterDirection.Input));
+            }
+            command.ExecuteNonQuery();
+            command.Dispose();
+        }
+
+
+        /// <summary>
+        /// 查询DataList配置的字段
+        /// </summary>
+        /// <param name="TableName"></param>
+        /// <param name="Caller"></param>
+        /// <returns></returns>
+        public string GetDataList(string TableName, string Caller)
+        {
+            DataTable dt = new DataTable();
+            string SQL = " select listagg(dld_field,',') within group (order by dld_id)  from datalistdetail where dld_caller='" + Caller + "'";
+            command = new OracleCommand(SQL, connection);
+            OracleDataAdapter ad = new OracleDataAdapter(command);
+            ad.Fill(dt);
+            command.Dispose();
+            return dt.Rows[0][0].ToString();
+        }
+
+        /// <summary>
+        /// 取Configs表中的配置,进行该客户是否执行某个操作
+        /// </summary>
+        /// <param name="Code"></param>
+        /// <param name="Caller"></param>
+        /// <returns></returns>
+        public object GetConfig(string Code, string Caller)
+        {
+            DataTable dt = new DataTable();
+            string sql = "select * from configs where code='" + Code + "' and caller='" + Caller + "'";
+            dt = (DataTable)ExecuteSql(sql, "select");
+            if (dt.Rows.Count == 0)
+            {
+                return "";
+            }
+            else
+            {
+                return dt.Rows[0]["Data"];
+            }
+        }
+
+
+        //将数据类型的列类型转换为DataTable
+        public DataTable DataTypeColumnToDataTable(DataTable dt)
+        {
+            DataTable dt1 = new DataTable();
+            dt1.Rows.Add();
+            foreach (DataRow dr in dt.Rows)
+            {
+                dt1.Columns.Add(dr[0].ToString());
+                int index = dt.Rows.IndexOf(dr);
+                if (dr[1].ToString() == "NUMBER")
+                {
+                    dt1.Rows[0][index] = 0;
+                }
+                if (dr[1].ToString() == "VARCHAR2")
+                {
+                    dt1.Rows[0][index] = "这是一段文字";
+                }
+                if (dr[1].ToString() == "DATE")
+                {
+                    dt1.Rows[0][index] = DateTime.Now.ToString("yyyy-MM-dd");
+                }
+                if (dr[1].ToString() == "FLOAT")
+                {
+                    dt1.Rows[0][index] = 1.0;
+                }
+                if (dr[1].ToString() == "CLOB")
+                {
+                    dt1.Rows[0][index] = "一段长文字";
+                }
+            }
+            return dt1;
+        }
+
+
+        /// <summary>
+        /// 通过条件更新
+        /// </summary>
+        /// <param name="TableName"></param>
+        /// <param name="update"></param>
+        /// <param name="condition"></param>
+        public void UpdateByCondition(string TableName, string update, string condition)
+        {
+            string sql = "update " + TableName + " set " + update + " where " + condition;
+            command = new OracleCommand(sql, connection);
+            command.ExecuteNonQuery();
+            command.Dispose();
+        }
+
+        /// <summary>
+        /// 调用存储过程
+        /// </summary>
+        /// <param name="ProcedureName"></param>
+        /// <param name="param"></param>
+        public void CallProcedure(string ProcedureName, params string[] param)
+        {
+            command = new OracleCommand(ProcedureName);
+            command.Connection = connection;
+            command.CommandText = ProcedureName;
+            command.CommandType = CommandType.StoredProcedure;
+            for (int i = 0; i < param.Length; i++)
+                command.Parameters.Add(new OracleParameter(param[i].ToString(), OracleDbType.Varchar2, 200, param[i], ParameterDirection.InputOutput));
+            try
+            {
+                command.ExecuteNonQuery();
+            }
+            catch (Exception)
+            {
+                command.Connection = new OracleConnection(DBConnectionString);
+                command.Connection.Open();
+                command.ExecuteNonQuery();
+            }
+            for (int i = 0; i < command.Parameters.Count; i++)
+                param[i] = command.Parameters[i].Value.ToString();
+            command.Dispose();
+        }
+
+        /// <summary>
+        /// 出现异常进行回滚的执行方法
+        /// </summary>
+        /// <param name="SQL"></param>
+        public void ExecuteSQLTran(params string[] SQL)
+        {
+            OracleTransaction tx = connection.BeginTransaction();
+            command = new OracleCommand();
+            command.Connection = connection;
+            command.Transaction = tx;
+            try
+            {
+                foreach (string sql in SQL)
+                {
+                    if (!String.IsNullOrEmpty(sql))
+                    {
+                        command.CommandText = sql;
+                        command.ExecuteNonQuery();
+                    }
+                }
+                tx.Commit();
+            }
+            catch (OracleException E)
+            {
+                tx.Rollback();
+                throw new Exception(E.Message);
+            }
+        }
+
+        /// <summary>
+        /// 用于将string 的数组转换成SQL的查询内容
+        /// </summary>
+        /// <param name="Fields"></param>
+        /// <returns></returns>
+        private string AddField(string[] Fields)
+        {
+            string sql = " ";
+            foreach (string field in Fields)
+            {
+                sql += field + ",";
+            }
+            return sql.Substring(0, sql.Length - 1);
+        }
+        /// <summary>
+        /// 通过查询的内容获取到字段的描述
+        /// </summary>
+        /// <param name="field"></param>
+        /// <returns></returns>
+        private static string[] GetCaptionFromField(string field)
+        {
+            string[] caption = field.Split(',');
+            for (int i = 0; i < caption.Length; i++)
+            {
+                caption[i] = caption[i].Substring(0, caption[i].LastIndexOf("as")).Trim();
+            }
+            return caption;
+        }
+
+        /// <summary>
+        /// 通过查询的语句获取查询的字段
+        /// </summary>
+        /// <param name="field"></param>
+        /// <returns></returns>
+        private static string[] GetField(string field)
+        {
+            string[] fields = field.Split(',');
+            for (int i = 0; i < fields.Length; i++)
+            {
+                fields[i] = fields[i].Substring(fields[i].LastIndexOf("as") + 2, fields[i].Length - fields[i].LastIndexOf("as") - 2).Trim();
+            }
+            return fields;
+        }
+
+        public static string[] GetParamFromSQL(string SQL)
+        {
+            string[] par = SQL.Split(':');
+            //用来存参数的数组
+            StringBuilder[] addpar = new StringBuilder[par.Length - 1];
+            string[] param = new string[par.Length - 1];
+            for (int i = 0; i < par.Length - 1; i++)
+            {
+                //新建一个char类型的数组用来存储每个字节的变量
+                char[] c = par[i + 1].ToCharArray();
+                addpar[i] = new StringBuilder();
+                for (int j = 0; j < c.Length; j++)
+                {
+                    if (c[j] != ' ' && c[j] != ',' && c[j] != ')')
+                    {
+                        addpar[i].Append(c[j]);
+                    }
+                    else
+                    {
+                        break;
+                    }
+                }
+            }
+            for (int i = 0; i < par.Length - 1; i++)
+            {
+                param[i] = addpar[i].ToString();
+            }
+            return param;
+        }
+    }
+}

BIN
TestProject/tool/Kingdee.BOS.WebApi.Client.dll


BIN
TestProject/tool/Newtonsoft.Json.dll


BIN
TestProject/tool/UMESDLLService.dll


+ 10 - 10
UAS_MesInterface(4.0)/MesHelper.cs

@@ -49,8 +49,8 @@ namespace BenQGuru.eMES.DLLService
         //用于存放批量执行的SQL
         List<string> sqls = new List<string>();
         //系统默认的的连接字符串
-        private string ConnectionStrings = "Data Source=192.168.230.200/orcl;User ID=MES_ZZ;PassWord=select!#%*(;";
-       // private string ConnectionStrings = "Data Source=220.161.94.175/orcl;User ID=MES_ZZ;PassWord=select!#%*(;";
+        private string ConnectionStrings = "Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=N_MES;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.15.168)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
+
         //用户选择的数据库的连接字符串
         private OracleConnection connection;
         //用户选择的数据库的连接字符串
@@ -485,22 +485,22 @@ namespace BenQGuru.eMES.DLLService
             string ms_id = getFieldDataByCondition("makeserial", "max(ms_id)", "ms_sncode='" + iSN + "'").ToString();
             if (ms_id != "")
             {
-                DataTable dt = getFieldsDataByCondition("MakeSerial", new string[] { "ms_id", "ms_mac", "ms_bt", "ms_meid", "ms_netcode", "ms_psn", "ms_imei1", "ms_imei2", "ms_imei3", "ms_othcode1", "ms_othcode2", "ms_othcode3", "ms_othid1", "ms_othid2", "ms_othid3" }, "ms_id='" + ms_id + "'");
+                DataTable dt = getFieldsDataByCondition("MakeSerial left join makeimeilist on mil_sncode=ms_sncode and ms_makecode=mil_makecode", new string[] { "ms_id", "ms_mac", "ms_bt", "ms_meid", "ms_netcode", "ms_psn", "mil_imei1", "mil_imei2", "mil_imei3", "ms_othcode1", "ms_othcode2", "ms_othcode3", "mil_othid1", "mil_othid2", "mil_othid3" }, "ms_id='" + ms_id + "'");
                 if (dt.Rows.Count > 0)
                 {
-                    oWIFI = dt.Rows[0]["ms_mac"].ToString();
-                    oBT = dt.Rows[0]["ms_bt"].ToString();
+                    oWIFI = dt.Rows[0]["mil_othid1"].ToString();
+                    oBT = dt.Rows[0]["mil_othid2"].ToString();
                     oPSN = dt.Rows[0]["ms_psn"].ToString();
                     oNetCode = dt.Rows[0]["ms_netcode"].ToString();
                     oMEID = dt.Rows[0]["ms_meid"].ToString();
-                    oIMEI1 = dt.Rows[0]["ms_imei1"].ToString();
-                    oIMEI2 = dt.Rows[0]["ms_imei2"].ToString();
+                    oIMEI1 = dt.Rows[0]["mil_imei1"].ToString();
+                    oIMEI2 = dt.Rows[0]["mil_imei2"].ToString();
                     oCode1 = dt.Rows[0]["ms_othcode1"].ToString();
                     oCode2 = dt.Rows[0]["ms_othcode2"].ToString();
                     oCode3 = dt.Rows[0]["ms_othcode3"].ToString();
-                    oID1 = dt.Rows[0]["ms_othid3"].ToString();
-                    oID2 = dt.Rows[0]["ms_othid3"].ToString();
-                    oID3 = dt.Rows[0]["ms_othid3"].ToString();
+                    oID1 = dt.Rows[0]["mil_othid1"].ToString();
+                    oID2 = dt.Rows[0]["mil_othid2"].ToString();
+                    oID3 = dt.Rows[0]["mil_othid3"].ToString();
                     oErrMessage = "";
                     return true;
                 }

+ 2 - 0
UAS_MesInterface(4.0)/UAS_MesInterface(4.0).csproj

@@ -22,6 +22,7 @@
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>
     <RegisterForComInterop>true</RegisterForComInterop>
+    <Prefer32Bit>false</Prefer32Bit>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
     <DebugType>pdbonly</DebugType>
@@ -30,6 +31,7 @@
     <DefineConstants>TRACE</DefineConstants>
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>
+    <Prefer32Bit>false</Prefer32Bit>
   </PropertyGroup>
   <ItemGroup>
     <Reference Include="Oracle.ManagedDataAccess">

+ 20 - 26
UAS_MesInterface(LGDZ)/MesHelper.cs

@@ -22,10 +22,10 @@ namespace UMESDLLService
         bool GetRcardMOInfo(string iSN, out string oMoCode, out string oErrMessage);
         bool CheckUserAndResourcePassed(string iUserCode, string iResCode, string iPassWord, out string oErrMessage);
         bool GetAddressRangeByMO(string iSN, out string oInfo, out string oErrMessage);
-        bool SetAddressInfo(string iSN, string iMac, string iBT,string iNetCard, string iCode1, string iCode2, string iCode3, out string oErrorMessage);
+        bool SetAddressInfo(string iSN, string iMac, string iBT, string iNetCard, string iCode1, string iCode2, string iCode3, out string oErrorMessage);
         bool SetTestDetail(string iSN, string iTestResult, string iResCode, string[,] iTestDetail, out string oErrMessage);
         bool GetMEIOrNetCodeRange(string iSnCode, string iIMEI1, string iNetCode, out string oInfo, out string oErrMessage);
-        bool SetIMEIInfo(string iSN, string iIMEI1, string iIMEI2, string iIMEI3, string iIMEI4, string iMEID, string iNETCODE, string iID1, string iID2, string iID3, out string oErrMessage);
+        bool SetIMEIInfo(string iSN, string iIMEI1, string iIMEI2, string iIMEI3, string iMEID, string iNETCODE, string iID1, string iID2, string iID3, out string oErrMessage);
         bool GetMobileAllInfo(string iSnCode, out string oInfo, out string oErrorMessage);
         bool SetMobileData(string iTSN, string iSN, string iSourceCode, string iOperator, string iResult, string iErrCode, string flag, out string oErrorMessage);
         bool SetPcbaData(string iSN, string iResCode, string iOperator, string iResult, string iErrCode, out string oErrMessage);
@@ -48,7 +48,7 @@ namespace UMESDLLService
 
         string Master = "N_MES";
         //系统默认的的连接字符串
-        private string ConnectionStrings = "Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=N_MES;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=10.11.28.21)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
+        private string ConnectionStrings = "Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=N_MES;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=172.16.30.253)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
         //用户选择的数据库的连接字符串
         private OracleConnection connection;
         //用户选择的数据库的连接字符串
@@ -328,35 +328,29 @@ namespace UMESDLLService
             string oIMEI1 = "";
             string oIMEI2 = "";
             string oIMEI3 = "";
-            string oIMEI4 = "";
             string oMEID = "";
             string oNetCode = "";
             string oPSN = "";
             string oID1 = "";
             string oID2 = "";
             string oID3 = "";
-
             if (iSN == "")
             {
                 oErrMessage = "SN不能为空";
                 return false;
             }
-
             oErrMessage = "";
-            string[] param = new string[] { iSN, "", iIMEI1, iNetCode, oIMEI1, oIMEI2, oIMEI3, oIMEI4, oMEID, oNetCode, oPSN, oID1, oID2, oID3, oErrMessage };
-            string[] ParamName = new string[] { "v_i_sncode", "v_i_macode", "v_i_imei", "v_i_netcode", "v_o_imei1", "v_o_imei2", "v_o_imei3", "v_o_imei4", "v_o_meid", "v_o_netcode", "v_o_psn", "v_o_id1", "v_o_id2", "v_o_id3", "v_o_errmsg" };
-            CallProcedure("CS_GETIMEIORNETCODERANGE_FIMEI", ParamName, ref param);
-
-            oInfo += "IMEI1:" + param[4].ToString() + "^".Replace("null", "");
-            oInfo += "IMEI2:" + param[5].ToString() + "^".Replace("null", "");
-            oInfo += "IMEI3:" + param[6].ToString() + "^".Replace("null", "");
-            oInfo += "IMEI4:" + param[7].ToString() + "^".Replace("null", "");
-            oInfo += "MEID:" + param[8].ToString() + "^".Replace("null", "");
-            oInfo += "NETCODE:" + param[9].ToString() + "^".Replace("null", "");
-            oInfo += "PSN:" + param[10].ToString() + "^".Replace("null", "");
-            oInfo += "ID1:" + param[11].ToString() + "^".Replace("null", "");
-            oInfo += "ID2:" + param[12].ToString() + "^".Replace("null", "");
-            oInfo += "ID3:" + param[13].ToString() + "".Replace("null", "");
+            string[] param = new string[] { iSN, "", iIMEI1, iNetCode, oIMEI1, oIMEI2, oIMEI3, oMEID, oNetCode, oPSN, oID1, oID2, oID3, oErrMessage };
+            string[] ParamName = new string[] { "v_i_sncode", "v_i_macode", "v_i_imei", "v_i_netcode", "v_o_imei1", "v_o_imei2", "v_o_imei3", "v_o_meid", "v_o_netcode", "v_o_psn", "v_o_id1", "v_o_id2", "v_o_id3", "v_o_errmsg" };
+            CallProcedure("CS_GETIMEIORNETCODERANGE", ParamName, ref param);
+            oInfo = oInfo + "IMEI1:" + param[4].ToString() + "^".Replace("null", "");
+            oInfo = oInfo + "IMEI2:" + param[5].ToString() + "^".Replace("null", "");
+            oInfo = oInfo + "MEID:" + param[7].ToString() + "^".Replace("null", "");
+            oInfo = oInfo + "NETCODE:" + param[8].ToString() + "^".Replace("null", "");
+            oInfo = oInfo + "PSN:" + param[9].ToString() + "^".Replace("null", "");
+            oInfo = oInfo + "ID1:" + param[10].ToString() + "^".Replace("null", "");
+            oInfo = oInfo + "ID2:" + param[11].ToString() + "^".Replace("null", "");
+            oInfo = oInfo + "ID3:" + param[12].ToString() + "".Replace("null", "");
             oErrMessage = param[13];
             if (oErrMessage == "" || oErrMessage == null || oErrMessage == "null")
                 return true;
@@ -476,7 +470,7 @@ namespace UMESDLLService
             //        return false;
             //}
             //通过序列号获取最近操作的工单号
-            string ms_id = getFieldDataByCondition("makeserial", "max(ms_id)", "ms_sncode='" + iSN + "' or ms_firstsn='" + iSN + "' or ms_imei1='"+iSN+"'").ToString();
+            string ms_id = getFieldDataByCondition("makeserial", "max(ms_id)", "ms_sncode='" + iSN + "' or ms_firstsn='" + iSN + "' or ms_imei1='" + iSN + "' or ms_imei2='" + iSN + "'").ToString();
             if (ms_id != "")
             {
                 DataTable dt = getFieldsDataByCondition("MakeSerial", new string[] { "ms_id", "ms_mac", "ms_bt", "ms_meid", "ms_netcode", "ms_psn", "ms_imei1", "ms_imei2", "ms_imei3", "ms_othcode1", "ms_othcode2", "ms_othcode3", "ms_othid1", "ms_othid2", "ms_othid3" }, "ms_id='" + ms_id + "'");
@@ -782,7 +776,7 @@ namespace UMESDLLService
         /// <param name="oErrorMessage"></param>
         /// <returns></returns>
         [Description("设置IMEI信息")]
-        public bool SetIMEIInfo(string iSN, string iIMEI1, string iIMEI2, string iIMEI3, string iIMEI4, string iMEID, string iNETCODE, string iID1, string iID2, string iID3, out string oErrMessage)
+        public bool SetIMEIInfo(string iSN, string iIMEI1, string iIMEI2, string iIMEI3, string iMEID, string iNETCODE, string iID1, string iID2, string iID3, out string oErrMessage)
         {
             if (iSN == "")
             {
@@ -790,9 +784,9 @@ namespace UMESDLLService
                 return false;
             }
             oErrMessage = "";
-            string[] param = new string[] { iSN, iIMEI1, iIMEI2, iIMEI3, iIMEI4, iMEID, iNETCODE, "", iID1, iID2, iID3, oErrMessage };
-            string[] ParamName = new string[] { "v_i_sncode", "v_i_imei1", "v_i_imei2", "v_i_imei3", "v_i_imei4", "v_i_meid", "v_i_netcode", "v_i_psn", "v_i_id1", "v_i_id2", "v_i_id3", "v_o_errmsg" };
-            CallProcedure("CS_SETIMEIINFO_FIMEI", ParamName, ref param);
+            string[] param = new string[] { iSN, iIMEI1, iIMEI2, iIMEI3, iMEID, iNETCODE, "", iID1, iID2, iID3, oErrMessage };
+            string[] ParamName = new string[] { "v_i_sncode", "v_i_imei1", "v_i_imei2", "v_i_imei3", "v_i_meid", "v_i_netcode", "v_i_psn", "v_i_id1", "v_i_id2", "v_i_id3", "v_o_errmsg" };
+            CallProcedure("CS_SETIMEIINFO", ParamName, ref param);
             oErrMessage = param[10];
             if (oErrMessage == "" || oErrMessage == null || oErrMessage == "null")
                 return true;
@@ -1301,7 +1295,7 @@ namespace UMESDLLService
             oErrorMessage = "";
             try
             {
-                string url = "http://10.11.28.21:8099/mes/mobile/login.action";//html调用的地址              
+                string url = "http://172.16.30.253:8099/mes/mobile/login.action";//html调用的地址              
                 HttpWebRequest webrequest = (HttpWebRequest)WebRequest.Create(url);
                 if (webrequest == null)
                 {

+ 171 - 100
UAS_MesInterface(ODLF)/MesHelper.cs

@@ -23,7 +23,7 @@ namespace UMESDLLService
         bool CheckRoutePassed(string iSN, string iResCode, out string oErrMessage);
         bool GetRcardMOInfo(string iSN, out string oMoCode, out string oErrMessage);
         bool CheckUserAndResourcePassed(string iUserCode, string iResCode, string iPassWord, out string oErrMessage);
-        bool GetAddressRangeByMO(string iSN, out string oWIFI, out string oBT, out string oCode1, out string oCode2, out string oCode3, out string oErrMessage);
+        bool GetAddressRangeByMO(string iSN, out string oInfo, out string oErrMessage);
         bool SetAddressInfo(string iSN, string iMac, string iBT, string iCode1, string iCode2, string iCode3, out string oErrorMessage);
         bool SetTestDetail(string iSN, string iResCode, string[] iClassName, string[] iTestResult, string iMaxValue, string iMinValue, string[] iTestDetail, out string oErrMessage);
         bool GetMEIOrNetCodeRange(string iSN, string iIMEI1, string iNetCode, out string oIMEI1, out string oIMEI2, out string oIMEI3, out string oMEID, out string oNetCode, out string oPSN, out string oID1, out string oID2, out string oID3, out string oErrMessage);
@@ -65,6 +65,36 @@ namespace UMESDLLService
             connection = new OracleConnection(ConnectionStrings);
         }
 
+        public bool GetAddressRangeByMO(string iSN, out string oInfo, out string oErrMessage)
+        {
+            oInfo = "";
+            string oWIFI = "";
+            string oBT = "";
+            string oCode1 = "";
+            string oCode2 = "";
+            string oCdoe3 = "";
+            if (iSN == "")
+            {
+                oErrMessage = "SN不能为空";
+                return false;
+            }
+            oErrMessage = "";
+            string omakeCode = "";
+            GetRcardMOInfo(iSN, out omakeCode, out oErrMessage);
+            string[] param = new string[] { iSN, omakeCode, oWIFI, oBT,  oCode1, oCode2, oCdoe3, oErrMessage };
+            string[] ParamName = new string[] { "v_i_sncode", "v_i_macode", "v_o_mac", "v_o_bt", "v_o_code1", "v_o_code2", "v_o_code3", "v_o_errmsg" };
+            CallProcedure("CS_GETADDRESSBYMAKECODE", ParamName, ref param);
+            oInfo += "MAC:" + param[2].ToString() + "^".Replace("null", "");
+            oInfo += "BT:" + param[3].ToString() + "^".Replace("null", "");
+            oInfo += "Code1:" + param[4].ToString() + "^".Replace("null", "");
+            oInfo += "Code2:" + param[5].ToString() + "^".Replace("null", "");
+            oInfo += "Code3:" + param[6].ToString() + "";
+            oErrMessage = param[7];
+            if (oErrMessage == "" || oErrMessage == null || oErrMessage == "null")
+                return true;
+            else
+                return false;
+        }
         public MESHelper(string IP)
         {
             connection = new OracleConnection("Data Source=" + IP + "/orcl;User ID=N_MES;PassWord=select!#%*(;");
@@ -268,47 +298,7 @@ namespace UMESDLLService
             return false;
         }
 
-        /// <summary>
-        /// 分配Mac地址和BT地址
-        /// </summary>
-        /// <param name="iSN"></param>
-        /// <param name="oWIFI"></param>
-        /// <param name="oBT"></param>
-        /// <param name="oCode1"></param>
-        /// <param name="oCode2"></param>
-        /// <param name="oCdoe3"></param>
-        /// <param name="oErrMessage"></param>
-        /// <returns></returns>
-        [Description("分配MAC和BT信息")]
-        public bool GetAddressRangeByMO(string iSN, out string oWIFI, out string oBT, out string oCode1, out string oCode2, out string oCode3, out string oErrMessage)
-        {
-            oWIFI = "";
-            oBT = "";
-            oCode1 = "";
-            oCode2 = "";
-            oCode3 = "";
-            if (iSN == "")
-            {
-                oErrMessage = "SN不能为空";
-                return false;
-            }
-            oErrMessage = "";
-            string omakeCode = "";
-            GetRcardMOInfo(iSN, out omakeCode, out oErrMessage);
-            string[] param = new string[] { iSN, omakeCode, oWIFI, oBT, oCode1, oCode2, oCode3, oErrMessage };
-            string[] ParamName = new string[] { "v_i_sncode", "v_i_macode", "v_o_mac", "v_o_bt", "v_o_code1", "v_o_code2", "v_o_code3", "v_o_errmsg" };
-            CallProcedure("CS_GETADDRESSBYMAKECODE", ParamName, ref param);
-            oWIFI = param[2].ToString();
-            oBT = param[3].ToString();
-            oCode1 = param[4].ToString();
-            oCode2 = param[5].ToString();
-            oCode3 = param[6].ToString();
-            oErrMessage = param[7];
-            if (oErrMessage == "" || oErrMessage == null || oErrMessage == "null")
-                return true;
-            else
-                return false;
-        }
+     
 
         /// <summary>
         /// 输入的 SN 号查找在制品是否有 IMEI 信息存在,如果存在则将 IMEI 信息传出,如果没有则在该工单下未使用的 IMEI 中随机分配一组
@@ -423,78 +413,159 @@ namespace UMESDLLService
         [Description("查询已分配的信息")]
         public bool GetMobileAllInfo(string iSN, out string oJson, out string oErrMessage)
         {
-            JavaScriptSerializer jss = new JavaScriptSerializer();
-            Dictionary<string, string> oInfo = new Dictionary<string, string>();
+            JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer();
+            Dictionary<string, string> dictionary = new Dictionary<string, string>();
             oErrMessage = "";
             oJson = "";
-            if (iSN == "")
+            if (!(iSN == ""))
             {
-                oErrMessage = "SN不能为空";
-                return false;
-            }
-            DataTable dt = (DataTable)ExecuteSql("select ms_sncode from makeserial where ms_sncode='" + iSN + "' or ms_firstsn='" + iSN + "'  order by ms_id desc", "select");
-            if (dt.Rows.Count > 0)
-            {
-                iSN = dt.Rows[0]["ms_sncode"].ToString();
-            }
-            //通过序列号获取最近操作的工单号
-            string ms_id = getFieldDataByCondition("makeserial", "max(ms_id)", "ms_sncode='" + iSN + "' or ms_firstsn='" + iSN + "'").ToString();
-            if (ms_id != "")
-            {
-                dt = getFieldsDataByCondition("MakeSerial", new string[] { "ms_id", "ms_mac", "ms_bt", "ms_meid", "ms_netcode", "ms_psn", "ms_imei1", "ms_imei2", "ms_imei3", "ms_othcode1", "ms_othcode2", "ms_othcode3", "ms_othid1", "ms_othid2", "ms_othid3" }, "ms_id='" + ms_id + "'");
-                if (dt.Rows.Count > 0)
+                if (GetAddressRangeByMO(iSN, out string oInfo, out oErrMessage))
                 {
-                    string Code1 = "";
-                    string Code2 = "";
-                    string Code3 = "";
-                    string Code4 = "";
-                    string Code5 = "";
-                    string Code6 = "";
-                    string Code7 = "";
-                    string Code8 = "";
-                    string Code9 = "";
-                    string Code10 = "";
-                    string Code11 = "";
-                    string Code12 = "";
-                    string Code13 = "";
-                    string Code14 = "";
-                    string Code15 = "";
-                    string Code16 = "";
-                    string Code17 = "";
-                    string Code18 = "";
-                    string Code19 = "";
-                    string Code20 = "";
-                    string Code21 = "";
-                    string Code22 = "";
-                    string Code23 = "";
-                    string Code24 = "";
-                    string Code25 = "";
-                    string[] param = new string[] { ms_id, Code1, Code2, Code3, Code4, Code5, Code6, Code7, Code8, Code9, Code10, Code11, Code12, Code13, Code14, Code15, Code16, Code17, Code18, Code19, Code20, Code21, Code22, Code23, Code24, Code25 };
-                    string[] ParamName = new string[] { "v_ms_id", "v_i_code1", "v_i_code2", "v_i_code3", "v_i_code4", "v_i_code5", "v_i_code6", "v_i_code7", "v_i_code8", "v_i_code9", "v_i_code10", "v_i_code11", "v_i_code12", "v_i_code13", "v_i_code14", "v_i_code15", "v_i_code16", "v_i_code17", "v_i_code18", "v_i_code19", "v_i_code20", "v_i_code21", "v_i_code22", "v_i_code23", "v_i_code24", "v_i_code25" };
-                    CallProcedure("GetMobileAllInfo_NEW_TOOL", ParamName, ref param);
-                    for (int i = 1; i < param.Length; i++)
+                    string text = oInfo.Split('^')[0].Replace("MAC:", "");
+                    string text2 = oInfo.Split('^')[1].Replace("BT:", "");
+                    string text3 = oInfo.Split('^')[2].Replace("Code1:", "");
+                    string text4 = oInfo.Split('^')[3].Replace("Code2:", "");
+                    string text5 = oInfo.Split('^')[4].Replace("Code3:", "");
+                    if (SetAddressInfo(iSN, (text == "null") ? "" : text, (text2 == "null") ? "" : text2, (text3 == "null") ? "" : text3, (text4 == "null") ? "" : text4, (text5 == "null") ? "" : text5, out oErrMessage))
                     {
-                        //获取出来的参数使用^分割
-                        if (param[i] != "" && param[i] != "null" && param[i] != null)
+                        string text6 = getFieldDataByCondition("makeserial", "max(ms_id)", "ms_sncode='" + iSN + "' or ms_firstsn='" + iSN + "'").ToString();
+                        if (!(text6 != ""))
+                        {
+                            oErrMessage = "序列号" + iSN + "不存在";
+                            return false;
+                        }
+                        DataTable fieldsDataByCondition = getFieldsDataByCondition("MakeSerial", new string[15]
                         {
-                            oInfo.Add(param[i].Split('^')[0], param[i].Split('^')[1]);
+                    "ms_id",
+                    "ms_mac",
+                    "ms_bt",
+                    "ms_meid",
+                    "ms_netcode",
+                    "ms_psn",
+                    "ms_imei1",
+                    "ms_imei2",
+                    "ms_imei3",
+                    "ms_othcode1",
+                    "ms_othcode2",
+                    "ms_othcode3",
+                    "ms_othid1",
+                    "ms_othid2",
+                    "ms_othid3"
+                        }, "ms_id='" + text6 + "'");
+                        if (fieldsDataByCondition.Rows.Count <= 0)
+                        {
+                            oErrMessage = "序列号" + iSN + "不存在";
+                            return false;
+                        }
+                        string text7 = "";
+                        string text8 = "";
+                        string text9 = "";
+                        string text10 = "";
+                        string text11 = "";
+                        string text12 = "";
+                        string text13 = "";
+                        string text14 = "";
+                        string text15 = "";
+                        string text16 = "";
+                        string text17 = "";
+                        string text18 = "";
+                        string text19 = "";
+                        string text20 = "";
+                        string text21 = "";
+                        string text22 = "";
+                        string text23 = "";
+                        string text24 = "";
+                        string text25 = "";
+                        string text26 = "";
+                        string text27 = "";
+                        string text28 = "";
+                        string text29 = "";
+                        string text30 = "";
+                        string text31 = "";
+                        string[] param = new string[26]
+                        {
+                    text6,
+                    text7,
+                    text8,
+                    text9,
+                    text10,
+                    text11,
+                    text12,
+                    text13,
+                    text14,
+                    text15,
+                    text16,
+                    text17,
+                    text18,
+                    text19,
+                    text20,
+                    text21,
+                    text22,
+                    text23,
+                    text24,
+                    text25,
+                    text26,
+                    text27,
+                    text28,
+                    text29,
+                    text30,
+                    text31
+                        };
+                        string[] paramName = new string[26]
+                        {
+                    "v_ms_id",
+                    "v_i_code1",
+                    "v_i_code2",
+                    "v_i_code3",
+                    "v_i_code4",
+                    "v_i_code5",
+                    "v_i_code6",
+                    "v_i_code7",
+                    "v_i_code8",
+                    "v_i_code9",
+                    "v_i_code10",
+                    "v_i_code11",
+                    "v_i_code12",
+                    "v_i_code13",
+                    "v_i_code14",
+                    "v_i_code15",
+                    "v_i_code16",
+                    "v_i_code17",
+                    "v_i_code18",
+                    "v_i_code19",
+                    "v_i_code20",
+                    "v_i_code21",
+                    "v_i_code22",
+                    "v_i_code23",
+                    "v_i_code24",
+                    "v_i_code25"
+                        };
+                        CallProcedure("GetMobileAllInfo_NEW", paramName, ref param);
+                        for (int i = 1; i < param.Length; i++)
+                        {
+                            if (param[i] != "" && param[i] != "null" && param[i] != null)
+                            {
+                                dictionary.Add(param[i].Split('^')[0], param[i].Split('^')[1]);
+                            }
                         }
+                        oJson = javaScriptSerializer.Serialize(dictionary);
+                        oErrMessage = "";
+                        return true;
+                    }
+                    if (!(oErrMessage == "") && oErrMessage != null && !(oErrMessage == "null"))
+                    {
+                        return false;
                     }
-                    oJson = jss.Serialize(oInfo);
-                    oErrMessage = "";
                     return true;
                 }
-                else
+                if (!(oErrMessage == "") && oErrMessage != null && !(oErrMessage == "null"))
                 {
-                    oErrMessage = "序列号" + iSN + "不存在";
                     return false;
                 }
+                return true;
             }
-            else
-            {
-                oErrMessage = "序列号" + iSN + "不存在";
-                return false;
-            }
+            oErrMessage = "SN不能为空";
+            return false;
         }
 
         /// <summary>

+ 383 - 345
UAS_MesInterface(YD)/MesHelper.cs

@@ -3,114 +3,108 @@ using System;
 using System.Collections.Generic;
 using System.ComponentModel;
 using System.Data;
-using System.Globalization;
-using System.IO;
-using System.Net;
 using System.Runtime.InteropServices;
-using System.Security.Cryptography;
 using System.Text;
-using System.Text.RegularExpressions;
 using System.Web.Script.Serialization;
 
 namespace UMESDLLService
 {
 
-    [Guid("974DEAD2-9D4C-4728-87EA-2407752E300F")]
+    [Guid("99D0E96E-1058-415D-9874-D34537625284")]
     [InterfaceType(ComInterfaceType.InterfaceIsDual)]
     public interface IMESHelper
     {
-        [DispId(12)]
+        [DispId(20)]
         bool CheckRoutePassed(string iSN, string iResCode, out string oErrMessage);
+        bool CheckRoutePassed_OnlyOK(string iSN, string iResCode, out string oErrMessage);
         bool GetRcardMOInfo(string iSN, out string oMoCode, out string oErrMessage);
         bool CheckUserAndResourcePassed(string iUserCode, string iResCode, string iPassWord, out string oErrMessage);
-        bool GetAddressRangeByMO(string iSN, out string oWIFI, out string oBT, out string oCode1, out string oCode2, out string oCode3, out string oErrMessage);
-        bool SetAddressInfo(string iSN, string iMac, string iBT, string iCode1, string iCode2, string iCode3, out string oErrorMessage);
-        bool SetTestDetail(string iSN, string iResCode, string[] iClassName, string[] iTestResult, string iMaxValue, string iMinValue, string[] iTestDetail, out string oErrMessage);
-        bool GetMEIOrNetCodeRange(string iSN, string iIMEI1, string iNetCode, out string oIMEI1, out string oIMEI2, out string oIMEI3, out string oMEID, out string oNetCode, out string oPSN, out string oID1, out string oID2, out string oID3, out string oErrMessage);
-        bool SetIMEIInfo(string iSN, string iIMEI1, string iIMEI2, string iIMEI3, string iMEID, string iPSN, string iNETCODE, string iID1, string iID2, string iID3, out string oErrMessage);
-        bool GetMobileAllInfo(string iSnCode, out string oInfo, out string oErrorMessage);
+        bool GetAddressRangeByMO(string iSN, out string oWIFI, out string oBT, out string oCode1, out string oCode2, out string oCdoe3, out string oErrMessage);
+        bool SetAddressInfo(string iSN, string iWIFI, string iBT, string iCode1, string iCode2, string iCode3, out string oErrorMessage);
+        bool GetMaster(out string oMaster);
+        bool SetMaster(string Master);
+        bool SetTestDetail(string iSN, string iTestResult, string iResCode, string[] iTestDetail, out string oErrMessage);
+        bool GetMEIOrNetCodeRange(string iSnCode, string iIMEI1, string iNetCode, out string oIMEI1, out string oIMEI2, out string oMEID, out string oNetCode, out string oPSN, out string oID1, out string oID2, out string oID3, out string oID4, out string oID5, out string oErrMessage);
+        bool SetIMEIInfo(string iSN, string iIMEI1, string iIMEI2, string iIMEI3, string iMEID, string iNET, string iID1, string iID2, string iID3, out string oErrMessage);
+        bool GetMobileAllInfo(string iSnCode, out string oWIFI, out string oBT, out string oCode1, out string oCode2, out string oCode3, out string oIMEI1, out string oIMEI2, out string oMEID, out string oNetCode, out string oPSN, out string oID1, out string oID2, out string oID3, out string oID4, out string oID5, out string oErrorMessage);
         bool SetMobileData(string iTSN, string iSN, string iSourceCode, string iOperator, string iResult, string iErrCode, string flag, out string oErrorMessage);
         bool SetPcbaData(string iSN, string iResCode, string iOperator, string iResult, string iErrCode, out string oErrMessage);
         bool GoMo(string iMO, string iSN, string iResCode, out string oErrMessage);
-        bool GetInfoByMaterial(string iPCBA, out string oSN, out string oErrMessage);
         bool GetSoftVersion(string iSN, out string oSoftVersion, out string oErrMessage);
-        bool GetMakeInfoBySN(string iSN, out string oInfo, out string oErrorMessage);
-        bool GetPSN(string iSN, out string oInfo, out string oErrorMessage);
-
-        bool GetMakeInfo(string iSN, out string oInfo, out string oErrorMessage);
-
-        bool GetPCBABySN(string iSN, out string oPCBA);
-
+        bool GetProductRelation(string iSN, out string oWIFI, out string oBT, out string IMEI1, out string IMEI2, out string IMEI3, out string oNetCode, out string oMEID, out string oErrMessage);
+        bool GetSNList(string iMaCode, out string[] TSN_List, out string[] SN_List, out string[] TSN_Rule, out string[] SN_Rule, out string oErrMessage);
+        bool GetMaterialInfo(string iSN, out string oResult, out string oErrMessage);
+        bool GetPrintLabel(string iSN, out string oResult, out string oErrMessage);
+        bool GetSnRelation(string iSN, out string oSN, out string oErrMessage);
     }
 
-    [Guid("5379A8F6-EB38-4A2B-9050-52AD9757E12D")]
+    [Guid("41EAB546-6EF4-464A-895A-9C34013A5D8C")]
     [ComSourceInterfaces(typeof(IMESHelper))]
     [ClassInterface(ClassInterfaceType.None)]
-    [ProgId("UMES.DllService.MESHelper")]
+    [ProgId("DllService.MESHelper")]
     public class MESHelper : IMESHelper
     {
         //用于拼接SQL 
         StringBuilder sql = new StringBuilder();
         //用于存放批量执行的SQL
         List<string> sqls = new List<string>();
-
-        string Master = "YD_CYZZ";
         //系统默认的的连接字符串
         private string ConnectionStrings = "Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=N_MES;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.15.168)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
+
         //用户选择的数据库的连接字符串
         private OracleConnection connection;
         //用户选择的数据库的连接字符串
         private OracleCommand command = null;
 
+        DataTable MasterDB;
+
         public MESHelper()
         {
             connection = new OracleConnection(ConnectionStrings);
         }
 
-        public MESHelper(string IP)
-        {
-            connection = new OracleConnection("Data Source=" + IP + "/orcl;User ID=N_MES;PassWord=select!#%*(;");
-        }
-
-
-        [Description("获取工单软件版本")]
-        public bool GetSoftVersion(string iMakeCode, out string oSoftVersion, out string oErrMessage)
+        /// <summary>
+        /// 检测当前的岗位资源对应的工序
+        /// </summary>
+        /// <param name="iSN"></param>
+        /// <param name="iResCode"></param>
+        /// <param name="oErrMessage"></param>
+        /// <returns></returns>
+        [Description("序列号对应工序检测")]
+        public bool CheckRoutePassed(string iSN, string iResCode, out string oErrMessage)
         {
-            string oMakeCode = "";
-            oErrMessage = "";
-            oSoftVersion = "";
-            //GetRcardMOInfo(iSN, out oMakeCode, out oErrMessage);
-            if (!CheckExist("Make", "ma_Code='" + iMakeCode + "'"))
+            if (iSN == "")
             {
-                oErrMessage = "工单号" + iMakeCode + "不存在";
+                oErrMessage = "SN不能为空";
                 return false;
             }
-            oSoftVersion = getFieldDataByCondition("make", "ma_softversion", "ma_code='" + iMakeCode + "'").ToString();
-            return true;
-        }
-
-
-        public bool GetInfoByMaterial(string iPCBA, out string oSN, out string oErrMessage)
-        {
-            oSN = "";
             oErrMessage = "";
-            if (iPCBA == "")
-            {
-                oErrMessage = "主板SN不能为空";
-            }
-
-            DataTable dt = (DataTable)ExecuteSql("select ms_firstsn,ms_sncode from CRAFTMATERIAL left join make on cm_makecode=ma_code " +
-                "left join makeserial on ms_firstsn=cm_firstsn and cm_makecode=ms_makecode  where cm_barcode='" + iPCBA + "' and nvl(cm_status,0)<>-1 order by cm_id desc", "select");
+            string[] param = new string[] { "", iResCode, iSN, "", "", "", oErrMessage };
+            string[] ParamName = new string[] { "v_i_macode", "v_i_sourcecode", "v_i_sncode", "v_i_usercode", "v_o_macode", "v_o_msid", "v_o_errmsg" };
+            CallProcedure("CS_CHECKSTEPSNANDMACODE", ParamName, ref param);
+            oErrMessage = param[6];
+            DataTable dt = (DataTable)ExecuteSql("select ms_status,ms_stepcode,ms_nextstepcode from makeserial where ms_id=(  select max(ms_id) from makeserial where ms_sncode  in ( select '" + iSN + "' from dual union select sn from makesnrelation where beforesn='" + iSN + "' and sn<>' '  union select beforesn from makesnrelation where sn='" + iSN + "' and beforesn<>' '))", "select");
+            string ms_status = "";
+            string ms_stepcode = "";
+            string ms_nextstepcode = "";
             if (dt.Rows.Count > 0)
             {
-                oSN = dt.Rows[0]["ms_sncode"].ToString();
+                ms_status = dt.Rows[0]["ms_status"].ToString();
+                ms_stepcode = dt.Rows[0]["ms_stepcode"].ToString();
+                ms_nextstepcode = dt.Rows[0]["ms_nextstepcode"].ToString();
             }
-            else
+            string stepcode = GetStepCodeBySource(iResCode);
+            if (ms_nextstepcode != "" && ms_nextstepcode != stepcode)
             {
-                oErrMessage = "主板SN未查询到关联信息";
+                oErrMessage = "当前序列号下一工序" + ms_nextstepcode;
+                return false;
             }
-            if (oErrMessage == "" || oErrMessage == null || oErrMessage == "null")
+            if (oErrMessage == "" || oErrMessage == null || oErrMessage == "null" || (ms_status == "3" && stepcode == ms_stepcode))
             {
+                if (ms_status == "3")
+                {
+                    oErrMessage = "";
+                }
                 return true;
             }
             else
@@ -124,30 +118,20 @@ namespace UMESDLLService
         /// <param name="iResCode"></param>
         /// <param name="oErrMessage"></param>
         /// <returns></returns>
-        [Description("序列号对应工序检测")]
-        public bool CheckRoutePassed(string iSN, string iResCode, out string oErrMessage)
+        [Description("序列号对应工序检测,不允许测试NG序列号")]
+        public bool CheckRoutePassed_OnlyOK(string iSN, string iResCode, out string oErrMessage)
         {
             if (iSN == "")
             {
                 oErrMessage = "SN不能为空";
                 return false;
             }
-            string SNcode = iSN;
-            DataTable dt = (DataTable)ExecuteSql("select ms_sncode from makeserial where ms_sncode='" + iSN + "' or ms_imei1='" + iSN + "' or ms_imei2='" + iSN + "' order by ms_id desc", "select");
-            if (dt.Rows.Count > 0)
-            {
-                iSN = dt.Rows[0]["ms_sncode"].ToString();
-            }
-            if (iSN == "")
-            {
-                iSN = SNcode;
-            }
             oErrMessage = "";
             string[] param = new string[] { "", iResCode, iSN, "", "", "", oErrMessage };
             string[] ParamName = new string[] { "v_i_macode", "v_i_sourcecode", "v_i_sncode", "v_i_usercode", "v_o_macode", "v_o_msid", "v_o_errmsg" };
             CallProcedure("CS_CHECKSTEPSNANDMACODE", ParamName, ref param);
             oErrMessage = param[6];
-            dt = (DataTable)ExecuteSql("select ms_status,ms_stepcode,ms_nextstepcode from makeserial where ms_id=(  select max(ms_id) from makeserial where ms_sncode  in ( select '" + iSN + "' from dual union select sn from makesnrelation where beforesn='" + iSN + "' and sn<>' '  union select beforesn from makesnrelation where sn='" + iSN + "' and beforesn<>' '))", "select");
+            DataTable dt = (DataTable)ExecuteSql("select ms_status,ms_stepcode,ms_nextstepcode from makeserial where ms_id=(  select max(ms_id) from makeserial where ms_sncode  in ( select '" + iSN + "' from dual union select sn from makesnrelation where beforesn='" + iSN + "' and sn<>' '  union select beforesn from makesnrelation where sn='" + iSN + "' and beforesn<>' '))", "select");
             string ms_status = "";
             string ms_stepcode = "";
             string ms_nextstepcode = "";
@@ -160,23 +144,11 @@ namespace UMESDLLService
             string stepcode = GetStepCodeBySource(iResCode);
             if (ms_nextstepcode != "" && ms_nextstepcode != stepcode)
             {
-                oErrMessage = "当前序列号" + iSN + "下一工序" + ms_nextstepcode;
+                oErrMessage = "当前序列号下一工序" + ms_nextstepcode;
                 return false;
             }
             if (oErrMessage == "" || oErrMessage == null || oErrMessage == "null" || (ms_status == "3" && stepcode == ms_stepcode))
             {
-                if (ms_status == "3")
-                {
-                    oErrMessage = "";
-                }
-                DataTable dt1 = (DataTable)ExecuteSql("select 1 from makebadcount where mbc_sncode='" + iSN + "' and mbc_stepcode='" + stepcode + "' and mbc_status=0", "select");
-                int BadCount = dt1.Rows.Count;
-                //测试不良3次不允许再测试,必须先维修
-                if (BadCount == 3)
-                {
-                    oErrMessage = stepcode + "连续三次测试不良,请进行维修";
-                    return false;
-                }
                 return true;
             }
             else
@@ -204,6 +176,70 @@ namespace UMESDLLService
             }
         }
 
+        [Description("获取工单软件版本")]
+        public bool GetSoftVersion(string iSN, out string oSoftVersion, out string oErrMessage)
+        {
+            string oMakeCode = "";
+            oErrMessage = "";
+            GetRcardMOInfo(iSN, out oMakeCode, out oErrMessage);
+            oSoftVersion = getFieldDataByCondition("make", "ma_softversion", "ma_code='" + oMakeCode + "'").ToString();
+            return true;
+        }
+
+        [Description("获取SN关联采集信息")]
+        public bool GetProductRelation(string iSN, out string oWIFI, out string oBT, out string oIMEI1, out string oIMEI2, out string oIMEI3, out string oNetCode, out string oMEID, out string oErrMessage)
+        {
+            oWIFI = "";
+            oBT = "";
+            oIMEI1 = "";
+            oIMEI2 = "";
+            oIMEI3 = "";
+            oNetCode = "";
+            oMEID = "";
+            string oMakeCode = "";
+            if (GetRcardMOInfo(iSN, out oMakeCode, out oErrMessage))
+            {
+                DataTable dt = (DataTable)ExecuteSql("select mal_mac,mal_bt from makeaddresslist where mal_makecode='" + oMakeCode + "' and rownum=1 ", "select");
+                if (dt.Rows.Count > 0)
+                {
+                    if (dt.Rows[0]["mal_mac"].ToString() != "")
+                    {
+                        oWIFI = "Required";
+                    }
+                    if (dt.Rows[0]["mal_bt"].ToString() != "")
+                    {
+                        oBT = "Required";
+                    }
+                }
+                dt = (DataTable)ExecuteSql("select mil_imei1,mil_imei2,mil_imei3,mil_netcode,mil_meid from makeimeilist where mil_makecode='" + oMakeCode + "' and rownum=1", "select");
+                if (dt.Rows.Count > 0)
+                {
+                    if (dt.Rows[0]["mil_imei1"].ToString() != "")
+                    {
+                        oIMEI1 = "Required";
+                    }
+                    if (dt.Rows[0]["mil_imei2"].ToString() != "")
+                    {
+                        oIMEI2 = "Required";
+                    }
+                    if (dt.Rows[0]["mil_imei3"].ToString() != "")
+                    {
+                        oIMEI3 = "Required";
+                    }
+                    if (dt.Rows[0]["mil_netcode"].ToString() != "")
+                    {
+                        oNetCode = "Required";
+                    }
+                    if (dt.Rows[0]["mil_meid"].ToString() != "")
+                    {
+                        oMEID = "Required";
+                    }
+                }
+                return true;
+            }
+            else return false;
+        }
+
         /// <summary>
         /// 验证用户身份信息和岗位资源
         /// </summary>
@@ -282,13 +318,13 @@ namespace UMESDLLService
         /// <param name="oErrMessage"></param>
         /// <returns></returns>
         [Description("分配MAC和BT信息")]
-        public bool GetAddressRangeByMO(string iSN, out string oWIFI, out string oBT, out string oCode1, out string oCode2, out string oCode3, out string oErrMessage)
+        public bool GetAddressRangeByMO(string iSN, out string oWIFI, out string oBT, out string oCode1, out string oCode2, out string oCdoe3, out string oErrMessage)
         {
             oWIFI = "";
             oBT = "";
             oCode1 = "";
             oCode2 = "";
-            oCode3 = "";
+            oCdoe3 = "";
             if (iSN == "")
             {
                 oErrMessage = "SN不能为空";
@@ -297,14 +333,14 @@ namespace UMESDLLService
             oErrMessage = "";
             string omakeCode = "";
             GetRcardMOInfo(iSN, out omakeCode, out oErrMessage);
-            string[] param = new string[] { iSN, omakeCode, oWIFI, oBT, oCode1, oCode2, oCode3, oErrMessage };
+            string[] param = new string[] { iSN, omakeCode, oWIFI, oBT, oCode1, oCode2, oCdoe3, oErrMessage };
             string[] ParamName = new string[] { "v_i_sncode", "v_i_macode", "v_o_mac", "v_o_bt", "v_o_code1", "v_o_code2", "v_o_code3", "v_o_errmsg" };
             CallProcedure("CS_GETADDRESSBYMAKECODE", ParamName, ref param);
-            oWIFI = param[2].ToString();
-            oBT = param[3].ToString();
-            oCode1 = param[4].ToString();
-            oCode2 = param[5].ToString();
-            oCode3 = param[6].ToString();
+            oWIFI = param[2];
+            oBT = param[3];
+            oCode1 = param[4];
+            oCode2 = param[5];
+            oCdoe3 = param[6];
             oErrMessage = param[7];
             if (oErrMessage == "" || oErrMessage == null || oErrMessage == "null")
                 return true;
@@ -331,35 +367,35 @@ namespace UMESDLLService
         /// <param name="oErrMessage"></param>
         /// <returns></returns>
         [Description("分配IMEI和NetCode信息")]
-        public bool GetMEIOrNetCodeRange(string iSN, string iIMEI1, string iNetCode, out string oIMEI1, out string oIMEI2, out string oIMEI3, out string oMEID, out string oNetCode, out string oPSN, out string oID1, out string oID2, out string oID3, out string oErrMessage)
+        public bool GetMEIOrNetCodeRange(string iSN, string iIMEI1, string iNetCode, out string oIMEI1, out string oIMEI2, out string oMEID, out string oNetCode, out string oPSN, out string oID1, out string oID2, out string oID3, out string oID4, out string oID5, out string oErrMessage)
         {
             oIMEI1 = "";
             oIMEI2 = "";
-            oIMEI3 = "";
             oMEID = "";
             oNetCode = "";
             oPSN = "";
             oID1 = "";
             oID2 = "";
             oID3 = "";
+            oID4 = "";
+            oID5 = "";
             if (iSN == "")
             {
                 oErrMessage = "SN不能为空";
                 return false;
             }
             oErrMessage = "";
-            string[] param = new string[] { iSN, "", iIMEI1, iNetCode, oIMEI1, oIMEI2, oIMEI3, oMEID, oNetCode, oPSN, oID1, oID2, oID3, oErrMessage };
+            string[] param = new string[] { iSN, "", iIMEI1, iNetCode, oIMEI1, oIMEI2, "", oMEID, oNetCode, oPSN, oID1, oID2, oID3, oErrMessage };
             string[] ParamName = new string[] { "v_i_sncode", "v_i_macode", "v_i_imei", "v_i_netcode", "v_o_imei1", "v_o_imei2", "v_o_imei3", "v_o_meid", "v_o_netcode", "v_o_psn", "v_o_id1", "v_o_id2", "v_o_id3", "v_o_errmsg" };
             CallProcedure("CS_GETIMEIORNETCODERANGE", ParamName, ref param);
-            oIMEI1 = param[4].ToString();
-            oIMEI2 = param[5].ToString();
-            oIMEI3 = param[6].ToString();
-            oMEID = param[7].ToString();
-            oNetCode = param[8].ToString();
-            oPSN = param[9].ToString();
-            oID1 = param[10].ToString();
-            oID2 = param[11].ToString();
-            oID3 = param[12].ToString();
+            oIMEI1 = param[4];
+            oIMEI2 = param[5];
+            oMEID = param[7];
+            oNetCode = param[8];
+            oPSN = param[9];
+            oID1 = param[10];
+            oID2 = param[11];
+            oID3 = param[12];
             oErrMessage = param[13];
             if (oErrMessage == "" || oErrMessage == null || oErrMessage == "null")
                 return true;
@@ -400,7 +436,7 @@ namespace UMESDLLService
             }
         }
 
-        /// <summary> 
+        /// <summary>
         /// 获取序列号的所有串号信息
         /// </summary>
         /// <param name="iSN"></param>
@@ -423,66 +459,48 @@ namespace UMESDLLService
         /// <param name="oErrMessage"></param>
         /// <returns></returns>
         [Description("查询已分配的信息")]
-        public bool GetMobileAllInfo(string iSN, out string oJson, out string oErrMessage)
+        public bool GetMobileAllInfo(string iSN, out string oWIFI, out string oBT, out string oCode1, out string oCode2, out string oCode3, out string oIMEI1, out string oIMEI2, out string oMEID, out string oNetCode, out string oPSN, out string oID1, out string oID2, out string oID3, out string oID4, out string oID5, out string oErrMessage)
         {
-            JavaScriptSerializer jss = new JavaScriptSerializer();
-            Dictionary<string, string> oInfo = new Dictionary<string, string>();
-            oErrMessage = "";
-            oJson = "";
+            oBT = "";
+            oMEID = "";
+            oWIFI = "";
+            oPSN = "";
+            oNetCode = "";
+            oIMEI1 = "";
+            oIMEI2 = "";
+            oCode1 = "";
+            oCode2 = "";
+            oCode3 = "";
+            oID1 = "";
+            oID2 = "";
+            oID3 = "";
+            oID4 = "";
+            oID5 = "";
             if (iSN == "")
             {
                 oErrMessage = "SN不能为空";
                 return false;
             }
-            DataTable dt = (DataTable)ExecuteSql("select ms_sncode from makeserial where ms_sncode='" + iSN + "' or ms_firstsn='" + iSN + "'  order by ms_id desc", "select");
-            if (dt.Rows.Count > 0)
-            {
-                iSN = dt.Rows[0]["ms_sncode"].ToString();
-            }
             //通过序列号获取最近操作的工单号
-            string ms_id = getFieldDataByCondition("makeserial", "max(ms_id)", "ms_sncode='" + iSN + "' or ms_firstsn='" + iSN + "'").ToString();
+            string ms_id = getFieldDataByCondition("makeserial", "max(ms_id)", "ms_sncode='" + iSN + "'").ToString();
             if (ms_id != "")
             {
-                dt = getFieldsDataByCondition("MakeSerial", new string[] { "ms_id", "ms_mac", "ms_bt", "ms_meid", "ms_netcode", "ms_psn", "ms_imei1", "ms_imei2", "ms_imei3", "ms_othcode1", "ms_othcode2", "ms_othcode3", "ms_othid1", "ms_othid2", "ms_othid3" }, "ms_id='" + ms_id + "'");
+                DataTable dt = getFieldsDataByCondition("MakeSerial left join makeimeilist on mil_sncode=ms_sncode and ms_makecode=mil_makecode", new string[] { "ms_id", "ms_mac", "ms_bt", "ms_meid", "ms_netcode", "ms_psn", "mil_imei1", "mil_imei2", "mil_imei3", "ms_othcode1", "ms_othcode2", "ms_othcode3", "mil_othid1", "mil_othid2", "mil_othid3" }, "ms_id='" + ms_id + "'");
                 if (dt.Rows.Count > 0)
                 {
-                    string Code1 = "";
-                    string Code2 = "";
-                    string Code3 = "";
-                    string Code4 = "";
-                    string Code5 = "";
-                    string Code6 = "";
-                    string Code7 = "";
-                    string Code8 = "";
-                    string Code9 = "";
-                    string Code10 = "";
-                    string Code11 = "";
-                    string Code12 = "";
-                    string Code13 = "";
-                    string Code14 = "";
-                    string Code15 = "";
-                    string Code16 = "";
-                    string Code17 = "";
-                    string Code18 = "";
-                    string Code19 = "";
-                    string Code20 = "";
-                    string Code21 = "";
-                    string Code22 = "";
-                    string Code23 = "";
-                    string Code24 = "";
-                    string Code25 = "";
-                    string[] param = new string[] { ms_id, Code1, Code2, Code3, Code4, Code5, Code6, Code7, Code8, Code9, Code10, Code11, Code12, Code13, Code14, Code15, Code16, Code17, Code18, Code19, Code20, Code21, Code22, Code23, Code24, Code25 };
-                    string[] ParamName = new string[] { "v_ms_id", "v_i_code1", "v_i_code2", "v_i_code3", "v_i_code4", "v_i_code5", "v_i_code6", "v_i_code7", "v_i_code8", "v_i_code9", "v_i_code10", "v_i_code11", "v_i_code12", "v_i_code13", "v_i_code14", "v_i_code15", "v_i_code16", "v_i_code17", "v_i_code18", "v_i_code19", "v_i_code20", "v_i_code21", "v_i_code22", "v_i_code23", "v_i_code24", "v_i_code25" };
-                    CallProcedure("GetMobileAllInfo_NEW_TOOL", ParamName, ref param);
-                    for (int i = 1; i < param.Length; i++)
-                    {
-                        //获取出来的参数使用^分割
-                        if (param[i] != "" && param[i] != "null" && param[i] != null)
-                        {
-                            oInfo.Add(param[i].Split('^')[0], param[i].Split('^')[1]);
-                        }
-                    }
-                    oJson = jss.Serialize(oInfo);
+                    oWIFI = dt.Rows[0]["mil_othid1"].ToString();
+                    oBT = dt.Rows[0]["mil_othid2"].ToString();
+                    oPSN = dt.Rows[0]["ms_psn"].ToString();
+                    oNetCode = dt.Rows[0]["ms_netcode"].ToString();
+                    oMEID = dt.Rows[0]["ms_meid"].ToString();
+                    oIMEI1 = dt.Rows[0]["mil_imei1"].ToString();
+                    oIMEI2 = dt.Rows[0]["mil_imei2"].ToString();
+                    oCode1 = dt.Rows[0]["ms_othcode1"].ToString();
+                    oCode2 = dt.Rows[0]["ms_othcode2"].ToString();
+                    oCode3 = dt.Rows[0]["ms_othcode3"].ToString();
+                    oID1 = dt.Rows[0]["mil_othid1"].ToString();
+                    oID2 = dt.Rows[0]["mil_othid2"].ToString();
+                    oID3 = dt.Rows[0]["mil_othid3"].ToString();
                     oErrMessage = "";
                     return true;
                 }
@@ -499,6 +517,9 @@ namespace UMESDLLService
             }
         }
 
+
+
+
         /// <summary>
         /// 记录操作日志
         /// </summary>
@@ -527,7 +548,7 @@ namespace UMESDLLService
         /// 保存Mac地址和BT地址
         /// </summary>
         /// <param name="iSN"></param>
-        /// <param name="iMac"></param>
+        /// <param name="iWIFI"></param>
         /// <param name="iBT"></param>
         /// <param name="iCode1"></param>
         /// <param name="iCode2"></param>
@@ -535,7 +556,7 @@ namespace UMESDLLService
         /// <param name="oErrMessage"></param>
         /// <returns></returns>
         [Description("写入SN的Wifi,BT信息")]
-        public bool SetAddressInfo(string iSN, string iMac, string iBT, string iCode1, string iCode2, string iCode3, out string oErrMessage)
+        public bool SetAddressInfo(string iSN, string iWIFI, string iBT, string iCode1, string iCode2, string iCode3, out string oErrMessage)
         {
             if (iSN == "")
             {
@@ -543,8 +564,7 @@ namespace UMESDLLService
                 return false;
             }
             oErrMessage = "";
-            iSN = getFieldDataByCondition("makeserial", "ms_sncode", "ms_sncode='" + iSN + "' order by ms_id").ToString();
-            string[] param = new string[] { iSN, iMac, iBT, iCode1, iCode2, iCode3, oErrMessage };
+            string[] param = new string[] { iSN, iWIFI, iBT, iCode1, iCode2, iCode3, oErrMessage };
             string[] ParamName = new string[] { "v_i_sncode", "v_i_mac", "v_i_bt", "v_i_code1", "v_i_code2", "v_i_code3", "v_o_errmsg" };
             CallProcedure("CS_SETADDRESSINFO", ParamName, ref param);
             oErrMessage = param[6];
@@ -555,7 +575,7 @@ namespace UMESDLLService
         }
 
         [Description("序列号跳到下一 步")]
-        private bool SetStepFinish(string iMakeCode, string iSourceCode, string iSN, string iMPKind, string iResult, string iUserCode, string iErrCode, out string oErrMessage)
+        public bool SetStepFinish(string iMakeCode, string iSourceCode, string iSN, string iMPKind, string iResult, string iUserCode, string iErrCode, out string oErrMessage)
         {
             if (iSN == "")
             {
@@ -580,16 +600,33 @@ namespace UMESDLLService
                     {
                         UpdateByCondition("makebad", "mb_status=-1", "mb_sncode='" + iSN + "' and mb_makecode='" + iMakeCode + "' and mb_stepcode='" + CurrentStep + "' and mb_status=0");
                         string[] BadCode = iErrCode.Split(',');
-                        sql.Length = 0;
-                        sql.Append("insert into makebad(mb_id,mb_makecode,mb_mscode,mb_sncode,mb_inman,mb_indate,mb_stepcode");
-                        sql.Append(",mb_sourcecode,mb_badcode,mb_badtable,mb_bgcode,mb_soncode,mb_status) select makebad_seq.nextval");
-                        sql.Append(",ma_code,ms_code,ms_sncode,'" + iUserCode + "',sysdate,'" + CurrentStep + "','" + iSourceCode + "',:bc_code,'',");
-                        sql.Append("'" + BgCode + "',sp_soncode,'0' from make left join makeSerial on ms_makecode=ma_code left join stepProduct on ");
-                        sql.Append("sp_mothercode=ma_prodcode and sp_stepcode=ms_nextstepcode where ms_sncode='" + iSN + "' and ms_makecode='" + iMakeCode + "'");
                         List<string> InsertSQL = new List<string>();
                         for (int i = 0; i < BadCode.Length; i++)
                         {
-                            InsertSQL.Add(sql.ToString().Replace(":bc_code", "'" + BadCode[i] + "'"));
+                            string mb_id = GetSEQ("makebad_seq");
+                            sql.Length = 0;
+                            sql.Append("insert into makebad(mb_id,mb_makecode,mb_mscode,mb_sncode,mb_inman,mb_indate,mb_stepcode");
+                            sql.Append(",mb_sourcecode,mb_badcode,mb_badtable,mb_bgcode,mb_soncode,mb_status) select '" + mb_id + "'");
+                            sql.Append(",ma_code,ms_code,ms_sncode,'" + iUserCode + "',sysdate,'" + CurrentStep + "','" + iSourceCode + "',:bc_code,'',");
+                            sql.Append("'" + BgCode + "',sp_soncode,'0' from make left join makeSerial on ms_makecode=ma_code left join stepProduct on ");
+                            sql.Append("sp_mothercode=ma_prodcode and sp_stepcode=ms_nextstepcode where ms_sncode='" + iSN + "' and ms_makecode='" + iMakeCode + "'");
+                            InsertSQL.Add(sql.ToString().Replace(":bc_code", "'" + (BadCode[i].IndexOf("|") > 0 ? BadCode[i].Split('|')[0] : BadCode[i]) + "'"));
+                            //如果含有不良位号的则进行插入
+                            if (BadCode[i].IndexOf("|") > 0)
+                            {
+                                //使用|来分割不良代码和位号
+                                string badloc = BadCode[i].Split('|')[1];
+                                //获取多个位号
+                                string[] balocstr = badloc.Split('#');
+                                for (int j = 0; j < balocstr.Length; j++)
+                                {
+                                    //插入不良位号
+                                    sql.Length = 0;
+                                    sql.Append("insert into MAKEBADRSLOC(mbl_id,mbl_mbrid,mbl_loc,mbl_badcode,mbl_brcode,mbl_sncode,mbl_makecode,mbl_indate,mbl_inman)");
+                                    sql.Append("values(MAKEBADRSLOC_seq.nextval,'" + mb_id + "','" + balocstr[j] + "','" + BadCode[i].Split('|')[0] + "','" + BadCode[i].Split('|')[0] + "','" + iSN + "','" + iMakeCode + "',sysdate,'" + iUserCode + "')");
+                                    InsertSQL.Add(sql.ToString());
+                                }
+                            }
                         }
                         ExecuteSQLTran(InsertSQL.ToArray());
                         //将不良的序列号的状态码设为3
@@ -620,6 +657,41 @@ namespace UMESDLLService
             return CS_SetFinish(iMakeCode, iSourceCode, iSN, iUserCode, iResult, out oErrMessage);
         }
 
+        [Description("获取账套信息")]
+        public bool GetMaster(out string oMaster)
+        {
+            MasterDB = (DataTable)ExecuteSql("select ms_pwd,ma_user,ma_address from master", "select");
+            oMaster = "";
+            for (int i = 0; i < MasterDB.Rows.Count; i++)
+            {
+                if (i != MasterDB.Rows.Count - 1)
+                    oMaster += MasterDB.Rows[i]["ma_user"].ToString() + "|";
+                else
+                    oMaster += MasterDB.Rows[i]["ma_user"].ToString();
+            }
+            return true;
+        }
+
+        [Description("设置账套信息")]
+        public bool SetMaster(string iMaster)
+        {
+            DataTable dt = (DataTable)ExecuteSql("select ms_pwd,ma_user,ma_address,ma_inneraddress from master where ma_user='" + iMaster + "'", "select");
+            if (dt.Rows.Count > 0)
+            {
+                ConnectionStrings = "Data Source=" + dt.Rows[0]["ma_inneraddress"].ToString() + "/orcl;User ID=" + iMaster + ";PassWord=" + dt.Rows[0]["ms_pwd"].ToString() + ";";
+                try
+                {
+                    connection = new OracleConnection(ConnectionStrings);
+                }
+                catch (Exception)
+                {
+                    return false;
+                }
+                return true;
+            }
+            return false;
+        }
+
         /// <summary>
         /// 设置测试结果
         /// </summary>
@@ -637,22 +709,9 @@ namespace UMESDLLService
             oErrorMessage = "";
             if (iTSN == "") { oErrorMessage = "TSN不能为空"; return false; }
             if (iSN == "") { oErrorMessage = "SN不能为空"; return false; }
-            DataTable dt = (DataTable)ExecuteSql("select ms_sncode from makeserial where ms_sncode='" + iTSN + "' order by ms_id desc", "select");
-            if (dt.Rows.Count > 0)
-            {
-                iTSN = dt.Rows[0]["ms_sncode"].ToString();
-            }
-            else
-            {
-                dt = (DataTable)ExecuteSql("select ms_sncode from makeserial where ms_imei2='" + iTSN + "' order by ms_id desc", "select");
-                if (dt.Rows.Count > 0)
-                {
-                    iTSN = dt.Rows[0]["ms_sncode"].ToString();
-                }
-            }
             string[] param = new string[] { iTSN, iSN, iSourceCode, iOperater, iResult, iErrCode, oErrorMessage };
             string[] ParamName = new string[] { "v_i_tsn", "v_i_sncode", "v_i_sourcecode", "v_i_usercode", "v_i_result", "v_i_errcode", "v_o_errmsg" };
-            CallProcedure("CS_DLLSNCHANGE_TOOL", ParamName, ref param);
+            CallProcedure("CS_DLLSNCHANGE", ParamName, ref param);
             oErrorMessage = param[6];
             if (oErrorMessage == "" || oErrorMessage == null || oErrorMessage == "null")
                 return true;
@@ -670,7 +729,7 @@ namespace UMESDLLService
             oErrMessage = "";
             string[] param = new string[] { iMakeCode, iSourceCode, iSN, iUserCode, iResult, oErrMessage };
             string[] ParamName = new string[] { "v_i_macode", "v_i_sourcecode", "v_i_sncode", "v_i_usercode", "v_i_result", "v_o_errmsg" };
-            CallProcedure("CS_SETSTEPRESULT_TOOL", ParamName, ref param);
+            CallProcedure("CS_SETSTEPRESULT", ParamName, ref param);
             oErrMessage = param[5];
             if (oErrMessage == "" || oErrMessage == null || oErrMessage == "null")
                 return true;
@@ -696,7 +755,7 @@ namespace UMESDLLService
         /// <param name="oErrMessage"></param>                                                      
         /// <returns></returns>
         [Description("设置测试结果")]
-        public bool SetTestDetail(string iSN, string iResCode, string[] iClassName, string[] iTestResult, string iMaxValue, string iMinValue, string[] iTestDetail, out string oErrMessage)
+        public bool SetTestDetail(string iSN, string iTestResult, string iResCode, string[] iTestDetail, out string oErrMessage)
         {
             if (iSN == "" || iSN == null)
             {
@@ -708,17 +767,13 @@ namespace UMESDLLService
             GetRcardMOInfo(iSN, out omakeCode, out oErrMessage);
             sql.Clear();
             sql.Append("begin ");
-            if (iClassName.Length != iTestResult.Length || iTestResult.Length != iTestDetail.Length)
-            {
-                oErrMessage = "参数项次不对应";
-                return false;
-            }
             for (int i = 0; i < iTestDetail.Length; i++)
             {
-                string sql = "Insert into STEPTESTDETAIL (STD_ID,STD_CLASS,STD_SN,STD_MAKECODE,STD_ACTUALVALUE,STD_TESTRESULT,STD_INDATE,STD_RESCODE,STD_MAXVALUE, STD_MINVALUE)";
-                sql += "values(STEPTESTDETAIL_SEQ.nextval,'" + iClassName[i] + "','" + iSN + "','" + omakeCode + "','" + iTestDetail[i] + "','" + iTestResult[i] + "',sysdate,'" + iResCode + "','" + iMaxValue + "','" + iMinValue + "')";
-                ExecuteSql(sql.ToString(), "insert");
+                sql.Append("Insert into STEPTESTDETAIL (STD_ID,STD_CLASS,STD_SN,STD_MAKECODE,STD_ACTUALVALUE,STD_TESTRESULT,STD_INDATE,STD_RESCODE)");
+                sql.Append("values(STEPTESTDETAIL_SEQ.nextval,'ITEM" + i + "','" + iSN + "','" + omakeCode + "','" + iTestDetail[i] + "','" + iTestResult + "',sysdate,'" + iResCode + "');");
             }
+            sql.Append("end;");
+            ExecuteSql(sql.ToString(), "insert");
             return true;
         }
 
@@ -741,7 +796,7 @@ namespace UMESDLLService
         /// <param name="oErrorMessage"></param>
         /// <returns></returns>
         [Description("设置IMEI信息")]
-        public bool SetIMEIInfo(string iSN, string iIMEI1, string iIMEI2, string iIMEI3, string iMEID, string iPSN, string iNETCODE, string iID1, string iID2, string iID3, out string oErrMessage)
+        public bool SetIMEIInfo(string iSN, string iIMEI1, string iIMEI2, string iIMEI3, string iMEID, string iNET, string iID1, string iID2, string iID3, out string oErrMessage)
         {
             if (iSN == "")
             {
@@ -749,7 +804,7 @@ namespace UMESDLLService
                 return false;
             }
             oErrMessage = "";
-            string[] param = new string[] { iSN, iIMEI1, iIMEI2, iIMEI3, iMEID, iNETCODE, iPSN, iID1, iID2, iID3, oErrMessage };
+            string[] param = new string[] { iSN, iIMEI1, iIMEI2, iIMEI3, iMEID, iNET, "", iID1, iID2, iID3, oErrMessage };
             string[] ParamName = new string[] { "v_i_sncode", "v_i_imei1", "v_i_imei2", "v_i_imei3", "v_i_meid", "v_i_netcode", "v_i_psn", "v_i_id1", "v_i_id2", "v_i_id3", "v_o_errmsg" };
             CallProcedure("CS_SETIMEIINFO", ParamName, ref param);
             oErrMessage = param[10];
@@ -777,15 +832,6 @@ namespace UMESDLLService
                 oErrMessage = "SN不能为空";
                 return false;
             }
-            string SNcode = iSN;
-            //if (!GetInfoByMaterial(iSN, out iSN, out oErrMessage))
-            //{
-            //    oErrMessage = "";
-            //}
-            if (iSN == "")
-            {
-                iSN = SNcode;
-            }
             oErrMessage = "";
             string oMakeCode = "";
             GetRcardMOInfo(iSN, out oMakeCode, out oErrMessage);
@@ -806,12 +852,17 @@ namespace UMESDLLService
         [Description("序列号归属工单")]
         public bool GoMo(string iMO, string iSN, string iResCode, out string oErrMessage)
         {
+            oErrMessage = "";
             if (iSN == "")
             {
                 oErrMessage = "SN不能为空";
                 return false;
             }
-            oErrMessage = "";
+            if (CheckExist("makeserial", "ms_sncode='" + iSN + "' and ms_makecode='" + iMO + "'"))
+            {
+                oErrMessage = "SN" + iSN + "已存在于工单" + iMO;
+                return false;
+            }
             string[] param = new string[] { iMO, iResCode, iSN, "", "", "", oErrMessage };
             string[] ParamName = new string[] { "v_i_macode", "v_i_sourcecode", "v_i_sncode", "v_i_usercode", "v_o_macode", "v_o_msid", "v_o_errmsg" };
             CallProcedure("CS_CHECKSTEPSNANDMACODE", ParamName, ref param);
@@ -883,16 +934,6 @@ namespace UMESDLLService
             return getFieldDataByCondition("source", "sc_stepcode", "sc_code='" + Source + "'").ToString();
         }
 
-        /// <summary>
-        /// 获取步骤代码
-        /// </summary>
-        /// <param name="Source"></param>
-        /// <returns></returns>
-        private string GetStepName(string st_code)
-        {
-            return getFieldDataByCondition("step", "st_name", "st_code='" + st_code + "'").ToString();
-        }
-
         /// <summary>
         /// 获取第一行第一列的信息
         /// </summary>
@@ -1244,183 +1285,180 @@ namespace UMESDLLService
             }
         }
 
-        /// <summary>
-        /// 验证用户身份信息
-        /// </summary>
-        /// <param name="iUserCode"></param>
-        /// <param name="oErrorMessage"></param>
-        /// <returns></returns>
-        private bool CheckUserLogin(string iUserCode, string iPassWord, string Master, out string oErrorMessage)
+        private string GetSEQ(string SeqName)
         {
-            oErrorMessage = "";
-            string SQL = "select em_code from employee where em_code=:UserName and em_password =:PassWord";
-            DataTable dt;
-            dt = (DataTable)ExecuteSql(SQL, "select", iUserCode, iPassWord);
-            if (dt.Rows.Count > 0)
-                return true;
-            else
-            {
-                oErrorMessage = "用户名或者密码不正确!";
-                return false;
-            }
+            DataTable dt = new DataTable();
+            dt = (DataTable)ExecuteSql("SELECT " + SeqName + ".NEXTVAL FROM DUAL", "select");
+            return dt.Rows[0][0].ToString();
         }
 
-        private Dictionary<string, object> ToDictionary(string JsonData)
+        [Description("获取上料信息")]
+        public bool GetMaterialInfo(string iSN, out string oResult, out string oErrMessage)
         {
-            object Data = null;
-            Dictionary<string, object> Dic = new Dictionary<string, object>();
-            if (JsonData.StartsWith("["))
-            {
-                //如果目标直接就为数组类型,则将会直接输出一个Key为List的List<Dictionary<string, object>>集合 
-                //使用示例List<Dictionary<string, object>> ListDic = (List<Dictionary<string, object>>)Dic["List"]; 
-                List<Dictionary<string, object>> List = new List<Dictionary<string, object>>();
-                MatchCollection ListMatch = Regex.Matches(JsonData, @"{[\s\S]+?}");//使用正则表达式匹配出JSON数组 
-                foreach (Match ListItem in ListMatch)
-                {
-                    List.Add(ToDictionary(ListItem.ToString()));//递归调用 
-                }
-                Data = List;
-                Dic.Add("List", Data);
+            JavaScriptSerializer jss = new JavaScriptSerializer();
+            Dictionary<string, string> oInfo = new Dictionary<string, string>();
+            oErrMessage = "";
+            oResult = "";
+            if (iSN == "")
+            {
+                oErrMessage = "SN不能为空";
+                return false;
             }
-            else
+            Dictionary<string, string> MacInfo = new Dictionary<string, string>();
+            //通过序列号获取最近操作的工单号
+            string ms_id = getFieldDataByCondition("makeserial", "max(ms_id)", "ms_sncode='" + iSN + "' or ms_firstsn='" + iSN + "'").ToString();
+            if (ms_id != "")
             {
-                MatchCollection Match = Regex.Matches(JsonData, @"""(.+?)"": {0,1}(\[[\s\S]+?\]|null|"".+?""|-{0,1}\d*)");//使用正则表达式匹配出JSON数据中的键与值 
-                foreach (Match item in Match)
+                DataTable dt = getFieldsDataByCondition("MakeSerial", new string[] { "ms_id", "ms_mac", "ms_bt", "ms_meid", "ms_netcode", "ms_psn", "ms_imei1", "ms_imei2", "ms_imei3", "ms_othcode1", "ms_othcode2", "ms_othcode3", "ms_othid1", "ms_othid2", "ms_othid3" }, "ms_id='" + ms_id + "'");
+                if (dt.Rows.Count > 0)
                 {
-                    try
+                    string Code1 = "";
+                    string Code2 = "";
+                    string Code3 = "";
+                    string Code4 = "";
+                    string Code5 = "";
+                    string Code6 = "";
+                    string Code7 = "";
+                    string Code8 = "";
+                    string Code9 = "";
+                    string Code10 = "";
+                    string Code11 = "";
+                    string Code12 = "";
+                    string Code13 = "";
+                    string Code14 = "";
+                    string Code15 = "";
+                    string[] param = new string[] { ms_id, Code1, Code2, Code3, Code4, Code5, Code6, Code7, Code8, Code9, Code10, Code11, Code12, Code13, Code14, Code15 };
+                    string[] ParamName = new string[] { "v_ms_id", "v_i_code1", "v_i_code2", "v_i_code3", "v_i_code4", "v_i_code5", "v_i_code6", "v_i_code7", "v_i_code8", "v_i_code9", "v_i_code10", "v_i_code11", "v_i_code12", "v_i_code13", "v_i_code14", "v_i_code15" };
+                    CallProcedure("GetMaterialInfo", ParamName, ref param);
+                    for (int i = 1; i < param.Length; i++)
                     {
-                        if (item.Groups[2].ToString().StartsWith("["))
+                        //获取出来的参数使用^分割
+                        if (param[i] != "" && param[i] != "null" && param[i] != null)
                         {
-                            //如果目标是数组,将会输出一个Key为当前Json的List<Dictionary<string, object>>集合 
-                            //使用示例List<Dictionary<string, object>> ListDic = (List<Dictionary<string, object>>)Dic["Json中的Key"]; 
-                            List<Dictionary<string, object>> List = new List<Dictionary<string, object>>();
-                            MatchCollection ListMatch = Regex.Matches(item.Groups[2].ToString(), @"{[\s\S]+?}");//使用正则表达式匹配出JSON数组 
-                            foreach (Match ListItem in ListMatch)
-                            {
-                                List.Add(ToDictionary(ListItem.ToString()));//递归调用 
-                            }
-                            Data = List;
+                            oInfo.Add(param[i].Split('^')[0], param[i].Split('^')[1]);
                         }
-                        else if (item.Groups[2].ToString().ToLower() == "null") Data = null;//如果数据为null(字符串类型),直接转换成null
-                        else Data = item.Groups[2].ToString(); //数据为数字、字符串中的一类,直接写入 
-                        Dic.Add(item.Groups[1].ToString(), Data);
                     }
-                    catch { }
+                    oResult = jss.Serialize(oInfo);
+                    oErrMessage = "";
+                    return true;
+                }
+                else
+                {
+                    oErrMessage = "序列号" + iSN + "不存在";
+                    return false;
                 }
-            }
-            return Dic;
-        }
-
-        public bool GetMakeInfoBySN(string iSN, out string oInfo, out string oErrorMessage)
-        {
-            oInfo = "";
-            oErrorMessage = "";
-            DataTable rs = (DataTable)ExecuteSql("select ma_remark1,ma_remark2,ma_remark3,ma_remark4,ma_remark5,ma_remark6,ma_remark7,ma_remark8,ma_remark9,ma_remark10,ma_remark11,ma_remark12,ma_remark13,ma_remark14,ma_remark15,ma_remark16,ma_remark17,ma_remark18 from  " + Master + ".make  " +
-                  "left join " + Master + ".makeserial on ms_makecode=ma_code  where ms_sncode='" + iSN + "' order by ms_id desc", "select");
-            if (rs.Rows.Count > 0)
-            {
-                oInfo += "oMaremark1:" + rs.Rows[0]["ma_remark1"].ToString() + "^";
-                oInfo += "oMaremark2:" + rs.Rows[0]["ma_remark2"].ToString() + "^";
-                oInfo += "oMaremark3:" + rs.Rows[0]["ma_remark3"].ToString() + "^";
-                oInfo += "oMaremark4:" + rs.Rows[0]["ma_remark4"].ToString() + "^";
-                oInfo += "oMaremark5:" + rs.Rows[0]["ma_remark5"].ToString() + "^";
-                oInfo += "oMaremark6:" + rs.Rows[0]["ma_remark6"].ToString() + "^";
-                oInfo += "oMaremark7:" + rs.Rows[0]["ma_remark7"].ToString() + "^";
-                oInfo += "oMaremark8:" + rs.Rows[0]["ma_remark8"].ToString() + "^";
-                oInfo += "oMaremark9:" + rs.Rows[0]["ma_remark9"].ToString() + "^";
-                oInfo += "oMaremark10:" + rs.Rows[0]["ma_remark10"].ToString() + "^";
-                oInfo += "oMaremark11:" + rs.Rows[0]["ma_remark11"].ToString() + "^";
-                oInfo += "oMaremark12:" + rs.Rows[0]["ma_remark12"].ToString() + "^";
-                oInfo += "oMaremark13:" + rs.Rows[0]["ma_remark13"].ToString() + "^";
-                oInfo += "oMaremark14:" + rs.Rows[0]["ma_remark14"].ToString() + "^";
-                oInfo += "oMaremark15:" + rs.Rows[0]["ma_remark15"].ToString() + "^";
-                oInfo += "oMaremark16:" + rs.Rows[0]["ma_remark16"].ToString() + "^";
-                oInfo += "oMaremark17:" + rs.Rows[0]["ma_remark17"].ToString() + "^";
-                oInfo += "oMaremark18:" + rs.Rows[0]["ma_remark18"].ToString() + "^";
-                return true;
             }
             else
             {
-                oErrorMessage = "SN未查询到关联信息";
+                oErrMessage = "序列号" + iSN + "不存在";
                 return false;
             }
         }
 
-        public bool GetMakeInfo(string iSN, out string oInfo, out string oErrorMessage)
+
+        [Description("获取打印路径")]
+        public bool GetPrintLabel(string iSN, out string oResult, out string oErrMessage)
         {
-            oInfo = "";
-            oErrorMessage = "";
-            JavaScriptSerializer jss = new JavaScriptSerializer();
-            if (iSN == "")
+            oResult = "";
+            oErrMessage = "";
+            string ms_id = getFieldDataByCondition("makeserial", "max(ms_id)", "ms_sncode='" + iSN + "' or ms_firstsn='" + iSN + "'").ToString();
+            if (ms_id == "")
             {
-                oErrorMessage = "SN不能为空";
+                oErrMessage = "SN" + iSN + "不存在";
                 return false;
             }
-            Dictionary<string, string> Info = new Dictionary<string, string>();
-            String makecode = getFieldDataByCondition("makeserial", "ms_makecode", "ms_id=(select max(ms_id) from makeserial where ms_sncode='" + iSN + "')").ToString();
-            DataTable rs = (DataTable)ExecuteSql("select mid_item,mid_value from makeitem left join makeitemdetail on mi_id=mid_miid where mi_makecode='" + makecode + "' and mid_item is not null", "select");
-            for (int i = 0; i < rs.Rows.Count; i++)
+            string prcode = getFieldDataByCondition("makeserial", "ms_prodcode", "ms_id=" + ms_id).ToString();
+            DataTable dt = (DataTable)ExecuteSql("select la_templatetype,la_url from label where la_prodcode='" + prcode + "' and la_statuscode='AUDITED'", "select");
+            if (dt.Rows.Count > 0)
+            {
+                for (int i = 0; i < dt.Rows.Count; i++)
+                {
+                    oResult = dt.Rows[i]["la_templatetype"].ToString() + "^" + dt.Rows[i]["la_url"].ToString() + "#";
+                }
+                if (oResult.IndexOf("#") > 0)
+                {
+                    oResult = oResult.Substring(0, oResult.Length - 1);
+                }
+            }
+            else
             {
-                Info.Add(rs.Rows[i]["mid_item"].ToString(), rs.Rows[i]["mid_value"].ToString());
+                oErrMessage = "产品" + prcode + "未维护标签";
+                return false;
             }
-            oInfo = jss.Serialize(Info);
             return true;
         }
 
-        public bool GetPSN(string iSN, out string oPSN, out string oErrorMessage)
+
+        [Description("通过关联信息获取SN")]
+        public bool GetSnRelation(string iSN, out string oSN, out string oErrMessage)
         {
-            oPSN = "";
-            oErrorMessage = "";
-            string iMakecode = getFieldDataByCondition("makeserial", "ms_makecode", "ms_id=(select max(ms_id) from makeserial where ms_sncode='" + iSN + "')").ToString();
-            if (iMakecode == "")
-            {
-                oErrorMessage = iSN + "无关联工单";
-                return false;
-            }
-            DataTable rs = (DataTable)ExecuteSql("select msl_sncode from makesnlist where msl_beforesn='" + iSN + "'", "select");
-            if (rs.Rows.Count > 0)
-            {
-                oPSN = rs.Rows[0][0].ToString();
-                return true;
-            }
-            rs = (DataTable)ExecuteSql("select msl_sncode,msl_id from makesnlist where msl_makecode='" + iMakecode + "' and msl_type='after' and nvl(msl_status,0)=0 order by msl_sncode", "select");
-            if (rs.Rows.Count > 0)
+            oSN = "";
+            oErrMessage = "";
+            string[] param = new string[] { iSN, oSN, oErrMessage };
+            string[] ParamName = new string[] { "iSN", "oSN", "oErrMessage" };
+            CallProcedure("GetSnRelation", ParamName, ref param);
+            oSN = param[1];
+            oErrMessage = param[2];
+            if (oErrMessage == "" || oErrMessage == null || oErrMessage == "null")
             {
-                String msl_id = rs.Rows[0]["msl_id"].ToString();
-                String msl_sncode = rs.Rows[0]["msl_sncode"].ToString();
-                ExecuteSql("update makesnlist set msl_status=-1,msl_beforesn='" + iSN + "' where msl_id=" + msl_id + " and nvl(msl_status,0)=0", "update");
-                oPSN = rs.Rows[0][0].ToString();
                 return true;
             }
             else
             {
-                oErrorMessage = "无可分配号段";
                 return false;
             }
         }
 
-        private void GetPCBABySN(string iSN, out string oPCBA)
+        [Description("获取序列号")]
+        public bool GetSNList(string iMaCode, out string[] TSN_List, out string[] SN_List, out string[] TSN_Rule, out string[] SN_Rule, out string oErrMessage)
         {
-            string oErrMessage = "";
-            oPCBA = "";
-            if (iSN == null)
+            TSN_List = null;
+            SN_List = null;
+            TSN_Rule = null;
+            SN_Rule = null;
+            if (!CheckExist("Make", "ma_code='" + iMaCode + "'"))
             {
-                oErrMessage = "SN不能为空";
-                return;
+                oErrMessage = "工单号" + iMaCode + "不存在";
+                return false;
+            }
+            //导入前的清单
+            DataTable listbefore = (DataTable)ExecuteSql("select msl_sncode from makesnlist where msl_makecode='" + iMaCode + "' and msl_type='before' and nvl(msl_status,0)=0  order by msl_sncode", "select");
+            List<string> _TSN = new List<string>();
+            for (int i = 0; i < listbefore.Rows.Count; i++)
+            {
+                _TSN.Add(listbefore.Rows[i]["msl_sncode"].ToString());
             }
+            TSN_List = _TSN.ToArray();
 
-            DataTable rs = (DataTable)ExecuteSql("select ms_firstsn from makeserial  where ms_sncode='" + iSN + "' order by ms_id desc", "select");
-            if (rs.Rows.Count > 0)
+            //导入后的清单
+            DataTable listafter = (DataTable)ExecuteSql("select msl_sncode from makesnlist where msl_makecode='" + iMaCode + "' and msl_type='after' and nvl(msl_status,0)=0 and msl_sncode not in (select ms_firstsn from makeserial where ms_makecode='" + iMaCode + "')  order by msl_sncode", "select");
+            List<string> _SN = new List<string>();
+            for (int i = 0; i < listafter.Rows.Count; i++)
             {
-                rs = (DataTable)ExecuteSql("select cm_barcode from craftmaterial left join product on cm_fsoncode=pr_code " +
-                        "where cm_firstsn='" + rs.Rows[0]["ms_firstsn"].ToString() + "' and cm_status=0 and (pr_detail like '%PCBA%' or pr_detail like '%主板%')", "select");
-                if (rs.Rows.Count > 0)
-                {
-                    oPCBA = rs.Rows[0]["cm_barcode"].ToString();
-                }
+                _SN.Add(listafter.Rows[i]["msl_sncode"].ToString());
             }
-            return;
-        }
+            SN_List = _SN.ToArray();
+
+            //转换前的规则
+            DataTable rulebefore = (DataTable)ExecuteSql("select msd_sncode from MAKESNRULEDETAIL where msd_makecode='" + iMaCode + "' and msd_type='before' and nvl(msd_status,0)=0 and msd_sncode not in (select ms_firstsn from makeserial where ms_makecode='" + iMaCode + "') order by msd_sncode", "select");
+            List<string> _TSN_rule = new List<string>();
+            for (int i = 0; i < rulebefore.Rows.Count; i++)
+            {
+                _TSN_rule.Add(rulebefore.Rows[i]["msd_sncode"].ToString());
+            }
+            TSN_Rule = _TSN_rule.ToArray();
+
+            //转换后的规则
+            DataTable ruleafter = (DataTable)ExecuteSql("select msd_sncode from MAKESNRULEDETAIL where msd_makecode='" + iMaCode + "' and msd_type='after' and nvl(msd_status,0)=0 order by msd_sncode", "select");
+            List<string> _SN_rule = new List<string>();
+            for (int i = 0; i < ruleafter.Rows.Count; i++)
+            {
+                _SN_rule.Add(ruleafter.Rows[i]["msd_sncode"].ToString());
+            }
+            SN_Rule = _SN_rule.ToArray();
 
+            oErrMessage = "";
+            return true;
+        }
     }
 }