private void GetMaterialapplication(HttpContext context)
        {
            string materialapplicationid = context.Request["materialapplicationid"];
            string processnumber         = context.Request["processnumber"];
            string sql  = "";
            string json = "";

            try
            {
                if (!string.IsNullOrEmpty(materialapplicationid))
                {
                    sql += " and materialapplicationid='" + materialapplicationid + "'  ";
                }

                if (!string.IsNullOrEmpty(processnumber) && string.IsNullOrEmpty(materialapplicationid))
                {
                    sql += " and processnumber='" + processnumber + "'  ";
                }

                TBL_MATERIALAPPLICATION ma = maBLL.GetMaterialapplication(sql);

                if (ma == null)
                {
                    json = "{IsSuccess:'false',Message:'数据不存在!'}";
                }
                else
                {
                    json = JsonConvert.SerializeObject(ma);

                    json = "{IsSuccess:'true',Message:'" + json + "'}";
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
                json = "{IsSuccess:'false',Message:'获取数据失败!'}";
            }
            json = JsonConvert.SerializeObject(json);
            context.Response.ContentType = "application/json";
            //返回JSON结果
            context.Response.Write(json);
            context.Response.End();
        }
        private void add(HttpContext context)
        {
            string json = "{IsSuccess:'true',Message:'保存成功!'}";
            //List<TBL_MATERIALAPPLICATION_PROJECT> pList = new List<TBL_MATERIALAPPLICATION_PROJECT>();
            //TBL_MATERIALAPPLICATION ma = new TBL_MATERIALAPPLICATION();
            //ma.materialapplicationid = System.Guid.NewGuid().ToString().ToUpper();
            //ma.processnumber = context.Request["processnumber"];
            //ma.organizationid = context.Request["organizationid"];
            //ma.applicantname = context.Request["applicantname"];
            //ma.useinstructions = context.Request["useinstructions"];
            //ma.submitdate = context.Request["submitdate"];
            string flowstate = context.Request["flowstate"];

            try
            {
                TBL_MATERIALAPPLICATION ma = CFunctions.JsonDeserialize <TBL_MATERIALAPPLICATION>(context.Request["materialapply"].ToString());
                ma.materialapplicationid = System.Guid.NewGuid().ToString().ToUpper();
                WorkFlow.Model.FLOW_TASK tasks = WorkFlow.BLL.Operate.GetTask(ma.processnumber);
                if (tasks == null)
                {
                    DaoFactory.BeginTransaction();


                    List <TBL_MATERIALAPPLICATION> maList = maBLL.GetList(" and processnumber='" + ma.processnumber + "' ").ToList <TBL_MATERIALAPPLICATION>();
                    if (maList.Count == 0)
                    {
                        if (maBLL.Insert(ma))
                        {
                            foreach (TBL_MATERIALAPPLICATION_PROJECT map in ma.projects)
                            {
                                map.materialapplicationid        = ma.materialapplicationid;
                                map.materialapplicationprojectid = System.Guid.NewGuid().ToString().ToUpper();
                                if (mapBLL.Insert(map))
                                {
                                    foreach (TBL_MATERIALAPPLICATION_DETAIL mad in map.madetail)
                                    {
                                        mad.materialapplicationdetailid  = System.Guid.NewGuid().ToString().ToUpper();
                                        mad.materialapplicationprojectid = map.materialapplicationprojectid;
                                        madBLL.Insert(mad);
                                    }
                                }
                                else
                                {
                                    json = "{IsSuccess:'false',Message:'保存失败!'}";
                                    DaoFactory.RollBackTransaction();
                                    break;
                                }
                            }


                            if (flowstate == "1")
                            {
                                WorkFlow.Model.FLOW_TASK task = new WorkFlow.Model.FLOW_TASK();
                                task.TASK_ID     = Guid.NewGuid().ToString().ToUpper();
                                task.DEFINE_CODE = "LCBM20161208100520";
                                task.TASK_CODE   = ma.processnumber;
                                task.TASK_TILTE  = "材料申请" + DateTime.Now.ToString("yyyyMMddHHmmss");
                                task.STATUS      = "0";
                                task.TASK_TYPE   = "8CF337E8-08C0-45E7-97C4-1C2E617D06CC";
                                task.ADD_EMP     = CFunctions.getUserId(context);
                                task.TASK_JSON   = JsonConvert.SerializeObject(ma);
                                bool s = createFlow(task);
                                s    = sendFlow(task.TASK_CODE, task.DEFINE_CODE, task.ADD_EMP);
                                json = "{IsSuccess:'true',Message:'提交成功!'}";
                            }

                            DaoFactory.CommitTransaction();
                        }
                        else
                        {
                            json = "{IsSuccess:'false',Message:'保存失败!'}";
                            DaoFactory.RollBackTransaction();
                        }
                    }
                    else
                    {
                        if (flowstate == "1")
                        {
                            WorkFlow.Model.FLOW_TASK task = new WorkFlow.Model.FLOW_TASK();
                            task.TASK_ID     = Guid.NewGuid().ToString().ToUpper();
                            task.DEFINE_CODE = "LCBM20161208100520";
                            task.TASK_CODE   = ma.processnumber;
                            task.TASK_TILTE  = "材料申请" + DateTime.Now.ToString("yyyyMMddHHmmss");
                            task.STATUS      = "0";
                            task.TASK_TYPE   = "8CF337E8-08C0-45E7-97C4-1C2E617D06CC";
                            task.ADD_EMP     = CFunctions.getUserId(context);
                            task.TASK_JSON   = JsonConvert.SerializeObject(ma);
                            bool s = createFlow(task);
                            s    = sendFlow(task.TASK_CODE, task.DEFINE_CODE, task.ADD_EMP);
                            json = "{IsSuccess:'true',Message:'提交成功!'}";
                        }
                        else
                        {
                            json = "{IsSuccess:'false',Message:'申请单号存在!'}";
                        }
                    }
                }
                else
                {
                    json = "{IsSuccess:'true',Message:'此单号已经提交!'}";
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
                json = "{IsSuccess:'false',Message:'保存失败!'}";
                DaoFactory.RollBackTransaction();
            }

            json = JsonConvert.SerializeObject(json);
            context.Response.ContentType = "application/json";
            //返回JSON结果
            context.Response.Write(json);
            context.Response.End();
        }