/************************************************************************/
        /* 根据传入参数存入数据库
         * dt 时间
         * carID  车组编号
         * opname 操作人员
         * fs 故障描述
         * resovle 解决方法
         * runresove 运行解决方法
         * NP 现场照片list集合 (作为 static 可以直接用)
         * EP  电路图照片list 集合 (同上)
         * PP 部件照片集合list   (同上)
        /************************************************************************/
        public int AddRecord(DateTime dt, string carID, string opname, string fs, string resovel, string runresovle)
        {
            Operator op = new Operator();

            op.record.time = dt;
            op.record.carID = carID;
            op.record.worker = opname;
            op.fault.fault = fs;
            op.solution.solution = resovel;
            op.solution.runSolution = runresovle;
            foreach (NP n in NP)
            {
                op.fault.faultImgs.Add(n.src);
            }
            foreach (EP e in EP)
            {
                op.solution.criImgs.Add(e.src);
            }
            foreach (PP p in PP)
            {
                Parts ps = new Parts();
                ps.partsName = p.name;
                ps.partsImgs.Add(p.src);
                op.parts.Add(ps);
            }
            //op.fault.faultKey = "null";

            //string key = fs.Substring(fs.IndexOf("代码"));
            string key = getValue(fs);
            op.fault.faultKey = key;
            SqlHelper.addAll(op);
            PP.Clear();
            NP.Clear();
            EP.Clear();
            return 0;
        }
 public static List<Parts> findPartsBySolutionID(int solutionID)
 {
     SqlConnection conn = null;
     SqlCommand cmd = null;
     try
     {
         conn = new SqlConnection(conStr);
         conn.Open();
         cmd = conn.CreateCommand();
         cmd.CommandText = "select * from solution_parts S left join parts P on S.parts_ID=P.parts_ID where S.solution_ID=@solutionID";
         cmd.Parameters.AddWithValue("@solutionID", solutionID);
         SqlDataReader reader = cmd.ExecuteReader();
         List<Parts> partList = new List<Parts>();
         while (reader.Read())
         {
             Parts part = new Parts();
             part.partsID = reader.GetInt32(reader.GetOrdinal("parts_ID"));
             part.partsName = reader.GetString(reader.GetOrdinal("parts_name"));
             string partImgs = reader.GetString(reader.GetOrdinal("parts_img"));
             string[] pimgs = partImgs.Split(',');
             foreach (string img in pimgs)
             {
                 part.partsImgs.Add(img);
             }
             partList.Add(part);
         }
         return partList;
     }
     finally
     {
         conn.Close();
     }
 }
 public static Parts findPartsByPartsName(string partsName)
 {
     SqlConnection conn = null;
     SqlCommand cmd = null;
     try
     {
         conn = new SqlConnection(conStr);
         conn.Open();
         cmd = conn.CreateCommand();
         cmd.CommandText = "select * from  parts where parts_name=@partsName";
         cmd.Parameters.AddWithValue("@partsName", partsName);
         SqlDataReader reader = cmd.ExecuteReader();
         while (reader.Read())
         {
             Parts pa = new Parts();
             pa.partsID = reader.GetInt32(reader.GetOrdinal("parts_ID"));
             pa.partsName = reader.GetString(reader.GetOrdinal("parts_name"));
             string partImgs = reader.GetString(reader.GetOrdinal("parts_img"));
             string[] pimgs = partImgs.Split(',');
             foreach (string img in pimgs)
             {
                 pa.partsImgs.Add(img);
             }
             return pa;
         }
         return null;
     }
     finally
     {
         conn.Close();
     }
 }
 public static int deleteParts(Parts parts)
 {
     SqlConnection conn = null;
     SqlCommand cmd = null;
     try
     {
         conn = new SqlConnection(conStr);
         conn.Open();
         cmd = conn.CreateCommand();
         cmd.CommandText = "delete from parts where parts_ID=@partsID";
         cmd.Parameters.AddWithValue("@partsID", parts.partsID);
         return cmd.ExecuteNonQuery();
     }
     finally
     {
         conn.Close();
     }
 }
        public static int addParts(Parts parts)
        {
            SqlConnection conn = null;
            SqlCommand cmd = null;
            try
            {

                conn = new SqlConnection(conStr);
                conn.Open();
                cmd = conn.CreateCommand();

                if (findPartsByPartsID(parts.partsID) != null)
                    return -1;

                cmd.CommandText = "insert into parts (parts_name,parts_img) values(@partsName,@partsImg)";
                //cmd.Parameters.AddWithValue("@partID", parts.partsID);
                cmd.Parameters.AddWithValue("@partsName", parts.partsName);
                String imgs = null;
                int i = 0;
                foreach (string im in parts.partsImgs)
                {
                    if (i > 0) { imgs = imgs + ","; }
                    i++;
                    imgs = imgs + im;
                }
                cmd.Parameters.AddWithValue("@partsImg", imgs);

                return cmd.ExecuteNonQuery();
            }
            finally
            {
                conn.Close();
            }
        }
 public static int updateParts(Parts parts)
 {
     SqlConnection conn = null;
     SqlCommand cmd = null;
     try
     {
         conn = new SqlConnection(conStr);
         conn.Open();
         cmd = conn.CreateCommand();
         cmd.CommandText = "update parts set parts_name=@partsName,parts_img=@partsImg where parts_ID=@partsID";
         cmd.Parameters.AddWithValue("@partsID", parts.partsID);
         cmd.Parameters.AddWithValue("@partsName", parts.partsName);
         String imgs = null;
         int i = 0;
         foreach (string im in parts.partsImgs)
         {
             if (i > 0) { imgs = imgs + ","; }
             i++;
             imgs = imgs + im;
         }
         cmd.Parameters.AddWithValue("@partsImg", imgs);
         return cmd.ExecuteNonQuery();
     }
     finally
     {
         conn.Close();
     }
 }
        public static List<Parts> getAllParts()
        {
            SqlConnection conn = null;
            SqlCommand cmd = null;
            try
            {
                conn = new SqlConnection(conStr);
                conn.Open();
                cmd = conn.CreateCommand();
                cmd.CommandText = "select * from parts";
                SqlDataReader reader = cmd.ExecuteReader();
                List<Parts> partsList = new List<Parts>();
                while (reader.Read())
                {
                    Parts p = new Parts();
                    p.partsID = reader.GetInt32(reader.GetOrdinal("parts_ID"));
                    p.partsName = reader.GetString(reader.GetOrdinal("parts_name"));
                    string partsImgs = reader.GetString(reader.GetOrdinal("parts_img"));
                    string[] simgs = partsImgs.Split(',');
                    foreach (string img in simgs)
                    {
                        p.partsImgs.Add(img);
                    }

                    partsList.Add(p);
                }
                return partsList;
            }
            finally
            {
                conn.Close();
            }
        }