Example #1
0
        public void ProcessRequest(HttpContext context)
        {
            //允许跨域
            context.Response.AddHeader("Access-Control-Allow-Origin", "*");
            JSON_MSG jsonMsg = new JSON_MSG();

            try
            {
                context.Response.ContentType = "text/plain";
                HttpRequest request = context.Request;

                StringBuilder rsb       = new StringBuilder();
                int           bytelengg = (int)request.InputStream.Length;
                using (var reader = new StreamReader(request.InputStream, Encoding.UTF8))
                {
                    var read  = new Char[bytelengg];
                    var count = reader.Read(read, 0, bytelengg);
                    while (count > 0)
                    {
                        var str = new string(read, 0, count);
                        rsb.Append(str);
                        count = reader.Read(read, 0, bytelengg);
                    }
                    reader.Close();
                    reader.Dispose();
                    request.InputStream.Close();
                    request.InputStream.Dispose();
                }

                if (string.IsNullOrEmpty(rsb.ToString()))
                {
                    throw new Exception("参数错误.");
                }

                JsonMCE_MT_APPLY entity = JsonConvert.DeserializeObject <JsonMCE_MT_APPLY>(rsb.ToString());


                if (string.IsNullOrEmpty(entity.CODE))
                {
                    throw new Exception("参数错误,单号不能为空.");
                }



                if (string.IsNullOrEmpty(entity.APPLY_DEPT_ID))
                {
                    throw new Exception("参数错误,报修科室不能为空.");
                }

                if (string.IsNullOrEmpty(entity.APPLY_USER_ID))
                {
                    throw new Exception("参数错误,报修人不能为空.");
                }

                if (string.IsNullOrEmpty(entity.CREATE_DATE))
                {
                    throw new Exception("参数错误,报修时间不能为空.");
                }

                if (string.IsNullOrEmpty(entity.ASSETS_ID))
                {
                    throw new Exception("参数错误,设备名称不能为空.");
                }

                if (string.IsNullOrEmpty(entity.FAULT_DESC))
                {
                    throw new Exception("参数错误,故障描述不能为空.");
                }

                BizLogicMsg msg = BizLogicObject_MCE_B_ASSETS_MT_APPLY.Proxy.Save_Ext(entity);


                jsonMsg.Succeed = 1;
                jsonMsg.Message = msg.Message;
            }
            catch (Exception ex)
            {
                jsonMsg.Succeed = 0;
                jsonMsg.Message = ex.Message;
            }
            finally
            {
                context.Response.Write(JsonConvert.SerializeObject(jsonMsg));
                context.Response.End();
            }
        }
        public BizLogicMsg Save_Ext(JsonMCE_MT_APPLY json)
        {
            if (LocalMode)
            {
                BizLogicMsg msg = new BizLogicMsg();
                using (IDbConnection connection = IDALProvider.IDAL.PopConnection())
                {
                    using (IDbTransaction transaction = connection.BeginTransaction())
                    {
                        try
                        {
                            EntityObject_MCE_B_ASSETS_MT_APPLY entity = new EntityObject_MCE_B_ASSETS_MT_APPLY();


                            if (!string.IsNullOrEmpty(json.ID))
                            {
                                entity.ID = json.ID;

                                entity = HelperObject_MCE_B_ASSETS_MT_APPLY.Get(entity);

                                if (entity == null)
                                {
                                    throw new Exception("获取数据出错.");
                                }
                            }


                            entity.CODE          = json.CODE;
                            entity.APPLY_DEPT_ID = json.APPLY_DEPT_ID;
                            entity.APPLY_USER_ID = json.APPLY_USER_ID;
                            entity.ASSETS_ID     = json.ASSETS_ID;
                            entity.ASSETS_CODE   = json.ASSETS_CODE;
                            entity.SPEC          = json.SPEC;

                            entity.ASSETS_TYPE_ID   = json.ASSETS_TYPE_ID;
                            entity.PRD_ID           = json.PRD_ID;
                            entity.MTN_TYPE_ID      = json.MTN_TYPE_ID;
                            entity.FAULT_TYPE       = json.FAULT_TYPE;
                            entity.EMERGENCY_DEGREE = json.EMERGENCY_DEGREE;
                            entity.REPAIR_RESULT    = json.REPAIR_RESULT;

                            if (!string.IsNullOrEmpty(json.CREATE_DATE))
                            {
                                entity.CREATE_DATE = DateTime.Parse(json.CREATE_DATE);
                            }

                            entity.APPLY_USER_PHONE = json.APPLY_USER_PHONE;

                            if (!string.IsNullOrEmpty(json.COMPLETE_TIME))
                            {
                                entity.COMPLETE_TIME = DateTime.Parse(json.COMPLETE_TIME);
                            }

                            entity.MTN_ENGINEER = json.MTN_ENGINEER;

                            if (!string.IsNullOrEmpty(json.MTN_TOTAL_HOURS))
                            {
                                entity.MTN_TOTAL_HOURS = decimal.Parse(json.MTN_TOTAL_HOURS);
                            }

                            if (!string.IsNullOrEmpty(json.MAINTAIN_MONEY))
                            {
                                entity.MAINTAIN_MONEY = decimal.Parse(json.MAINTAIN_MONEY);
                            }

                            entity.INVOICE_CODE   = json.INVOICE_CODE;
                            entity.FAULT_DESC     = json.FAULT_DESC;
                            entity.FAULT_ANALYSIS = json.FAULT_ANALYSIS;
                            entity.FAULT_SOLUTION = json.FAULT_SOLUTION;

                            if (string.IsNullOrEmpty(entity.ID))
                            {
                                entity.STATE          = 1;
                                entity.CREATE_TIME    = DateTime.Now;
                                entity.CREATE_USER_ID = Ipedf.Web.BizLogic.SystemLogic.Proxy.CurrentUser.ID;
                                int amount = HelperObject_MCE_B_ASSETS_MT_APPLY.Save(entity, transaction);
                            }
                            else
                            {
                                entity.MODIFY_TIME    = DateTime.Now;
                                entity.MODIFY_USER_ID = Ipedf.Web.BizLogic.SystemLogic.Proxy.CurrentUser.ID;

                                int amount = HelperObject_MCE_B_ASSETS_MT_APPLY.Update(entity, transaction);


                                CauseObject_COM_FILE pCOM_FILE = new CauseObject_COM_FILE();
                                pCOM_FILE.REF_TAB_ID   = entity.ID;
                                pCOM_FILE.REF_TAB_NAME = "MCE_B_ASSETS_MT_APPLY";
                                HelperObject_COM_FILE.Delete(pCOM_FILE, transaction);
                            }


                            if (json.listAttach != null && json.listAttach.Count > 0)
                            {
                                foreach (JsonMCEMT_APPLY_MTN_ATTACH item in json.listAttach)
                                {
                                    Ipedf.Web.Entity.EntityObject_COM_FILE entityPicFile = new Ipedf.Web.Entity.EntityObject_COM_FILE();
                                    entityPicFile.REF_TAB_NAME   = "MCE_B_ASSETS_MT_APPLY";
                                    entityPicFile.CLIENT_NAME    = item.CLIENT_NAME;
                                    entityPicFile.STATE          = 1;
                                    entityPicFile.CREATE_TIME    = item.CREATE_TIME;
                                    entityPicFile.CREATE_USER_ID = Ipedf.Web.BizLogic.SystemLogic.Proxy.CurrentUser.ID;
                                    entityPicFile.REF_TAB_ID     = entity.ID;
                                    entityPicFile.SERVER_NAME    = item.SERVER_NAME;
                                    entityPicFile.IS_IMPORT      = 0;
                                    Ipedf.Web.DataAccess.HelperObject_COM_FILE.Save(entityPicFile, transaction);
                                }
                            }


                            msg.Message = entity.ID;

                            transaction.Commit();
                        }
                        catch (Exception expt)
                        {
                            transaction.Rollback();
                            msg = new BizLogicMsg(false, expt.Message);
                            Error(expt);
                        }
                        finally
                        {
                            IDALProvider.IDAL.PushConnection(connection);
                        }
                    }
                }
                return(msg);
            }
            else
            {
                using (ServiceManager <ServiceContract_MCE_B_ASSETS_MT_APPLY> smgr = new ServiceManager <ServiceContract_MCE_B_ASSETS_MT_APPLY>(ServiceUri))
                {
                    return(smgr.Service.Save_Ext(json));
                }
            }
        }