public Equ_PmSpecInfo GetEquDetailObj(Equ_PmSpecInfo equinfo, Equ_PmSpecInfo result)
        {
            DataTable dt          = new DataTable();
            string    ReturnValue = string.Empty;

            using (var conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ELCO_ConnectionString"].ToString()))
            {
                SqlCommand cmd = new SqlCommand();
                conn.Open();
                cmd.Connection = conn;
                string str1 = "select * from Equ_PmSpecList";
                if (equinfo.ID != "")
                {
                    str1 += " WHERE ID = " + equinfo.ID + " ";
                }
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = str1;
                SqlDataAdapter Datapter = new SqlDataAdapter(cmd);
                Datapter.Fill(dt);

                if (dt != null && dt.Rows.Count > 0)
                {
                    result.ID            = dt.Rows[0]["ID"].ToString();
                    result.ProcessCode   = dt.Rows[0]["ProcessCode"].ToString();
                    result.DeviceName    = dt.Rows[0]["DeviceName"].ToString();
                    result.PmSpecCode    = dt.Rows[0]["PmSpecCode"].ToString();
                    result.PmSpecName    = dt.Rows[0]["PmSpecName"].ToString();
                    result.PmLevel       = dt.Rows[0]["PmLevel"].ToString();
                    result.PmSpecFile    = dt.Rows[0]["PmSpecFile"].ToString();
                    result.PmSpecComment = dt.Rows[0]["PmSpecComment"].ToString();
                }
            }
            return(result);
        }
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            if (context.Session["UserName"] != null)
            {
                UserName = context.Session["UserName"].ToString().ToUpper().Trim();
            }
            else
            {
                UserName = "";
            }

            Action = RequstString("Action");

            if (Action.Length == 0)
            {
                Action = "";
            }

            if (Action == "EquMaintenceStandrad_Detail")
            {
                Equ_PmSpecInfo equinfo = new Equ_PmSpecInfo();
                equinfo.ID = RequstString("EquID");
                Equ_PmSpecInfo result = new Equ_PmSpecInfo();
                result = GetEquDetailObj(equinfo, result);
                context.Response.Write(jsc.Serialize(result));
            }
            else if (Action == "PmSpecFileUploadify")
            {
                HttpPostedFile             file   = System.Web.HttpContext.Current.Request.Files["Filedata"];
                ResultMsg_PmSpecFileUPload result = new ResultMsg_PmSpecFileUPload();
                result = doUploadFile(result, file);
                context.Response.Write(jsc.Serialize(result));
            }
            else if (Action == "EquMaintenceStandrad_Add")
            {
                Equ_PmSpecInfo dataEntity = new Equ_PmSpecInfo();
                //dataEntity.ID = RequstString("ProcId");
                dataEntity.ProcessCode   = RequstString("ProcessName");
                dataEntity.DeviceName    = RequstString("DeviceName");
                dataEntity.PmSpecCode    = RequstString("PmSpecCode");
                dataEntity.PmSpecName    = RequstString("PmSpecName");
                dataEntity.PmLevel       = RequstString("PmLevel");
                dataEntity.PmSpecFile    = RequstString("PmSpecFile");
                dataEntity.UploadedFile  = RequstString("UploadedPmSpecFile");
                dataEntity.PmSpecComment = RequstString("PmSpecComment");
                ResultMsg_Equ_PmSpec result = new ResultMsg_Equ_PmSpec();
                result = addEquMaintenceStandradDataInDB(dataEntity, result);
                context.Response.Write(jsc.Serialize(result));
            }
            else if (Action == "EquMaintenceStandrad_Edit")
            {
                Equ_PmSpecInfo dataEntity = new Equ_PmSpecInfo();
                dataEntity.ID           = RequstString("EquID");
                dataEntity.ProcessCode  = RequstString("ProcessName");
                dataEntity.DeviceName   = RequstString("DeviceName");
                dataEntity.PmSpecCode   = RequstString("PmSpecCode");
                dataEntity.PmSpecName   = RequstString("PmSpecName");
                dataEntity.PmLevel      = RequstString("PmLevel");
                dataEntity.PmSpecFile   = RequstString("PmSpecFile");
                dataEntity.UploadedFile = RequstString("UploadedPmSpecFile");

                ResultMsg_Equ_PmSpec result = new ResultMsg_Equ_PmSpec();
                result = editEquMaintenceStandradDataInDB(dataEntity, result);
                context.Response.Write(jsc.Serialize(result));
            }
            else if (Action == "StandardFileCHECK" || Action == "StandardFileDOWNLOAD" || Action == "PmStandardFileCHECK")
            {
                string objID    = RequstString("objID");
                string fileName = string.Empty;
                if (Action == "StandardFileCHECK" || Action == "StandardFileDOWNLOAD")
                {
                    fileName = GetEquStandardFileNameFromDB(objID);
                }
                else
                {
                    fileName = GetEquPmStandardFileNameFromDB(objID);
                }
                string   fileType        = Path.GetExtension(fileName).ToLower();
                FileInfo fileInfo        = new FileInfo(browsePmSpecFilePath + fileName);
                string   fileWithoutType = Path.GetFileNameWithoutExtension(fileName);
                if (!Directory.Exists(browsePmSpecFilePath))
                {
                    Directory.CreateDirectory(browsePmSpecFilePath);
                }
                context.Response.ClearContent();
                context.Response.ClearHeaders();
                if (Action == "StandardFileCHECK" || Action == "PmStandardFileCHECK")
                {
                    if (fileType == ".docx" || fileType == ".doc")
                    {
                        string path = browsePmSpecFilePath + Common.StringFilter.FilterSpecial(fileName);
                        try
                        {
                            //读取doc文档
                            Document doc = new Document(path);
                            ////保存为PDF文件,此处的SaveFormat支持很多种格式,如图片,epub,rtf 等等
                            doc.Save(browsePmSpecFilePath + fileWithoutType + ".pdf", Aspose.Words.SaveFormat.Pdf);
                            //Workbook wb = new Workbook(path);
                            //wb.Save(browseManualFilePath + fileWithoutType + ".pdf", SaveFormat.Pdf);
                            context.Response.Write("./PmSpecFile/" + fileWithoutType + ".pdf");
                        }
                        catch (Exception ex)
                        {
                            context.Response.Write("false");
                        }
                    }
                    else
                    {
                        context.Response.Write("./PmSpecFile/" + fileWithoutType + ".pdf");
                    }
                }
                else
                {
                    if (fileType == ".docx" || fileType == ".doc")
                    {
                        context.Response.AppendHeader("content-type", "application/msword");
                    }
                    else if (fileType == ".xlsx" || fileType == ".xls")
                    {
                        context.Response.AppendHeader("content-type", "application/x-msexcel");
                    }
                    else if (fileType == ".pdf")
                    {
                        context.Response.AppendHeader("content-type", "application/pdf");
                    }

                    try
                    {
                        FileInfo fileInfo1 = new FileInfo(browsePmSpecFilePath + Common.StringFilter.FilterSpecial(fileName));
                        context.Response.AddHeader("content-length", fileInfo1.Length.ToString());//文件大小
                        context.Response.WriteFile(browsePmSpecFilePath + Common.StringFilter.FilterSpecial(fileName));
                    }
                    catch (Exception ex)
                    {
                        context.Response.Write(ex.Message);
                    }
                    context.Response.Flush();
                    context.Response.Close();
                }
            }
        }
        public ResultMsg_Equ_PmSpec editEquMaintenceStandradDataInDB(Equ_PmSpecInfo dataEntity, ResultMsg_Equ_PmSpec result)
        {
            if (dataEntity.ID.Length == 0)
            {
                dataEntity.ID = "0";
            }
            //if (dataEntity.ProcessCode.Length == 0) dataEntity.ProcessCode = "";
            //if (dataEntity.ProcessName.Length == 0) dataEntity.ProcessName = "";
            //if (dataEntity.ProcessBeat.Length == 0) dataEntity.ProcessBeat = "";
            //if (dataEntity.ProcessDsca.Length == 0) dataEntity.ProcessDsca = "";
            //if (dataEntity.InturnNumber.Length == 0) dataEntity.InturnNumber = "0";
            //if (dataEntity.ProcessManual.Length == 0) dataEntity.ProcessManual = "";
            using (var conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ELCO_ConnectionString"].ToString()))
            {
                SqlCommand     cmd         = new SqlCommand();
                SqlTransaction transaction = null;
                try
                {
                    conn.Open();
                    cmd.Connection = conn;

                    string strSql = " SELECT COUNT(1) AS SM FROM Equ_PmSpecList WHERE PmSpecCode = '" + dataEntity.PmSpecCode + "' and ID <> " + dataEntity.ID;
                    cmd.CommandType = CommandType.Text;
                    cmd.CommandText = strSql;
                    SqlDataAdapter Datapter = new SqlDataAdapter(cmd);
                    DataTable      dt       = new DataTable();
                    Datapter.Fill(dt);

                    if (dt != null && dt.Rows.Count > 0)
                    {
                        if (Convert.ToInt32(dt.Rows[0]["SM"]) > 0)
                        {
                            result.result = "failed";
                            result.msg    = "此保养规范编号已经存在, 请核对!";
                        }
                        else
                        {
                            result.result = "";
                            result.msg    = "";
                        }
                    }
                    else
                    {
                        result.result = "failed";
                        result.msg    = "数据重复性检查失败!";
                    }

                    if (result.result == "")
                    {
                        transaction     = conn.BeginTransaction();
                        cmd.Transaction = transaction;
                        strSql          = string.Format(
                            @" UPDATE Equ_PmSpecList SET 
                                                  ProcessCode  = '{0}' 
                                                , DeviceName  = '{1}'
                                                , PmSpecCode  = '{2}'
                                                , PmSpecName = '{3}'
                                                , PmLevel= '{4}'
                                                , PmSpecFile= '{5}'
                                                , PmSpecComment= '{6}'
                                                , UpdateUser   = '******'
                                                , UpdateTime   = getdate()
                                                WHERE id = {8}
                                            ",
                            dataEntity.ProcessCode,
                            dataEntity.DeviceName,
                            dataEntity.PmSpecCode,
                            dataEntity.PmSpecName,
                            dataEntity.PmLevel,
                            dataEntity.PmSpecFile,
                            dataEntity.PmSpecComment,
                            UserName,
                            dataEntity.ID
                            );
                        cmd.CommandType = CommandType.Text;
                        cmd.CommandText = strSql;
                        cmd.ExecuteNonQuery();

                        if (dataEntity.UploadedFile != dataEntity.PmSpecFile)
                        {
                            string strFileMoveResult = "";

                            strFileMoveResult = doManualFileMove(dataEntity.UploadedFile, dataEntity.PmSpecCode);
                            if (strFileMoveResult.Length == 0)
                            {
                                transaction.Commit();
                                result.result = "success";
                                result.msg    = "保存数据成功!";
                            }
                            else
                            {
                                transaction.Rollback();
                                result.result = "failed";
                                result.msg    = "服务器端文件处理发生错误.\n" + strFileMoveResult;
                            }
                        }
                        else
                        {
                            string fileType       = Path.GetExtension(dataEntity.PmSpecFile).ToLower();
                            string targetFileName = dataEntity.PmSpecCode + fileType;
                            if (fileType == ".docx" || fileType == ".doc")
                            {
                                //读取doc文档
                                Document doc = new Document(browsePmSpecFilePath + Common.StringFilter.FilterSpecial(targetFileName));
                                ////保存为PDF文件,此处的SaveFormat支持很多种格式,如图片,epub,rtf 等等
                                doc.Save(browsePmSpecFilePath + dataEntity.PmSpecCode + ".pdf", SaveFormat.Pdf);
                            }
                            transaction.Commit();
                            result.result = "success";
                            result.msg    = "保存数据成功!";
                        }
                    }
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    result.result = "failed";
                    result.msg    = "保存失败! \n" + ex.Message;
                }
            }
            return(result);
        }
        public ResultMsg_Equ_PmSpec addEquMaintenceStandradDataInDB(Equ_PmSpecInfo dataEntity, ResultMsg_Equ_PmSpec result)
        {
            if (dataEntity.ProcessCode.Length == 0)
            {
                dataEntity.ProcessCode = "";
            }
            if (dataEntity.DeviceName.Length == 0)
            {
                dataEntity.DeviceName = "";
            }
            if (dataEntity.PmSpecCode.Length == 0)
            {
                dataEntity.PmSpecCode = "";
            }
            if (dataEntity.PmSpecName.Length == 0)
            {
                dataEntity.PmSpecName = "";
            }
            if (dataEntity.PmLevel.Length == 0)
            {
                dataEntity.PmLevel = "";
            }
            if (dataEntity.PmSpecFile.Length == 0)
            {
                dataEntity.PmSpecFile = "";
            }
            if (dataEntity.PmSpecComment.Length == 0)
            {
                dataEntity.PmSpecComment = "";
            }

            using (var conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ELCO_ConnectionString"].ToString()))
            {
                SqlCommand     cmd         = new SqlCommand();
                SqlTransaction transaction = null;
                try
                {
                    conn.Open();
                    cmd.Connection = conn;
                    string strSql = " SELECT COUNT(1) AS SM FROM Equ_PmSpecList WHERE PmSpecCode = '" + dataEntity.PmSpecCode + "' ";
                    cmd.CommandType = CommandType.Text;
                    cmd.CommandText = strSql;
                    SqlDataAdapter Datapter = new SqlDataAdapter(cmd);
                    DataTable      dt       = new DataTable();
                    Datapter.Fill(dt);

                    if (dt != null && dt.Rows.Count > 0)
                    {
                        if (Convert.ToInt32(dt.Rows[0]["SM"]) > 0)
                        {
                            result.result = "failed";
                            result.msg    = "此保养规范编号已经存在, 请核对!";
                        }
                        else
                        {
                            result.result = "";
                            result.msg    = "";
                        }
                    }
                    else
                    {
                        result.result = "failed";
                        result.msg    = "数据重复性检查失败!";
                    }

                    if (result.result == "")
                    {
                        transaction     = conn.BeginTransaction();
                        cmd.Transaction = transaction;
                        strSql          = string.Format(
                            @" INSERT INTO Equ_PmSpecList  
                        (  ProcessCode, DeviceName, PmSpecCode, PmSpecName, PmLevel,PmSpecFile,PmSpecComment, UpdateUser, UpdateTime) VALUES (
                          '{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}',getdate()) ",
                            dataEntity.ProcessCode,
                            dataEntity.DeviceName,
                            dataEntity.PmSpecCode,
                            dataEntity.PmSpecName,
                            dataEntity.PmLevel,
                            dataEntity.PmSpecFile,
                            dataEntity.PmSpecComment,
                            UserName
                            );
                        cmd.CommandType = CommandType.Text;
                        cmd.CommandText = strSql;
                        cmd.ExecuteNonQuery();

                        string strFileMoveResult = "";
                        strFileMoveResult = doManualFileMove(dataEntity.UploadedFile, dataEntity.PmSpecCode);
                        if (strFileMoveResult.Length == 0)
                        {
                            transaction.Commit();
                            result.result = "success";
                            result.msg    = "保存数据成功!";
                        }
                        else
                        {
                            transaction.Rollback();
                            result.result = "failed";
                            result.msg    = "服务器端文件处理发生错误.\n" + strFileMoveResult;
                        }
                    }
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    result.result = "failed";
                    result.msg    = "保存失败! \n" + ex.Message;
                }
            }
            return(result);
        }