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_Contract entity = JsonConvert.DeserializeObject <JsonMCE_Contract>(rsb.ToString());


                if (string.IsNullOrEmpty(entity.CODE))
                {
                    throw new Exception("参数错误,合同编号不能为空.");
                }
                if (string.IsNullOrEmpty(entity.NAME))
                {
                    throw new Exception("参数错误,合同名称不能为空.");
                }

                if (string.IsNullOrEmpty(entity.SIGN_DATE))
                {
                    throw new Exception("参数错误,签定日期不能为空.");
                }

                if (string.IsNullOrEmpty(entity.EXPIRE_DATE))
                {
                    throw new Exception("参数错误,截止日期不能为空.");
                }

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

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

                if (string.IsNullOrEmpty(entity.MONEY))
                {
                    throw new Exception("参数错误,合同金额不能为空.");
                }



                if (entity.children != null && entity.children.Count > 0)
                {
                    foreach (JsonMCE_Contract_D item in entity.children)
                    {
                        if (string.IsNullOrEmpty(item.ASSET_ID))
                        {
                            throw new Exception("参数错误,设备名称不能为空.");
                        }
                    }
                }
                else
                {
                    throw new Exception("没有明细数据");
                }


                BizLogicMsg msg = BizLogicObject_MCE_B_ASSETS_CONTRACT.Proxy.Save_Ext2(entity);
                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();
            }
        }
Beispiel #2
0
        public BizLogicMsg Save_Ext2(JsonMCE_Contract json)
        {
            if (LocalMode)
            {
                BizLogicMsg msg = new BizLogicMsg();
                using (IDbConnection connection = IDALProvider.IDAL.PopConnection())
                {
                    using (IDbTransaction transaction = connection.BeginTransaction())
                    {
                        try
                        {
                            EntityObject_MCE_B_ASSETS_CONTRACT entity = new EntityObject_MCE_B_ASSETS_CONTRACT();


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

                                entity = HelperObject_MCE_B_ASSETS_CONTRACT.Get(entity);

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

                            entity.CODE = json.CODE;
                            entity.NAME = json.NAME;

                            if (!string.IsNullOrEmpty(json.SIGN_DATE))
                            {
                                entity.SIGN_DATE = DateTime.Parse(json.SIGN_DATE);
                            }
                            if (!string.IsNullOrEmpty(json.EXPIRE_DATE))
                            {
                                entity.EXPIRE_DATE = DateTime.Parse(json.EXPIRE_DATE);
                            }
                            entity.TYPE_ID     = json.TYPE_ID;
                            entity.FIRST_PARTY = json.FIRST_PARTY;

                            entity.SECOND_PARTY       = json.SECOND_PARTY;
                            entity.SECOND_LINK_PERSON = json.SECOND_LINK_PERSON;
                            entity.SECOND_LINK_PHONE  = json.SECOND_LINK_PHONE;

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

                            entity.ARCHIVE_NO = json.ARCHIVE_NO;

                            if (!string.IsNullOrEmpty(json.CHECK_DATE))
                            {
                                entity.CHECK_DATE = DateTime.Parse(json.CHECK_DATE);
                            }
                            entity.ARCHIVIST        = json.ARCHIVIST;
                            entity.INPUT_PERSON     = json.INPUT_PERSON;
                            entity.CONTRACT_CONTENT = json.CONTRACT_CONTENT;


                            entity.STATE = 1;

                            if (string.IsNullOrEmpty(json.ID))
                            {
                                entity.CONTRACT_STATE = 1;
                                entity.CREATE_TIME    = DateTime.Now;
                                entity.CREATE_USER_ID = Ipedf.Web.BizLogic.SystemLogic.Proxy.CurrentUser.ID;
                                int amount = HelperObject_MCE_B_ASSETS_CONTRACT.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_CONTRACT.Update(entity, transaction);


                                CauseObject_MCE_B_ASSETS_CONTRACT_D pCONTRACT_D = new CauseObject_MCE_B_ASSETS_CONTRACT_D();
                                pCONTRACT_D.BASE_ID = json.ID;
                                HelperObject_MCE_B_ASSETS_CONTRACT_D.Delete(pCONTRACT_D, 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_CONTRACT";
                                HelperObject_COM_FILE.Delete(pCOM_FILE, transaction);


                                DisplayObject_MCE_B_ASSETS_CONTRACT_PAY[] list_Pay = BizLogicObject_MCE_B_ASSETS_CONTRACT_PAY.Proxy.Query(new CauseObject_MCE_B_ASSETS_CONTRACT_PAY()
                                {
                                    BASE_ID = entity.ID
                                });
                                if (list_Pay != null && list_Pay.Length > 0)
                                {
                                    foreach (DisplayObject_MCE_B_ASSETS_CONTRACT_PAY item_Pay in list_Pay)
                                    {
                                        var v_Pay = json.listPay.Find(l => l.ID == item_Pay.ID);
                                        if (v_Pay == null)
                                        {
                                            HelperObject_MCE_B_ASSETS_CONTRACT_PAY.Delete(item_Pay, transaction);
                                        }
                                    }
                                }
                            }


                            if (json.children != null && json.children.Count > 0)
                            {
                                foreach (JsonMCE_Contract_D item in json.children)
                                {
                                    EntityObject_MCE_B_ASSETS_CONTRACT_D entity_D = new EntityObject_MCE_B_ASSETS_CONTRACT_D();

                                    entity_D.BASE_ID  = entity.ID;
                                    entity_D.ASSET_ID = item.ASSET_ID;

                                    HelperObject_MCE_B_ASSETS_CONTRACT_D.Save(entity_D, transaction);
                                }
                            }


                            if (json.listPay != null && json.listPay.Count > 0)
                            {
                                foreach (JsonMCE_Contract_Pay item in json.listPay)
                                {
                                    EntityObject_MCE_B_ASSETS_CONTRACT_PAY entity_D = new EntityObject_MCE_B_ASSETS_CONTRACT_PAY();

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

                                        entity_D = HelperObject_MCE_B_ASSETS_CONTRACT_PAY.Get(entity_D);

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

                                    entity_D.BASE_ID = entity.ID;
                                    entity_D.PERIODS = item.PERIODS;
                                    if (!string.IsNullOrEmpty(item.MONEY))
                                    {
                                        entity_D.MONEY = decimal.Parse(item.MONEY);
                                    }
                                    if (!string.IsNullOrEmpty(item.PLAN_PAY_DATE))
                                    {
                                        entity_D.PLAN_PAY_DATE = DateTime.Parse(item.PLAN_PAY_DATE);
                                    }

                                    if (string.IsNullOrEmpty(item.ID))
                                    {
                                        entity_D.STATE = 2;
                                        HelperObject_MCE_B_ASSETS_CONTRACT_PAY.Save(entity_D, transaction);
                                    }
                                    else
                                    {
                                        HelperObject_MCE_B_ASSETS_CONTRACT_PAY.Update(entity_D, 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_CONTRACT";
                                    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_CONTRACT> smgr = new ServiceManager <ServiceContract_MCE_B_ASSETS_CONTRACT>(ServiceUri))
                {
                    return(smgr.Service.Save_Ext2(json));
                }
            }
        }