zoukankan      html  css  js  c++  java
  • web Service 接口对xml数据处理

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Services;
    using System.Xml;
    using IM.BLL;
    using IM.Model;
    using System.IO;
    using System.Text;
    using WebSite.Public.FlashUpload;
    
    namespace WebSite.Api.Emp
    {
        /// <summary>
        /// EmpWebService 的摘要说明
        /// </summary>
        [WebService(Namespace = "http://tempuri.org/")]
        [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
        [System.ComponentModel.ToolboxItem(false)]
        // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
        // [System.Web.Script.Services.ScriptService]
        public class EmpWebService : System.Web.Services.WebService
        {
            private const string USERNAME = "sucgm";
            private const string PWD = "sucgmltsvc!@#";
            #region 插入人员数据
            [WebMethod]
            public string synchEmployee(string uName, string pwd, string xml)
            {
    
                tb_EmployeeBLL ol = new tb_EmployeeBLL();
                string result = "0"; //发送成功
    
                if (!uName.Equals(USERNAME) && !pwd.Equals(PWD)) return "-1";
    
                try
                {
                    XmlDocument doc = new XmlDocument();
                    doc.LoadXml(xml);
                    foreach (XmlNode node in doc.SelectNodes("employees/employee"))
                    {
                        tb_EmployeeModel mod = new tb_EmployeeModel();
                        mod.sysId = node["sysId"].InnerText;
                        mod.name = node["name"].InnerText;
                        mod.createDate = Convert.ToDateTime(node["createDate"].InnerText.Length > 0 ? node["createDate"].InnerText : "1900-01-01 00:00:00");
                        mod.sex = node["sex"].InnerText;
                        mod.mobile = node["mobile"].InnerText;
                        mod.identityNo = node["identityNo"].InnerText;
                        mod.province = node["province"].InnerText;
                        mod.birthDate = node["birthDate"].InnerText;
                        mod.nation = node["nation"].InnerText;
                        mod.blood = node["blood"].InnerText;
                        mod.Subcontractor = node["subcontractor"].InnerText;
                        mod.Worktype = node["worktype"].InnerText;
                        mod.shift = node["shift"].InnerText;
                        mod.empType = node["empType"].InnerText;
                        mod.entryTime = node["entryTime"].InnerText;
                        mod.outTime = node["outTime"].InnerText;
                        mod.medicalCertificate = node["medicalCertificate"].InnerText;
                        mod.Contract = node["contract"].InnerText;
                        mod.contractTime = node["contractTime"].InnerText;
                        mod.Certificate = node["certificate"].InnerText;
                        mod.certificateName = node["certificateName"].InnerText;
                        mod.townSecure = node["townSecure"].InnerText;
                        mod.otherSecure = node["otherSecure"].InnerText;
                        mod.safeCard = node["safeCard"].InnerText;
                        mod.cardTime = node["cardTime"].InnerText;
                        mod.safePost = node["safePost"].InnerText;
                        mod.postTime = node["postTime"].InnerText;
                        mod.orderBook = node["orderBook"].InnerText;
                        mod.orderTime = node["orderTime"].InnerText;
                        mod.safeEducationJiaoDi = node["safeEducationJiaoDi"].InnerText;
                        mod.peccancys = node["peccancys"].InnerText;
                        mod.safetys = node["safetys"].InnerText;
                        mod.projectCode = node["projectCode"].InnerText;
                        mod.createUserMsgCode = node["createUserMsgCode"].InnerText;
                        mod.createUserName = node["createUserName"].InnerText;
                        string c = node["picstr"].InnerText;
                        mod.fileName = node["fileName"].InnerText;
                        mod.del = node["del"].InnerText;
                        if (c.Length > 0)
                        {
                            byte[] a = Convert.FromBase64String(c);
                            ///empphoto/项目编号/xxxx.jpg
                            string paths = Server.MapPath("../../") + "Upload\" + "\empphoto\" + mod.projectCode;
                            if (!Directory.Exists(paths))
                            {
                                Directory.CreateDirectory(paths);
                            }
                            string path = paths + "\" + mod.fileName + "";
                            FileStream fs = new FileStream(path, FileMode.Create, FileAccess.Write);
                            fs.Write(a, 0, a.Length);
                            if (fs != null)
                            {
                                fs.Close();
                            }
                            mod.picstr = "Upload/empphoto/" + mod.projectCode + "/" + mod.fileName + "";
                        }
                        else
                        {
                            mod.picstr = "Upload/empphoto/" + "NoPhoto.jpg";
                        }
    
                        ol.Add(mod);
                    }
                }
                catch (Exception e)
                {
                    result = e.Message; //返回异常信息
                }
    
    
                return result;
            } 
            #endregion
    
            #region 插入门禁信息
            [WebMethod]
            public string synchCardRecord(string uName, string pwd, string xml)
            {
    
                tb_Emp_SysnBLL ol = new tb_Emp_SysnBLL();
                string result = "0"; //发送成功
                if (!uName.Equals(USERNAME) && !pwd.Equals(PWD)) return "-1";
    
                try
                {
                    XmlDocument doc = new XmlDocument();
                    string sql1 = "";
                    doc.LoadXml(xml);
                    foreach (XmlNode node in doc.SelectNodes("cardrecords/cardrecord"))
                    {
                        tb_Emp_Card_RecordModel mod = new tb_Emp_Card_RecordModel();
                        mod.recordId = Convert.ToInt32(node["recordId"].InnerText);
                        mod.empId = node["empId"].InnerText;
                        mod.cardNo = Convert.ToDecimal(node["cardNo"].InnerText);
                        mod.epcCardNo = node["epcCardNo"].InnerText;
                        mod.deviceNo = Convert.ToInt32(node["deviceNo"].InnerText);
                        mod.readerNo = Convert.ToInt32(node["readerNo"].InnerText);
                        mod.status = Convert.ToInt32(node["status"].InnerText);
                        mod.ioDate = Convert.ToDateTime(node["ioDate"].InnerText.Length > 0 ? node["ioDate"].InnerText : "1900-01-01 00:00:00");
                        mod.analysis = Convert.ToInt32(node["analysis"].InnerText);
                        mod.createDate = Convert.ToDateTime(node["createDate"].InnerText.Length > 0 ? node["createDate"].InnerText : "1900-01-01 00:00:00");
                        mod.result = Convert.ToInt32(node["result"].InnerText);
                        mod.projectCode = node["projectCode"].InnerText;
                        mod.fileName = node["fileName"].InnerText;
                        string c = node["picstr"].InnerText;
                        if (c.Length > 0)
                        {
                            byte[] a = Convert.FromBase64String(c);
                            ///empphoto/项目编号/xxxx.jpg
                            string paths = Server.MapPath("../../") + "Upload\" + "\empphoto\" + "\cardrecord\" + mod.projectCode;
                            if (!Directory.Exists(paths))
                            {
                                Directory.CreateDirectory(paths);
                            }
    
                            string path = paths + "\" + mod.fileName + "";
                            FileStream fs = new FileStream(path, FileMode.Create, FileAccess.Write);
                            fs.Write(a, 0, a.Length);
                            if (fs != null)
                            {
                                fs.Close();
                            }
                            mod.picstr = "Upload/empphoto/cardrecord/" + mod.projectCode + "/" + mod.fileName + "";
    
                        }
                        else
                        {
                            mod.picstr = "";
                        }
    
                        sql1 += synchCardRecordSQL(mod);
                        //ol.Add(mod);
                    }
                    ol.Add(sql1);
                }
                catch (Exception e)
                {
                    result = e.Message; //返回异常信息
                }
                return result;
            } 
            #endregion
    
            #region 门禁sql拼接
            /// <summary>
            /// 接收mod数据,返回拼接的sql语句
            /// </summary>
            /// <param name="mod"></param>
            /// <returns></returns>
            public string synchCardRecordSQL(tb_Emp_Card_RecordModel mod)
            {
                StringBuilder strSql = new StringBuilder();
                strSql.Append("if not exists(select 1 from tb_Emp_Card_Record where recordId='" + mod.recordId + "' and projectCode='" + mod.projectCode + "')");
                strSql.Append(" insert into tb_Emp_Card_Record ( ");
                strSql.Append(" recordId,empId,cardNo,epcCardNo,deviceNo,readerNo,status,ioDate,");
                strSql.Append("analysis,createDate,result,projectCode,picstr,similarity,fileName ");
                strSql.Append(" ) ");
                strSql.Append(" values (");
                strSql.Append(" '" + mod.recordId + "','" + mod.empId + "','" + mod.cardNo + "','" + mod.epcCardNo + "','" + mod.deviceNo + "','" + mod.readerNo + "','" + mod.status + "','" + mod.ioDate + "',");
                strSql.Append("'" + mod.analysis + "','" + mod.createDate + "','" + mod.result + "','" + mod.projectCode + "','" + mod.picstr + "','" + mod.similarity + "','" + mod.fileName + "' ");
                strSql.Append(" ) ");
                return strSql.ToString();
            } 
            #endregion
    
            #region 插入违章信息
            [WebMethod]
            public string synchViolationRecord(string uName, string pwd, string xml)
            {
    
                tb_Emp_SysnBLL ol = new tb_Emp_SysnBLL();
                string result = "0"; //发送成功
                if (!uName.Equals(USERNAME) && !pwd.Equals(PWD)) return "-1";
    
                try
                {
                    XmlDocument doc = new XmlDocument();
                    string sql1 = "";
                    doc.LoadXml(xml);
                    foreach (XmlNode node in doc.SelectNodes("violations/violation"))
                    {
                        tb_Emp_ViolationRecordModel mod = new tb_Emp_ViolationRecordModel();
                        mod.sysId = Guid.NewGuid().ToString().Replace("-", "");
                        mod.recordId = node["recordId"].InnerText;
                        mod.empId = node["empId"].InnerText;
                        mod.violationDate = node["violationDate"].InnerText;
                        mod.grade = node["grade"].InnerText;
                        mod.types = node["types"].InnerText;
                        mod.description = node["description"].InnerText;
                        mod.vtype = node["vtype"].InnerText;
                        mod.createDate = Convert.ToDateTime(node["createDate"].InnerText.Length > 0 ? node["createDate"].InnerText : "1900-01-01 00:00:00");
                        mod.projectCode = node["projectCode"].InnerText;
                        mod.createUserMsgCode = node["createUserMsgCode"].InnerText;
                        mod.createUserName = node["createUserName"].InnerText;
                        mod.del = node["del"].InnerText;
                        try
                        {
                            foreach (XmlNode node1 in node.SelectNodes("fileName"))
                            {
                                string sysId = node1["sysId"].InnerText;
                                string name = node1["name"].InnerText;
                                string uploadName = node1["uploadName"].InnerText;
                                string filestr = node1["filestr"].InnerText;
                                string Uploadtype = "tb_Emp_ViolationRecord";
                                string Foreignkey = mod.recordId;
                                string filetype = "application/octet-stream";
                                string savetype = "0";
                                string SaveServer = "";
                                string c = filestr;
                                if (c.Length > 0)
                                {
                                    byte[] a = Convert.FromBase64String(c);
                                    ///empphoto/项目编号/xxxx.jpg
                                    string paths = Server.MapPath("../../") + "Upload\empphoto\ViolationRecord\" + mod.projectCode + "\" + mod.sysId;
                                    if (!Directory.Exists(paths))
                                    {
                                        Directory.CreateDirectory(paths);
                                    }
    
                                    string path = paths + "\" + uploadName + "";
                                    FileStream fs = new FileStream(path, FileMode.Create, FileAccess.Write);
                                    fs.Write(a, 0, a.Length);
                                    if (fs != null)
                                    {
                                        fs.Close();
                                    }
                                    FileInfo fileInfo = new FileInfo(path);
                                    string filesize = fileInfo.Length.ToString();
                                    //string filesize = "0";
                                    //string FilePath = fileInfo.DirectoryName;
                                    string FilePath = paths;
                                    string FileAppPath = "Upload\empphoto\ViolationRecord\" + mod.projectCode + "\" + mod.sysId + "\" + uploadName + "";
                                    string filenewname = uploadName;
                                    string CreateUserId = "";
                                    string createdate = DateTime.Now.ToString();
                                    string downloads = "0";
    
                                    StringBuilder strSql2 = new StringBuilder();
                                    strSql2.Append("if not exists(select 1 from tb_UploadFileList where SysId='" + sysId + "')");
                                    strSql2.Append(" insert into tb_UploadFileList ( ");
                                    strSql2.Append("  SysId,UploadType,ForeignKey,UploadName,FileType,FileSize,SaveType,SaveServer,FilePath,");
                                    strSql2.Append("FileAppPath,FileNewName,CreateUserId,CreateDate,Downloads ");
                                    strSql2.Append(" ) ");
                                    strSql2.Append(" values (");
                                    //strSql2.Append(" "+string.Format("'{0}',",mod.sysId)+"");
                                    strSql2.Append(" '" + sysId + "','" + Uploadtype + "','" + Foreignkey + "','" + name + "','" + filetype + "'," + filesize + ",'" + savetype + "','" + SaveServer + "','" + FilePath + "',");
                                    strSql2.Append("'" + FileAppPath + "','" + filenewname + "','" + CreateUserId + "','" + createdate + "'," + downloads + " ");
                                    strSql2.Append(" ) ");
                                    //strSql2.Append(" else update tb_Emp_ViolationRecord ");
                                    //strSql2.Append(" set ");
                                    //strSql2.Append(" empId='" + mod.empId + "',violationDate='" + mod.violationDate + "',grade='" + mod.grade + "',types='" + mod.types + "',description='" + mod.description + "', ");
                                    //strSql2.Append(" vtype='" + mod.vtype + "',createDate='" + mod.createDate + "',del='" + mod.del + "' where recordId='" + mod.recordId + "' and projectCode='" + mod.projectCode + "') ");
    
                                    ol.Addfj(strSql2.ToString());
                                }
                            }
                        }
                        catch
                        {
    
                        }
                        sql1 += synchViolationRecordSQL(mod);
                    }
                    ol.Add(sql1);
                }
                catch (Exception e)
                {
                    result = e.Message; //返回异常信息
                }
                return result;
            } 
            #endregion
    
            #region 违章sql拼接
            public string synchViolationRecordSQL(tb_Emp_ViolationRecordModel mod)
            {
                StringBuilder strSql = new StringBuilder();
                strSql.Append("if not exists(select 1 from tb_Emp_ViolationRecord where recordId='" + mod.recordId + "' and projectCode='" + mod.projectCode + "')");
                strSql.Append(" insert into tb_Emp_ViolationRecord ( ");
                strSql.Append("  sysId,recordId,empId,violationDate,grade,types,description,vtype,createDate,");
                strSql.Append("projectCode,createUserMsgCode,createUserName,del ");
                strSql.Append(" ) ");
                strSql.Append(" values (");
                strSql.Append(" '" + mod.sysId + "','" + mod.recordId + "','" + mod.empId + "','" + mod.violationDate + "','" + mod.grade + "','" + mod.types + "','" + mod.description + "','" + mod.vtype + "','" + mod.createDate + "',");
                strSql.Append("'" + mod.projectCode + "','" + mod.createUserMsgCode + "','" + mod.createUserName + "','" + mod.del + "' ");
                strSql.Append(" )  else ");
                strSql.Append(" update tb_Emp_ViolationRecord ");
                strSql.Append(" set ");
                strSql.Append(" empId='" + mod.empId + "',violationDate='" + mod.violationDate + "',grade='" + mod.grade + "',types='" + mod.types + "',description='" + mod.description + "', ");
                strSql.Append(" vtype='" + mod.vtype + "',createDate='" + mod.createDate + "',createUserMsgCode='" + mod.createUserMsgCode + "',createUserName='" + mod.createUserName + "',del='" + mod.del + "' where recordId='" + mod.recordId + "' and projectCode='" + mod.projectCode + "' ");
                return strSql.ToString();
            } 
            #endregion
    
            #region 插入人员定位读头信息
            [WebMethod]
            public string synchReaders(string uName, string pwd, string xml)
            {
    
                tb_Emp_SysnBLL ol = new tb_Emp_SysnBLL();
                string result = "0"; //发送成功
                if (!uName.Equals(USERNAME) && !pwd.Equals(PWD)) return "-1";
    
                try
                {
                    XmlDocument doc = new XmlDocument();
                    string sql1 = "";
                    doc.LoadXml(xml);
                    foreach (XmlNode node in doc.SelectNodes("readers/reader"))
                    {
                        tb_Emp_ReadersModel mod = new tb_Emp_ReadersModel();
                        mod.sysId = Guid.NewGuid().ToString().Replace("-", "");
                        mod.recordId = Convert.ToInt32(node["recordId"].InnerText);
                        mod.lrmID = Convert.ToInt32(node["lrmID"].InnerText);
                        mod.lrmName = node["lrmName"].InnerText;
                        mod.lrmType = Convert.ToInt32(node["lrmType"].InnerText);
                        mod.lrmX = Convert.ToInt32(node["lrmX"].InnerText);
                        mod.lrmY = Convert.ToInt32(node["lrmY"].InnerText);
                        mod.lrmState = Convert.ToInt32(node["lrmState"].InnerText);
    
                        if (node["lrmTime"].InnerText.Length > 0) mod.lrmTime=Convert.ToDateTime(node["lrmTime"].InnerText);
                        else mod.lrmTime = null;
                        mod.rmk = node["rmk"].InnerText;
                        mod.monitorDaySecurity = node["monitorDaySecurity"].InnerText;
                        mod.commentMans = node["commentMans"].InnerText;
                        mod.dangerousMans = node["dangerousMans"].InnerText;
                        mod.mapId = node["mapId"].InnerText;
                        mod.lrmRadius = Convert.ToInt32(node["lrmRadius"].InnerText);
                        //mod.createDate = Convert.ToDateTime(node["createDate"].InnerText.Length > 0 ? node["createDate"].InnerText : DBNull.Value.ToString());
                        if (node["createDate"].InnerText.Length > 0) mod.createDate=Convert.ToDateTime(node["createDate"].InnerText);
                        else mod.createDate = null;
                        mod.projectCode = node["projectCode"].InnerText;
                        mod.del = node["del"].InnerText;
    
                        sql1 += synchReadersSQL(mod);
                        //ol.Add(mod);
                    }
                    ol.Add(sql1);
                }
                catch (Exception e)
                {
                    result = e.Message; //返回异常信息
                }
                return result;
            }
            #endregion
    
            #region 人员定位读头sql拼接
            public string synchReadersSQL(tb_Emp_ReadersModel mod)
            {
                StringBuilder strSql = new StringBuilder();
                strSql.Append("if not exists(select 1 from tb_Emp_Readers where recordId='" + mod.recordId + "' and projectCode='" + mod.projectCode + "')");
                strSql.Append(" insert into tb_Emp_Readers ( ");
                strSql.Append("  sysId,recordId,lrmID,lrmName,lrmType,lrmX,lrmY,lrmState,lrmTime,rmk,monitorDaySecurity,");
                strSql.Append("commentMans,dangerousMans,mapId,lrmRadius,createDate,projectCode,del ");
                strSql.Append(" ) ");
                strSql.Append(" values (");
                strSql.Append(" '" + mod.sysId + "','" + mod.recordId + "','" + mod.lrmID + "','" + mod.lrmName + "','" + mod.lrmType + "','" + mod.lrmX + "','" + mod.lrmY + "','" + mod.lrmState + "','" + mod.lrmTime + "',");
                strSql.Append("'" + mod.rmk + "','" + mod.monitorDaySecurity + "','" + mod.commentMans + "','" + mod.dangerousMans + "','" + mod.mapId + "','" + mod.lrmRadius + "','" + mod.createDate + "','" + mod.projectCode + "','" + mod.del + "' ");
                strSql.Append(" )  else ");
                strSql.Append(" update tb_Emp_Readers ");
                strSql.Append(" set ");
                strSql.Append(" lrmID='" + mod.lrmID + "',lrmName='" + mod.lrmName + "',lrmType='" + mod.lrmType + "',lrmX='" + mod.lrmX + "',lrmY='" + mod.lrmY + "', ");
                strSql.Append(" lrmState='" + mod.lrmState + "',lrmTime='" + mod.lrmTime + "',rmk='" + mod.rmk + "',monitorDaySecurity='" + mod.monitorDaySecurity + "',commentMans='" + mod.commentMans + "',dangerousMans='" + mod.dangerousMans + "',mapId='" + mod.mapId + "', ");
                strSql.Append(" lrmRadius='" + mod.lrmRadius + "',createDate='" + mod.createDate + "',del='" + mod.del + "' ");
                strSql.Append(" where recordId='" + mod.recordId + "' and projectCode='" + mod.projectCode + "' ");
                return strSql.ToString();
            }
            #endregion
    
            #region 插入人员定位读头实时人员信息
            [WebMethod]
            public string synchEntryRecord(string uName, string pwd, string xml)
            {
    
                tb_Emp_SysnBLL ol = new tb_Emp_SysnBLL();
                string result = "0"; //发送成功
                if (!uName.Equals(USERNAME) && !pwd.Equals(PWD)) return "-1";
    
                try
                {
                    XmlDocument doc = new XmlDocument();
                    string sql1 = "";
                    doc.LoadXml(xml);
                    foreach (XmlNode node in doc.SelectNodes("entryrecords/entryrecord"))
                    {
                        tb_Emp_EntryRecordModel mod =new tb_Emp_EntryRecordModel();
                        mod.sysId = Guid.NewGuid().ToString().Replace("-", "");
                        mod.recordId = Convert.ToInt32(node["recordId"].InnerText);
                        mod.labelId = Convert.ToInt32(node["labelId"].InnerText);
                        mod.lrmId = Convert.ToInt32(node["lrmId"].InnerText);
                        mod.inTime = Convert.ToDateTime(node["inTime"].InnerText.Length > 0 ? node["inTime"].InnerText : "1900-01-01 00:00:00");
                        mod.outTime = Convert.ToDateTime(node["outTime"].InnerText.Length > 0 ? node["outTime"].InnerText : "1900-01-01 00:00:00");
                        mod.rmk = node["rmk"].InnerText;
                        mod.empId = node["empId"].InnerText;
                        mod.projectCode = node["projectCode"].InnerText;
                        sql1 += synchEntryRecordSQL(mod);
                        //ol.Add(mod);
                    }
                    ol.Add(sql1);
                }
                catch (Exception e)
                {
                    result = e.Message; //返回异常信息
                }
                return result;
            }
            #endregion
    
            #region 人员定位读头实时人员信息sql拼接
            public string synchEntryRecordSQL(tb_Emp_EntryRecordModel mod)
            {
                StringBuilder strSql = new StringBuilder();
                strSql.Append("if not exists(select 1 from tb_Emp_EntryRecord where recordId='" + mod.recordId + "' and projectCode='" + mod.projectCode + "')");
                strSql.Append(" insert into tb_Emp_EntryRecord ( ");
                strSql.Append("  sysId,recordId,labelId,lrmId,inTime,outTime,rmk,empId,projectCode ");
                strSql.Append(" ) ");
                strSql.Append(" values (");
                strSql.Append(" '" + mod.sysId + "','" + mod.recordId + "','" + mod.labelId + "','" + mod.lrmId + "','" + mod.inTime + "','" + mod.outTime + "','" + mod.rmk + "','" + mod.empId + "','" + mod.projectCode + "' ");
                strSql.Append(" )  else ");
                strSql.Append(" update tb_Emp_EntryRecord ");
                strSql.Append(" set ");
                strSql.Append(" labelId='" + mod.labelId + "',lrmId='" + mod.lrmId + "',inTime='" + mod.inTime + "',outTime='" + mod.outTime + "',rmk='" + mod.rmk + "', ");
                strSql.Append(" empId='" + mod.empId + "' ");
                strSql.Append(" where recordId='" + mod.recordId + "' and projectCode='" + mod.projectCode + "' ");
                return strSql.ToString();
            }
            #endregion
    
            #region 在场人员统计信息
            [WebMethod]
            public string synchCurWorkers(string uName, string pwd, string xml)
            {
    
                tb_Emp_SysnBLL ol = new tb_Emp_SysnBLL();
                string result = "0"; //发送成功
                if (!uName.Equals(USERNAME) && !pwd.Equals(PWD)) return "-1";
    
                try
                {
                    XmlDocument doc = new XmlDocument();
                    string sql1 = "";
                    string sql2 = "";
                    doc.LoadXml(xml);
                    foreach (XmlNode node in doc.SelectNodes("workers/worker"))
                    {
                        tb_Emp_CurWorkInfoModel mod = new tb_Emp_CurWorkInfoModel();
                        mod.empId = node["empId"].InnerText;
                        if (node["groupId"].InnerText.Length > 0) mod.groupId = Convert.ToInt32(node["groupId"].InnerText);
                        else mod.groupId = null;
                        if (node["IODate"].InnerText.Length > 0) mod.IODate = Convert.ToDateTime(node["IODate"].InnerText);
                        else mod.IODate = null;
                        if (node["director"].InnerText.Length > 0) mod.director = Convert.ToInt32(node["director"].InnerText);
                        else mod.director = null;
                        if (node["lastDirector"].InnerText.Length > 0) mod.lastDirector = Convert.ToInt32(node["lastDirector"].InnerText);
                        else mod.lastDirector = null;
                        if (node["type"].InnerText.Length > 0) mod.type = Convert.ToInt32(node["type"].InnerText);
                        else mod.type = null;
                        mod.projectCode = node["projectCode"].InnerText;
    
    
                        sql2 = " delete from tb_Emp_CurWorkInfo where projectCode='" + mod.projectCode + "' ";
                        sql1 += synchCurWorkersSQL(mod);
                        //ol.Add(mod);
                    }
                    sql2 += sql1;
                    ol.Add(sql2);
                }
                catch (Exception e)
                {
                    result = e.Message; //返回异常信息
                }
                return result;
            }
            #endregion
    
            #region 在场人员统计信息sql拼接
            public string synchCurWorkersSQL(tb_Emp_CurWorkInfoModel mod)
            {
                StringBuilder strSql = new StringBuilder();
                strSql.Append(" insert into tb_Emp_CurWorkInfo ( ");
                strSql.Append("  empId,groupId,IODate,director,lastDirector,type,projectCode ");
                strSql.Append(" ) ");
                strSql.Append(" values (");
                strSql.Append(" '" + mod.empId + "','" + mod.groupId + "','" + mod.IODate + "','" + mod.director + "','" + mod.lastDirector + "','" + mod.type + "','" + mod.projectCode + "' ");
                strSql.Append(" )  ");
                return strSql.ToString();
            }
            #endregion
    
            #region 在场人员异常警告信息
            [WebMethod]
            public string synchWarnMessage(string uName, string pwd, string xml)
            {
    
                tb_Emp_SysnBLL ol = new tb_Emp_SysnBLL();
                string result = "0"; //发送成功
                if (!uName.Equals(USERNAME) && !pwd.Equals(PWD)) return "-1";
    
                try
                {
                    XmlDocument doc = new XmlDocument();
                    string sql1 = "";
                    doc.LoadXml(xml);
                    foreach (XmlNode node in doc.SelectNodes("warnMessages/warnMessage"))
                    {
                        tb_Emp_WarnMessageModel mod = new tb_Emp_WarnMessageModel();
                        mod.sysId = Guid.NewGuid().ToString().Replace("-", "");
                        mod.recordId = node["recordId"].InnerText;
                        mod.empId = node["empId"].InnerText;
                        mod.content = node["content"].InnerText;
                        mod.type = node["type"].InnerText;
                        if (node["createDate"].InnerText.Length > 0) mod.createDate = Convert.ToDateTime(node["createDate"].InnerText);
                        mod.projectCode = node["projectCode"].InnerText;
                        sql1 += synchWarnMessageSQL(mod);
                        //ol.Add(mod);
                    }
                    ol.Add(sql1);
                }
                catch (Exception e)
                {
                    result = e.Message; //返回异常信息
                }
                return result;
            }
            #endregion
    
            #region 在场人员异常警告信息sql拼接
            public string synchWarnMessageSQL(tb_Emp_WarnMessageModel mod)
            {
                StringBuilder strSql = new StringBuilder();
                strSql.Append("if not exists(select 1 from tb_Emp_WarnMessage where recordId='" + mod.recordId + "' and projectCode='" + mod.projectCode + "')");
                strSql.Append(" insert into tb_Emp_WarnMessage ( ");
                strSql.Append("  sysId,recordId,empId,content,type,createDate,projectCode ");
                strSql.Append(" ) ");
                strSql.Append(" values (");
                strSql.Append(" '" + mod.sysId + "','" + mod.recordId + "','" + mod.empId + "','" + mod.content + "','" + mod.type + "','" + mod.createDate.ToString("yyyy-MM-dd HH:mm:ss.fff") + "','" + mod.projectCode + "' ");
                strSql.Append(" ) ");
                return strSql.ToString();   
            }
            #endregion
    
    
    
            #region 闸机设备列表信息
            [WebMethod]
            public string synchMachine(string uName, string pwd, string xml)
            {
    
                tb_Emp_SysnBLL ol = new tb_Emp_SysnBLL();
                string result = "0"; //发送成功
                if (!uName.Equals(USERNAME) && !pwd.Equals(PWD)) return "-1";
    
                try
                {
                    XmlDocument doc = new XmlDocument();
                    string sql1 = "";
                    doc.LoadXml(xml);
                    foreach (XmlNode node in doc.SelectNodes("machines/machine"))
                    {
                        tb_Device_MachineModel mod = new tb_Device_MachineModel();
                        mod.sysId = Guid.NewGuid().ToString().Replace("-", "");
                        if (node["recordId"].InnerText.Length > 0) mod.recordId = Convert.ToInt32(node["recordId"].InnerText);
                        else mod.recordId = null;
                        mod.code = node["code"].InnerText;
                        mod.name = node["name"].InnerText;
                        if (node["goupId"].InnerText.Length > 0) mod.goupId = Convert.ToInt32(node["goupId"].InnerText);
                        else mod.goupId = null;
                        mod.ipAddress = node["ipAddress"].InnerText;
                        if (node["computerId"].InnerText.Length > 0) mod.computerId = Convert.ToInt32(node["computerId"].InnerText);
                        else mod.computerId = null;
                        if (node["needSync"].InnerText.Length > 0) mod.needSync = Convert.ToInt32(node["needSync"].InnerText);
                        else mod.needSync = null;
                        mod.del = node["del"].InnerText;
                        mod.projectCode = node["projectCode"].InnerText;
                        sql1 += synchDevice_MachineSQL(mod);
                        //ol.Add(mod);
                    }
                    ol.Add(sql1);
                }
                catch (Exception e)
                {
                    result = e.Message; //返回异常信息
                }
                return result;
            }
            #endregion
    
            #region 闸机设备列表信息sql拼接
            public string synchDevice_MachineSQL(tb_Device_MachineModel mod)
            {
                StringBuilder strSql = new StringBuilder();
                strSql.Append("if not exists(select 1 from tb_Device_Machine where recordId='" + mod.recordId + "' and projectCode='" + mod.projectCode + "')");
                strSql.Append(" insert into tb_Device_Machine ( ");
                strSql.Append("  sysId,recordId,code,name,goupId,ipAddress,computerId,needSync,del,projectCode ");
                strSql.Append(" ) ");
                strSql.Append(" values (");
                strSql.Append(" '" + mod.sysId + "','" + mod.recordId + "','" + mod.code + "','" + mod.name + "','" + mod.goupId + "','" + mod.ipAddress + "','" + mod.computerId + "','" + mod.needSync + "','" + mod.del + "',");
                strSql.Append("'" + mod.projectCode + "' ");
                strSql.Append(" )  else ");
                strSql.Append(" update tb_Device_Machine ");
                strSql.Append(" set ");
                strSql.Append(" sysId='" + mod.sysId + "',recordId='" + mod.recordId + "',code='" + mod.code + "',name='" + mod.name + "',goupId='" + mod.goupId + "', ");
                strSql.Append(" ipAddress='" + mod.ipAddress + "',computerId='" + mod.computerId + "',needSync='" + mod.needSync + "',del='" + mod.del + "',projectCode='" + mod.projectCode + "' ");
                strSql.Append(" where recordId='" + mod.recordId + "' and projectCode='" + mod.projectCode + "' ");
                return strSql.ToString();
            }
            #endregion
    
            #region 闸机设备列表信息
            [WebMethod]
            public string synchSafeTrain(string uName, string pwd, string xml)
            {
    
                tb_Emp_SysnBLL ol = new tb_Emp_SysnBLL();
                string result = "0"; //发送成功
                if (!uName.Equals(USERNAME) && !pwd.Equals(PWD)) return "-1";
    
                try
                {
                    XmlDocument doc = new XmlDocument();
                    string sql1 = "";
                    doc.LoadXml(xml);
                    foreach (XmlNode node in doc.SelectNodes("safeTrains/safeTrain"))
                    {
                        tb_Emp_SafeTrainModel mod = new tb_Emp_SafeTrainModel();
                        mod.sysId = node["sysId"].InnerText;
                        mod.title = node["title"].InnerText;
                        mod.content = node["content"].InnerText;
                        mod.participants = node["participants"].InnerText;
                        mod.participantNames = node["participantNames"].InnerText;
                        if (node["createDate"].InnerText.Length > 0) mod.createDate = Convert.ToDateTime(node["createDate"].InnerText);
                        else mod.createDate = null;
                        mod.createUserMsgCode = node["createUserMsgCode"].InnerText;
                        mod.createUserName = node["createUserName"].InnerText;
                        mod.projectCode = node["projectCode"].InnerText;
                        mod.del = node["del"].InnerText;
                        sql1 += synchSafeTrainSQL(mod);
                        //ol.Add(mod);
                    }
                    ol.Add(sql1);
                }
                catch (Exception e)
                {
                    result = e.Message; //返回异常信息
                }
                return result;
            }
            #endregion
    
            #region 闸机设备列表信息sql拼接
            public string synchSafeTrainSQL(tb_Emp_SafeTrainModel mod)
            {
                StringBuilder strSql = new StringBuilder();
                strSql.Append("if not exists(select 1 from tb_Emp_SafeTrain where sysId='" + mod.sysId + "' and projectCode='" + mod.projectCode + "')");
                strSql.Append(" insert into tb_Emp_SafeTrain ( ");
                strSql.Append("  sysId,title,content,participants,participantNames,createDate,createUserMsgCode,createUserName,projectCode,del ");
                strSql.Append(" ) ");
                strSql.Append(" values (");
                strSql.Append(" '" + mod.sysId + "','" + mod.title + "','" + mod.content + "','" + mod.participants + "','" + mod.participantNames + "','" + mod.createDate + "','" + mod.createUserMsgCode + "','" + mod.createUserName + "','" + mod.projectCode + "',");
                strSql.Append("'" + mod.del + "' ");
                strSql.Append(" )  else ");
                strSql.Append(" update tb_Emp_SafeTrain ");
                strSql.Append(" set ");
                strSql.Append(" sysId='" + mod.sysId + "',title='" + mod.title + "',content='" + mod.content + "',participants='" + mod.participants + "',participantNames='" + mod.participantNames + "', ");
                strSql.Append(" createDate='" + mod.createDate + "',createUserMsgCode='" + mod.createUserMsgCode + "',createUserName='" + mod.createUserName + "',projectCode='" + mod.projectCode + "',del='" + mod.del + "' ");
                strSql.Append(" where sysId='" + mod.sysId + "' and projectCode='" + mod.projectCode + "' ");
                return strSql.ToString();
            }
            #endregion
        }
    }

    using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.Services;using System.Xml;using IM.BLL;using IM.Model;using System.IO;using System.Text;using WebSite.Public.FlashUpload;
    namespace WebSite.Api.Emp{    /// <summary>    /// EmpWebService 的摘要说明    /// </summary>    [WebService(Namespace = "http://tempuri.org/")]    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]    [System.ComponentModel.ToolboxItem(false)]    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。    // [System.Web.Script.Services.ScriptService]    public class EmpWebService : System.Web.Services.WebService    {        private const string USERNAME = "sucgm";        private const string PWD = "sucgmltsvc!@#";        #region 插入人员数据        [WebMethod]        public string synchEmployee(string uName, string pwd, string xml)        {
                tb_EmployeeBLL ol = new tb_EmployeeBLL();            string result = "0"; //发送成功
                if (!uName.Equals(USERNAME) && !pwd.Equals(PWD)) return "-1";
                try            {                XmlDocument doc = new XmlDocument();                doc.LoadXml(xml);                foreach (XmlNode node in doc.SelectNodes("employees/employee"))                {                    tb_EmployeeModel mod = new tb_EmployeeModel();                    mod.sysId = node["sysId"].InnerText;                    mod.name = node["name"].InnerText;                    mod.createDate = Convert.ToDateTime(node["createDate"].InnerText.Length > 0 ? node["createDate"].InnerText : "1900-01-01 00:00:00");                    mod.sex = node["sex"].InnerText;                    mod.mobile = node["mobile"].InnerText;                    mod.identityNo = node["identityNo"].InnerText;                    mod.province = node["province"].InnerText;                    mod.birthDate = node["birthDate"].InnerText;                    mod.nation = node["nation"].InnerText;                    mod.blood = node["blood"].InnerText;                    mod.Subcontractor = node["subcontractor"].InnerText;                    mod.Worktype = node["worktype"].InnerText;                    mod.shift = node["shift"].InnerText;                    mod.empType = node["empType"].InnerText;                    mod.entryTime = node["entryTime"].InnerText;                    mod.outTime = node["outTime"].InnerText;                    mod.medicalCertificate = node["medicalCertificate"].InnerText;                    mod.Contract = node["contract"].InnerText;                    mod.contractTime = node["contractTime"].InnerText;                    mod.Certificate = node["certificate"].InnerText;                    mod.certificateName = node["certificateName"].InnerText;                    mod.townSecure = node["townSecure"].InnerText;                    mod.otherSecure = node["otherSecure"].InnerText;                    mod.safeCard = node["safeCard"].InnerText;                    mod.cardTime = node["cardTime"].InnerText;                    mod.safePost = node["safePost"].InnerText;                    mod.postTime = node["postTime"].InnerText;                    mod.orderBook = node["orderBook"].InnerText;                    mod.orderTime = node["orderTime"].InnerText;                    mod.safeEducationJiaoDi = node["safeEducationJiaoDi"].InnerText;                    mod.peccancys = node["peccancys"].InnerText;                    mod.safetys = node["safetys"].InnerText;                    mod.projectCode = node["projectCode"].InnerText;                    mod.createUserMsgCode = node["createUserMsgCode"].InnerText;                    mod.createUserName = node["createUserName"].InnerText;                    string c = node["picstr"].InnerText;                    mod.fileName = node["fileName"].InnerText;                    mod.del = node["del"].InnerText;                    if (c.Length > 0)                    {                        byte[] a = Convert.FromBase64String(c);                        ///empphoto/项目编号/xxxx.jpg                        string paths = Server.MapPath("../../") + "Upload\" + "\empphoto\" + mod.projectCode;                        if (!Directory.Exists(paths))                        {                            Directory.CreateDirectory(paths);                        }                        string path = paths + "\" + mod.fileName + "";                        FileStream fs = new FileStream(path, FileMode.Create, FileAccess.Write);                        fs.Write(a, 0, a.Length);                        if (fs != null)                        {                            fs.Close();                        }                        mod.picstr = "Upload/empphoto/" + mod.projectCode + "/" + mod.fileName + "";                    }                    else                    {                        mod.picstr = "Upload/empphoto/" + "NoPhoto.jpg";                    }
                        ol.Add(mod);                }            }            catch (Exception e)            {                result = e.Message; //返回异常信息            }

                return result;        }         #endregion
            #region 插入门禁信息        [WebMethod]        public string synchCardRecord(string uName, string pwd, string xml)        {
                tb_Emp_SysnBLL ol = new tb_Emp_SysnBLL();            string result = "0"; //发送成功            if (!uName.Equals(USERNAME) && !pwd.Equals(PWD)) return "-1";
                try            {                XmlDocument doc = new XmlDocument();                string sql1 = "";                doc.LoadXml(xml);                foreach (XmlNode node in doc.SelectNodes("cardrecords/cardrecord"))                {                    tb_Emp_Card_RecordModel mod = new tb_Emp_Card_RecordModel();                    mod.recordId = Convert.ToInt32(node["recordId"].InnerText);                    mod.empId = node["empId"].InnerText;                    mod.cardNo = Convert.ToDecimal(node["cardNo"].InnerText);                    mod.epcCardNo = node["epcCardNo"].InnerText;                    mod.deviceNo = Convert.ToInt32(node["deviceNo"].InnerText);                    mod.readerNo = Convert.ToInt32(node["readerNo"].InnerText);                    mod.status = Convert.ToInt32(node["status"].InnerText);                    mod.ioDate = Convert.ToDateTime(node["ioDate"].InnerText.Length > 0 ? node["ioDate"].InnerText : "1900-01-01 00:00:00");                    mod.analysis = Convert.ToInt32(node["analysis"].InnerText);                    mod.createDate = Convert.ToDateTime(node["createDate"].InnerText.Length > 0 ? node["createDate"].InnerText : "1900-01-01 00:00:00");                    mod.result = Convert.ToInt32(node["result"].InnerText);                    mod.projectCode = node["projectCode"].InnerText;                    mod.fileName = node["fileName"].InnerText;                    string c = node["picstr"].InnerText;                    if (c.Length > 0)                    {                        byte[] a = Convert.FromBase64String(c);                        ///empphoto/项目编号/xxxx.jpg                        string paths = Server.MapPath("../../") + "Upload\" + "\empphoto\" + "\cardrecord\" + mod.projectCode;                        if (!Directory.Exists(paths))                        {                            Directory.CreateDirectory(paths);                        }
                            string path = paths + "\" + mod.fileName + "";                        FileStream fs = new FileStream(path, FileMode.Create, FileAccess.Write);                        fs.Write(a, 0, a.Length);                        if (fs != null)                        {                            fs.Close();                        }                        mod.picstr = "Upload/empphoto/cardrecord/" + mod.projectCode + "/" + mod.fileName + "";
                        }                    else                    {                        mod.picstr = "";                    }
                        sql1 += synchCardRecordSQL(mod);                    //ol.Add(mod);                }                ol.Add(sql1);            }            catch (Exception e)            {                result = e.Message; //返回异常信息            }            return result;        }         #endregion
            #region 门禁sql拼接        /// <summary>        /// 接收mod数据,返回拼接的sql语句        /// </summary>        /// <param name="mod"></param>        /// <returns></returns>        public string synchCardRecordSQL(tb_Emp_Card_RecordModel mod)        {            StringBuilder strSql = new StringBuilder();            strSql.Append("if not exists(select 1 from tb_Emp_Card_Record where recordId='" + mod.recordId + "' and projectCode='" + mod.projectCode + "')");            strSql.Append(" insert into tb_Emp_Card_Record ( ");            strSql.Append(" recordId,empId,cardNo,epcCardNo,deviceNo,readerNo,status,ioDate,");            strSql.Append("analysis,createDate,result,projectCode,picstr,similarity,fileName ");            strSql.Append(" ) ");            strSql.Append(" values (");            strSql.Append(" '" + mod.recordId + "','" + mod.empId + "','" + mod.cardNo + "','" + mod.epcCardNo + "','" + mod.deviceNo + "','" + mod.readerNo + "','" + mod.status + "','" + mod.ioDate + "',");            strSql.Append("'" + mod.analysis + "','" + mod.createDate + "','" + mod.result + "','" + mod.projectCode + "','" + mod.picstr + "','" + mod.similarity + "','" + mod.fileName + "' ");            strSql.Append(" ) ");            return strSql.ToString();        }         #endregion
            #region 插入违章信息        [WebMethod]        public string synchViolationRecord(string uName, string pwd, string xml)        {
                tb_Emp_SysnBLL ol = new tb_Emp_SysnBLL();            string result = "0"; //发送成功            if (!uName.Equals(USERNAME) && !pwd.Equals(PWD)) return "-1";
                try            {                XmlDocument doc = new XmlDocument();                string sql1 = "";                doc.LoadXml(xml);                foreach (XmlNode node in doc.SelectNodes("violations/violation"))                {                    tb_Emp_ViolationRecordModel mod = new tb_Emp_ViolationRecordModel();                    mod.sysId = Guid.NewGuid().ToString().Replace("-", "");                    mod.recordId = node["recordId"].InnerText;                    mod.empId = node["empId"].InnerText;                    mod.violationDate = node["violationDate"].InnerText;                    mod.grade = node["grade"].InnerText;                    mod.types = node["types"].InnerText;                    mod.description = node["description"].InnerText;                    mod.vtype = node["vtype"].InnerText;                    mod.createDate = Convert.ToDateTime(node["createDate"].InnerText.Length > 0 ? node["createDate"].InnerText : "1900-01-01 00:00:00");                    mod.projectCode = node["projectCode"].InnerText;                    mod.createUserMsgCode = node["createUserMsgCode"].InnerText;                    mod.createUserName = node["createUserName"].InnerText;                    mod.del = node["del"].InnerText;                    try                    {                        foreach (XmlNode node1 in node.SelectNodes("fileName"))                        {                            string sysId = node1["sysId"].InnerText;                            string name = node1["name"].InnerText;                            string uploadName = node1["uploadName"].InnerText;                            string filestr = node1["filestr"].InnerText;                            string Uploadtype = "tb_Emp_ViolationRecord";                            string Foreignkey = mod.recordId;                            string filetype = "application/octet-stream";                            string savetype = "0";                            string SaveServer = "";                            string c = filestr;                            if (c.Length > 0)                            {                                byte[] a = Convert.FromBase64String(c);                                ///empphoto/项目编号/xxxx.jpg                                string paths = Server.MapPath("../../") + "Upload\empphoto\ViolationRecord\" + mod.projectCode + "\" + mod.sysId;                                if (!Directory.Exists(paths))                                {                                    Directory.CreateDirectory(paths);                                }
                                    string path = paths + "\" + uploadName + "";                                FileStream fs = new FileStream(path, FileMode.Create, FileAccess.Write);                                fs.Write(a, 0, a.Length);                                if (fs != null)                                {                                    fs.Close();                                }                                FileInfo fileInfo = new FileInfo(path);                                string filesize = fileInfo.Length.ToString();                                //string filesize = "0";                                //string FilePath = fileInfo.DirectoryName;                                string FilePath = paths;                                string FileAppPath = "Upload\empphoto\ViolationRecord\" + mod.projectCode + "\" + mod.sysId + "\" + uploadName + "";                                string filenewname = uploadName;                                string CreateUserId = "";                                string createdate = DateTime.Now.ToString();                                string downloads = "0";
                                    StringBuilder strSql2 = new StringBuilder();                                strSql2.Append("if not exists(select 1 from tb_UploadFileList where SysId='" + sysId + "')");                                strSql2.Append(" insert into tb_UploadFileList ( ");                                strSql2.Append("  SysId,UploadType,ForeignKey,UploadName,FileType,FileSize,SaveType,SaveServer,FilePath,");                                strSql2.Append("FileAppPath,FileNewName,CreateUserId,CreateDate,Downloads ");                                strSql2.Append(" ) ");                                strSql2.Append(" values (");                                //strSql2.Append(" "+string.Format("'{0}',",mod.sysId)+"");                                strSql2.Append(" '" + sysId + "','" + Uploadtype + "','" + Foreignkey + "','" + name + "','" + filetype + "'," + filesize + ",'" + savetype + "','" + SaveServer + "','" + FilePath + "',");                                strSql2.Append("'" + FileAppPath + "','" + filenewname + "','" + CreateUserId + "','" + createdate + "'," + downloads + " ");                                strSql2.Append(" ) ");                                //strSql2.Append(" else update tb_Emp_ViolationRecord ");                                //strSql2.Append(" set ");                                //strSql2.Append(" empId='" + mod.empId + "',violationDate='" + mod.violationDate + "',grade='" + mod.grade + "',types='" + mod.types + "',description='" + mod.description + "', ");                                //strSql2.Append(" vtype='" + mod.vtype + "',createDate='" + mod.createDate + "',del='" + mod.del + "' where recordId='" + mod.recordId + "' and projectCode='" + mod.projectCode + "') ");
                                    ol.Addfj(strSql2.ToString());                            }                        }                    }                    catch                    {
                        }                    sql1 += synchViolationRecordSQL(mod);                }                ol.Add(sql1);            }            catch (Exception e)            {                result = e.Message; //返回异常信息            }            return result;        }         #endregion
            #region 违章sql拼接        public string synchViolationRecordSQL(tb_Emp_ViolationRecordModel mod)        {            StringBuilder strSql = new StringBuilder();            strSql.Append("if not exists(select 1 from tb_Emp_ViolationRecord where recordId='" + mod.recordId + "' and projectCode='" + mod.projectCode + "')");            strSql.Append(" insert into tb_Emp_ViolationRecord ( ");            strSql.Append("  sysId,recordId,empId,violationDate,grade,types,description,vtype,createDate,");            strSql.Append("projectCode,createUserMsgCode,createUserName,del ");            strSql.Append(" ) ");            strSql.Append(" values (");            strSql.Append(" '" + mod.sysId + "','" + mod.recordId + "','" + mod.empId + "','" + mod.violationDate + "','" + mod.grade + "','" + mod.types + "','" + mod.description + "','" + mod.vtype + "','" + mod.createDate + "',");            strSql.Append("'" + mod.projectCode + "','" + mod.createUserMsgCode + "','" + mod.createUserName + "','" + mod.del + "' ");            strSql.Append(" )  else ");            strSql.Append(" update tb_Emp_ViolationRecord ");            strSql.Append(" set ");            strSql.Append(" empId='" + mod.empId + "',violationDate='" + mod.violationDate + "',grade='" + mod.grade + "',types='" + mod.types + "',description='" + mod.description + "', ");            strSql.Append(" vtype='" + mod.vtype + "',createDate='" + mod.createDate + "',createUserMsgCode='" + mod.createUserMsgCode + "',createUserName='" + mod.createUserName + "',del='" + mod.del + "' where recordId='" + mod.recordId + "' and projectCode='" + mod.projectCode + "' ");            return strSql.ToString();        }         #endregion
            #region 插入人员定位读头信息        [WebMethod]        public string synchReaders(string uName, string pwd, string xml)        {
                tb_Emp_SysnBLL ol = new tb_Emp_SysnBLL();            string result = "0"; //发送成功            if (!uName.Equals(USERNAME) && !pwd.Equals(PWD)) return "-1";
                try            {                XmlDocument doc = new XmlDocument();                string sql1 = "";                doc.LoadXml(xml);                foreach (XmlNode node in doc.SelectNodes("readers/reader"))                {                    tb_Emp_ReadersModel mod = new tb_Emp_ReadersModel();                    mod.sysId = Guid.NewGuid().ToString().Replace("-", "");                    mod.recordId = Convert.ToInt32(node["recordId"].InnerText);                    mod.lrmID = Convert.ToInt32(node["lrmID"].InnerText);                    mod.lrmName = node["lrmName"].InnerText;                    mod.lrmType = Convert.ToInt32(node["lrmType"].InnerText);                    mod.lrmX = Convert.ToInt32(node["lrmX"].InnerText);                    mod.lrmY = Convert.ToInt32(node["lrmY"].InnerText);                    mod.lrmState = Convert.ToInt32(node["lrmState"].InnerText);
                        if (node["lrmTime"].InnerText.Length > 0) mod.lrmTime=Convert.ToDateTime(node["lrmTime"].InnerText);                    else mod.lrmTime = null;                    mod.rmk = node["rmk"].InnerText;                    mod.monitorDaySecurity = node["monitorDaySecurity"].InnerText;                    mod.commentMans = node["commentMans"].InnerText;                    mod.dangerousMans = node["dangerousMans"].InnerText;                    mod.mapId = node["mapId"].InnerText;                    mod.lrmRadius = Convert.ToInt32(node["lrmRadius"].InnerText);                    //mod.createDate = Convert.ToDateTime(node["createDate"].InnerText.Length > 0 ? node["createDate"].InnerText : DBNull.Value.ToString());                    if (node["createDate"].InnerText.Length > 0) mod.createDate=Convert.ToDateTime(node["createDate"].InnerText);                    else mod.createDate = null;                    mod.projectCode = node["projectCode"].InnerText;                    mod.del = node["del"].InnerText;
                        sql1 += synchReadersSQL(mod);                    //ol.Add(mod);                }                ol.Add(sql1);            }            catch (Exception e)            {                result = e.Message; //返回异常信息            }            return result;        }        #endregion
            #region 人员定位读头sql拼接        public string synchReadersSQL(tb_Emp_ReadersModel mod)        {            StringBuilder strSql = new StringBuilder();            strSql.Append("if not exists(select 1 from tb_Emp_Readers where recordId='" + mod.recordId + "' and projectCode='" + mod.projectCode + "')");            strSql.Append(" insert into tb_Emp_Readers ( ");            strSql.Append("  sysId,recordId,lrmID,lrmName,lrmType,lrmX,lrmY,lrmState,lrmTime,rmk,monitorDaySecurity,");            strSql.Append("commentMans,dangerousMans,mapId,lrmRadius,createDate,projectCode,del ");            strSql.Append(" ) ");            strSql.Append(" values (");            strSql.Append(" '" + mod.sysId + "','" + mod.recordId + "','" + mod.lrmID + "','" + mod.lrmName + "','" + mod.lrmType + "','" + mod.lrmX + "','" + mod.lrmY + "','" + mod.lrmState + "','" + mod.lrmTime + "',");            strSql.Append("'" + mod.rmk + "','" + mod.monitorDaySecurity + "','" + mod.commentMans + "','" + mod.dangerousMans + "','" + mod.mapId + "','" + mod.lrmRadius + "','" + mod.createDate + "','" + mod.projectCode + "','" + mod.del + "' ");            strSql.Append(" )  else ");            strSql.Append(" update tb_Emp_Readers ");            strSql.Append(" set ");            strSql.Append(" lrmID='" + mod.lrmID + "',lrmName='" + mod.lrmName + "',lrmType='" + mod.lrmType + "',lrmX='" + mod.lrmX + "',lrmY='" + mod.lrmY + "', ");            strSql.Append(" lrmState='" + mod.lrmState + "',lrmTime='" + mod.lrmTime + "',rmk='" + mod.rmk + "',monitorDaySecurity='" + mod.monitorDaySecurity + "',commentMans='" + mod.commentMans + "',dangerousMans='" + mod.dangerousMans + "',mapId='" + mod.mapId + "', ");            strSql.Append(" lrmRadius='" + mod.lrmRadius + "',createDate='" + mod.createDate + "',del='" + mod.del + "' ");            strSql.Append(" where recordId='" + mod.recordId + "' and projectCode='" + mod.projectCode + "' ");            return strSql.ToString();        }        #endregion
            #region 插入人员定位读头实时人员信息        [WebMethod]        public string synchEntryRecord(string uName, string pwd, string xml)        {
                tb_Emp_SysnBLL ol = new tb_Emp_SysnBLL();            string result = "0"; //发送成功            if (!uName.Equals(USERNAME) && !pwd.Equals(PWD)) return "-1";
                try            {                XmlDocument doc = new XmlDocument();                string sql1 = "";                doc.LoadXml(xml);                foreach (XmlNode node in doc.SelectNodes("entryrecords/entryrecord"))                {                    tb_Emp_EntryRecordModel mod =new tb_Emp_EntryRecordModel();                    mod.sysId = Guid.NewGuid().ToString().Replace("-", "");                    mod.recordId = Convert.ToInt32(node["recordId"].InnerText);                    mod.labelId = Convert.ToInt32(node["labelId"].InnerText);                    mod.lrmId = Convert.ToInt32(node["lrmId"].InnerText);                    mod.inTime = Convert.ToDateTime(node["inTime"].InnerText.Length > 0 ? node["inTime"].InnerText : "1900-01-01 00:00:00");                    mod.outTime = Convert.ToDateTime(node["outTime"].InnerText.Length > 0 ? node["outTime"].InnerText : "1900-01-01 00:00:00");                    mod.rmk = node["rmk"].InnerText;                    mod.empId = node["empId"].InnerText;                    mod.projectCode = node["projectCode"].InnerText;                    sql1 += synchEntryRecordSQL(mod);                    //ol.Add(mod);                }                ol.Add(sql1);            }            catch (Exception e)            {                result = e.Message; //返回异常信息            }            return result;        }        #endregion
            #region 人员定位读头实时人员信息sql拼接        public string synchEntryRecordSQL(tb_Emp_EntryRecordModel mod)        {            StringBuilder strSql = new StringBuilder();            strSql.Append("if not exists(select 1 from tb_Emp_EntryRecord where recordId='" + mod.recordId + "' and projectCode='" + mod.projectCode + "')");            strSql.Append(" insert into tb_Emp_EntryRecord ( ");            strSql.Append("  sysId,recordId,labelId,lrmId,inTime,outTime,rmk,empId,projectCode ");            strSql.Append(" ) ");            strSql.Append(" values (");            strSql.Append(" '" + mod.sysId + "','" + mod.recordId + "','" + mod.labelId + "','" + mod.lrmId + "','" + mod.inTime + "','" + mod.outTime + "','" + mod.rmk + "','" + mod.empId + "','" + mod.projectCode + "' ");            strSql.Append(" )  else ");            strSql.Append(" update tb_Emp_EntryRecord ");            strSql.Append(" set ");            strSql.Append(" labelId='" + mod.labelId + "',lrmId='" + mod.lrmId + "',inTime='" + mod.inTime + "',outTime='" + mod.outTime + "',rmk='" + mod.rmk + "', ");            strSql.Append(" empId='" + mod.empId + "' ");            strSql.Append(" where recordId='" + mod.recordId + "' and projectCode='" + mod.projectCode + "' ");            return strSql.ToString();        }        #endregion
            #region 在场人员统计信息        [WebMethod]        public string synchCurWorkers(string uName, string pwd, string xml)        {
                tb_Emp_SysnBLL ol = new tb_Emp_SysnBLL();            string result = "0"; //发送成功            if (!uName.Equals(USERNAME) && !pwd.Equals(PWD)) return "-1";
                try            {                XmlDocument doc = new XmlDocument();                string sql1 = "";                string sql2 = "";                doc.LoadXml(xml);                foreach (XmlNode node in doc.SelectNodes("workers/worker"))                {                    tb_Emp_CurWorkInfoModel mod = new tb_Emp_CurWorkInfoModel();                    mod.empId = node["empId"].InnerText;                    if (node["groupId"].InnerText.Length > 0) mod.groupId = Convert.ToInt32(node["groupId"].InnerText);                    else mod.groupId = null;                    if (node["IODate"].InnerText.Length > 0) mod.IODate = Convert.ToDateTime(node["IODate"].InnerText);                    else mod.IODate = null;                    if (node["director"].InnerText.Length > 0) mod.director = Convert.ToInt32(node["director"].InnerText);                    else mod.director = null;                    if (node["lastDirector"].InnerText.Length > 0) mod.lastDirector = Convert.ToInt32(node["lastDirector"].InnerText);                    else mod.lastDirector = null;                    if (node["type"].InnerText.Length > 0) mod.type = Convert.ToInt32(node["type"].InnerText);                    else mod.type = null;                    mod.projectCode = node["projectCode"].InnerText;

                        sql2 = " delete from tb_Emp_CurWorkInfo where projectCode='" + mod.projectCode + "' ";                    sql1 += synchCurWorkersSQL(mod);                    //ol.Add(mod);                }                sql2 += sql1;                ol.Add(sql2);            }            catch (Exception e)            {                result = e.Message; //返回异常信息            }            return result;        }        #endregion
            #region 在场人员统计信息sql拼接        public string synchCurWorkersSQL(tb_Emp_CurWorkInfoModel mod)        {            StringBuilder strSql = new StringBuilder();            strSql.Append(" insert into tb_Emp_CurWorkInfo ( ");            strSql.Append("  empId,groupId,IODate,director,lastDirector,type,projectCode ");            strSql.Append(" ) ");            strSql.Append(" values (");            strSql.Append(" '" + mod.empId + "','" + mod.groupId + "','" + mod.IODate + "','" + mod.director + "','" + mod.lastDirector + "','" + mod.type + "','" + mod.projectCode + "' ");            strSql.Append(" )  ");            return strSql.ToString();        }        #endregion
            #region 在场人员异常警告信息        [WebMethod]        public string synchWarnMessage(string uName, string pwd, string xml)        {
                tb_Emp_SysnBLL ol = new tb_Emp_SysnBLL();            string result = "0"; //发送成功            if (!uName.Equals(USERNAME) && !pwd.Equals(PWD)) return "-1";
                try            {                XmlDocument doc = new XmlDocument();                string sql1 = "";                doc.LoadXml(xml);                foreach (XmlNode node in doc.SelectNodes("warnMessages/warnMessage"))                {                    tb_Emp_WarnMessageModel mod = new tb_Emp_WarnMessageModel();                    mod.sysId = Guid.NewGuid().ToString().Replace("-", "");                    mod.recordId = node["recordId"].InnerText;                    mod.empId = node["empId"].InnerText;                    mod.content = node["content"].InnerText;                    mod.type = node["type"].InnerText;                    if (node["createDate"].InnerText.Length > 0) mod.createDate = Convert.ToDateTime(node["createDate"].InnerText);                    mod.projectCode = node["projectCode"].InnerText;                    sql1 += synchWarnMessageSQL(mod);                    //ol.Add(mod);                }                ol.Add(sql1);            }            catch (Exception e)            {                result = e.Message; //返回异常信息            }            return result;        }        #endregion
            #region 在场人员异常警告信息sql拼接        public string synchWarnMessageSQL(tb_Emp_WarnMessageModel mod)        {            StringBuilder strSql = new StringBuilder();            strSql.Append("if not exists(select 1 from tb_Emp_WarnMessage where recordId='" + mod.recordId + "' and projectCode='" + mod.projectCode + "')");            strSql.Append(" insert into tb_Emp_WarnMessage ( ");            strSql.Append("  sysId,recordId,empId,content,type,createDate,projectCode ");            strSql.Append(" ) ");            strSql.Append(" values (");            strSql.Append(" '" + mod.sysId + "','" + mod.recordId + "','" + mod.empId + "','" + mod.content + "','" + mod.type + "','" + mod.createDate.ToString("yyyy-MM-dd HH:mm:ss.fff") + "','" + mod.projectCode + "' ");            strSql.Append(" ) ");            return strSql.ToString();           }        #endregion


            #region 闸机设备列表信息        [WebMethod]        public string synchMachine(string uName, string pwd, string xml)        {
                tb_Emp_SysnBLL ol = new tb_Emp_SysnBLL();            string result = "0"; //发送成功            if (!uName.Equals(USERNAME) && !pwd.Equals(PWD)) return "-1";
                try            {                XmlDocument doc = new XmlDocument();                string sql1 = "";                doc.LoadXml(xml);                foreach (XmlNode node in doc.SelectNodes("machines/machine"))                {                    tb_Device_MachineModel mod = new tb_Device_MachineModel();                    mod.sysId = Guid.NewGuid().ToString().Replace("-", "");                    if (node["recordId"].InnerText.Length > 0) mod.recordId = Convert.ToInt32(node["recordId"].InnerText);                    else mod.recordId = null;                    mod.code = node["code"].InnerText;                    mod.name = node["name"].InnerText;                    if (node["goupId"].InnerText.Length > 0) mod.goupId = Convert.ToInt32(node["goupId"].InnerText);                    else mod.goupId = null;                    mod.ipAddress = node["ipAddress"].InnerText;                    if (node["computerId"].InnerText.Length > 0) mod.computerId = Convert.ToInt32(node["computerId"].InnerText);                    else mod.computerId = null;                    if (node["needSync"].InnerText.Length > 0) mod.needSync = Convert.ToInt32(node["needSync"].InnerText);                    else mod.needSync = null;                    mod.del = node["del"].InnerText;                    mod.projectCode = node["projectCode"].InnerText;                    sql1 += synchDevice_MachineSQL(mod);                    //ol.Add(mod);                }                ol.Add(sql1);            }            catch (Exception e)            {                result = e.Message; //返回异常信息            }            return result;        }        #endregion
            #region 闸机设备列表信息sql拼接        public string synchDevice_MachineSQL(tb_Device_MachineModel mod)        {            StringBuilder strSql = new StringBuilder();            strSql.Append("if not exists(select 1 from tb_Device_Machine where recordId='" + mod.recordId + "' and projectCode='" + mod.projectCode + "')");            strSql.Append(" insert into tb_Device_Machine ( ");            strSql.Append("  sysId,recordId,code,name,goupId,ipAddress,computerId,needSync,del,projectCode ");            strSql.Append(" ) ");            strSql.Append(" values (");            strSql.Append(" '" + mod.sysId + "','" + mod.recordId + "','" + mod.code + "','" + mod.name + "','" + mod.goupId + "','" + mod.ipAddress + "','" + mod.computerId + "','" + mod.needSync + "','" + mod.del + "',");            strSql.Append("'" + mod.projectCode + "' ");            strSql.Append(" )  else ");            strSql.Append(" update tb_Device_Machine ");            strSql.Append(" set ");            strSql.Append(" sysId='" + mod.sysId + "',recordId='" + mod.recordId + "',code='" + mod.code + "',name='" + mod.name + "',goupId='" + mod.goupId + "', ");            strSql.Append(" ipAddress='" + mod.ipAddress + "',computerId='" + mod.computerId + "',needSync='" + mod.needSync + "',del='" + mod.del + "',projectCode='" + mod.projectCode + "' ");            strSql.Append(" where recordId='" + mod.recordId + "' and projectCode='" + mod.projectCode + "' ");            return strSql.ToString();        }        #endregion
            #region 闸机设备列表信息        [WebMethod]        public string synchSafeTrain(string uName, string pwd, string xml)        {
                tb_Emp_SysnBLL ol = new tb_Emp_SysnBLL();            string result = "0"; //发送成功            if (!uName.Equals(USERNAME) && !pwd.Equals(PWD)) return "-1";
                try            {                XmlDocument doc = new XmlDocument();                string sql1 = "";                doc.LoadXml(xml);                foreach (XmlNode node in doc.SelectNodes("safeTrains/safeTrain"))                {                    tb_Emp_SafeTrainModel mod = new tb_Emp_SafeTrainModel();                    mod.sysId = node["sysId"].InnerText;                    mod.title = node["title"].InnerText;                    mod.content = node["content"].InnerText;                    mod.participants = node["participants"].InnerText;                    mod.participantNames = node["participantNames"].InnerText;                    if (node["createDate"].InnerText.Length > 0) mod.createDate = Convert.ToDateTime(node["createDate"].InnerText);                    else mod.createDate = null;                    mod.createUserMsgCode = node["createUserMsgCode"].InnerText;                    mod.createUserName = node["createUserName"].InnerText;                    mod.projectCode = node["projectCode"].InnerText;                    mod.del = node["del"].InnerText;                    sql1 += synchSafeTrainSQL(mod);                    //ol.Add(mod);                }                ol.Add(sql1);            }            catch (Exception e)            {                result = e.Message; //返回异常信息            }            return result;        }        #endregion
            #region 闸机设备列表信息sql拼接        public string synchSafeTrainSQL(tb_Emp_SafeTrainModel mod)        {            StringBuilder strSql = new StringBuilder();            strSql.Append("if not exists(select 1 from tb_Emp_SafeTrain where sysId='" + mod.sysId + "' and projectCode='" + mod.projectCode + "')");            strSql.Append(" insert into tb_Emp_SafeTrain ( ");            strSql.Append("  sysId,title,content,participants,participantNames,createDate,createUserMsgCode,createUserName,projectCode,del ");            strSql.Append(" ) ");            strSql.Append(" values (");            strSql.Append(" '" + mod.sysId + "','" + mod.title + "','" + mod.content + "','" + mod.participants + "','" + mod.participantNames + "','" + mod.createDate + "','" + mod.createUserMsgCode + "','" + mod.createUserName + "','" + mod.projectCode + "',");            strSql.Append("'" + mod.del + "' ");            strSql.Append(" )  else ");            strSql.Append(" update tb_Emp_SafeTrain ");            strSql.Append(" set ");            strSql.Append(" sysId='" + mod.sysId + "',title='" + mod.title + "',content='" + mod.content + "',participants='" + mod.participants + "',participantNames='" + mod.participantNames + "', ");            strSql.Append(" createDate='" + mod.createDate + "',createUserMsgCode='" + mod.createUserMsgCode + "',createUserName='" + mod.createUserName + "',projectCode='" + mod.projectCode + "',del='" + mod.del + "' ");            strSql.Append(" where sysId='" + mod.sysId + "' and projectCode='" + mod.projectCode + "' ");            return strSql.ToString();        }        #endregion    }}

  • 相关阅读:
    招隐-古琴曲-山中鸣琴,万籁声沉沉,何泠泠!
    因循苟且逸豫而无为,可以侥幸一时,而不可以旷日持久。——王安石
    模糊理论在图像处理中的应用
    铁关-中国首都警官合唱团-歌词
    听着总感觉莫名熟悉的音乐汇总
    石鼓歌-韩愈
    唐长安城
    唐长安的信仰——读书笔记
    Eclipse安装java web插件
    Java调用MySql数据库函数
  • 原文地址:https://www.cnblogs.com/Zpyboke/p/5302952.html
Copyright © 2011-2022 走看看