public BizLogicMsg Save_Ext(JsonMceAssetsDeprAllot item)
        {
            if (LocalMode)
            {
                BizLogicMsg msg = new BizLogicMsg();
                using (IDbConnection connection = IDALProvider.IDAL.PopConnection())
                {
                    using (IDbTransaction transaction = connection.BeginTransaction())
                    {
                        try
                        {
                            EntityObject_MCE_B_ASSETS_DEPR_ALLOT obj = new EntityObject_MCE_B_ASSETS_DEPR_ALLOT();

                            if (!string.IsNullOrEmpty(item.id))
                            {
                                obj.ID = item.id;

                                obj = HelperObject_MCE_B_ASSETS_DEPR_ALLOT.Get(obj);

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

                            obj.DEPT_ID   = item.dept_id;
                            obj.DEPR_ID   = item.depr_id;
                            obj.ASSETS_ID = item.assets_id;
                            if (!string.IsNullOrEmpty(item.ratio))
                            {
                                obj.RATIO = decimal.Parse(item.ratio);
                            }

                            if (!string.IsNullOrEmpty(item.depr_years))
                            {
                                obj.DEPR_YEARS = decimal.Parse(item.depr_years);
                            }

                            obj.COMMENTS = item.comments;


                            if (string.IsNullOrEmpty(item.id))
                            {
                                obj.AUDIT_STATE = 1;
                                obj.CREATE_TIME = DateTime.Now;
                                HelperObject_MCE_B_ASSETS_DEPR_ALLOT.Save(obj, transaction);
                            }
                            else
                            {
                                obj.ID = item.id;
                                HelperObject_MCE_B_ASSETS_DEPR_ALLOT.Update(obj, transaction);
                            }

                            if (item.listFileName != null && (item.listFileName.Count > 0))
                            {
                                foreach (JsonMceAssetsFileInfo objFullName in item.listFileName)
                                {
                                    if (!string.IsNullOrEmpty(objFullName.saveName))
                                    {
                                        try
                                        {
                                            string strFileURL = System.Web.HttpContext.Current.Server.MapPath("~/upload/mce/" + objFullName.saveName);//路径
                                            if (File.Exists(strFileURL))
                                            {
                                                CauseObject_COM_FILE pCOM_FILE = new CauseObject_COM_FILE();
                                                pCOM_FILE.REF_TAB_ID   = obj.ID;
                                                pCOM_FILE.REF_TAB_NAME = "MCE_B_ASSETS_DEPR_ALLOT";
                                                pCOM_FILE.SERVER_NAME  = objFullName.saveName;
                                                DisplayObject_COM_FILE[] listCOM_FILE = BizLogicObject_COM_FILE.Proxy.Query(pCOM_FILE);

                                                if (listCOM_FILE == null || listCOM_FILE.Length == 0)
                                                {
                                                    Ipedf.Web.Entity.EntityObject_COM_FILE entityPicFile = new Ipedf.Web.Entity.EntityObject_COM_FILE();
                                                    entityPicFile.REF_TAB_NAME   = "MCE_B_ASSETS_DEPR_ALLOT";
                                                    entityPicFile.CLIENT_NAME    = objFullName.fileName;
                                                    entityPicFile.STATE          = 1;
                                                    entityPicFile.CREATE_TIME    = DateTime.Now;
                                                    entityPicFile.CREATE_USER_ID = Ipedf.Web.BizLogic.SystemLogic.Proxy.CurrentUser.ID;
                                                    entityPicFile.REF_TAB_ID     = obj.ID;
                                                    entityPicFile.SERVER_NAME    = objFullName.saveName;
                                                    entityPicFile.IS_IMPORT      = 0;
                                                    Ipedf.Web.DataAccess.HelperObject_COM_FILE.Save(entityPicFile, transaction);
                                                }
                                            }
                                        }
                                        catch { }
                                    }
                                }
                            }

                            msg.Message = obj.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_DEPR_ALLOT> smgr = new ServiceManager <ServiceContract_MCE_B_ASSETS_DEPR_ALLOT>(ServiceUri))
                {
                    return(smgr.Service.Save_Ext(item));
                }
            }
        }
Ejemplo n.º 2
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("参数错误.");
                }

                JsonMceAssetsDeprAllot item = JsonConvert.DeserializeObject <JsonMceAssetsDeprAllot>(rsb.ToString());

                if (string.IsNullOrEmpty(item.dept_id))
                {
                    throw new Exception("分配部门不能为空.");
                }

                BizLogicMsg msg = BizLogicObject_MCE_B_ASSETS_DEPR_ALLOT.Proxy.Save_Ext(item);
                if (!msg.Succeed)
                {
                    throw new Exception(msg.Message);
                }

                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();
            }
        }