public void Audit(string id, JObject data)
        {
            var pUpdate = ParamUpdate.Instance()
                          .Update("MES_PurchaseOrderMain")
                          .Column("ApproveState", data["status"])
                          .Column("ApproveRemark", data["comment"])
                          .Column("ApprovePerson", FormsAuth.GetUserData().UserName)
                          .Column("ApproveDate", DateTime.Now)
                          .AndWhere("ID", id);

            var service      = new MES_PurchaseOrderMainService();
            var rowsAffected = service.Update(pUpdate);

            MmsHelper.ThrowHttpExceptionWhen(rowsAffected < 0, "单据审核失败[BillNo={0}],请重试或联系管理员!", id);
        }
        public dynamic GetPageData(string id)
        {
            var masterService = new MES_PurchaseOrderMainService();
            var pQuery        = ParamQuery.Instance().AndWhere("ID", id);
            var pQuery2       = ParamQuery.Instance().AndWhere("MainID", id).AndWhere("IsEnable", 1);
            var maindata      = masterService.GetModel(pQuery);
            var result        = new
            {
                //主表数据
                form       = masterService.GetModel(pQuery),
                scrollKeys = masterService.ScrollKeys("ID", id),

                //明细数据
                tab0 = new MES_PurchaseOrderDetailService().GetDynamicList(pQuery2)
            };

            return(result);
        }
        public dynamic Get(RequestWrapper query)
        {
            query.LoadSettingXmlString(@"
<settings defaultOrderBy='ID'>
    <select>*</select>
    <from>MES_PurchaseOrderMain</from>
    <where defaultForAll='true' defaultCp='equal' defaultIgnoreEmpty='true' >
        <field name='BillCode'		cp='equal'></field>   
        <field name='ProductPurchaseCode'		cp='equal'></field>   
        <field name='ContractCode'		cp='equal'></field>   
        <field name='BillState'		cp='equal'></field>   
    </where>
</settings>");
            var service = new MES_PurchaseOrderMainService();
            var pQuery  = query.ToParamQuery();
            var result  = service.GetDynamicListWithPaging(pQuery.AndWhere("IsEnable", 1));

            return(result);
        }
        public void Edit(dynamic data)
        {
            var id     = data.form["ID"].ToString();
            var pQuery = ParamQuery.Instance().Select("*").AndWhere("ID", id);
            var re     = new MES_PurchaseOrderMainService().GetModelList(pQuery);

            if (re.Count > 0 && re[0].BillState == 2)
            {
                MmsHelper.ThrowHttpExceptionWhen(true, "已审核数据不能修改!");
                return;
            }
            var ids = "(";

            foreach (JToken tab in data["tabs"].Children())
            {
                foreach (JProperty item in tab.Children())
                {
                    if (item.Name == "deleted")
                    {
                        foreach (var row in item.Value.Children())
                        {
                            ids += "'" + row["ID"] + "',";
                        }
                        item.Value = "[]";
                    }
                }
            }
            if (ids != "(")
            {
                ids  = ids.Remove(ids.Length - 1, 1);
                ids += ")";
                using (var db = Db.Context("Mms"))
                {
                    string sql1 = string.Format("update MES_PurchaseOrderDetail set IsEnable=0 where ID in {0} ", ids);
                    db.Sql(sql1).Execute();
                }
            }
            var formWrapper = RequestWrapper.Instance().LoadSettingXmlString(@"
<settings>
    <table>
        MES_PurchaseOrderMain
    </table>
    <where>
        <field name='ID' cp='equal'></field>
    </where>
</settings>
");

            var tabsWrapper = new List <RequestWrapper>();

            tabsWrapper.Add(RequestWrapper.Instance().LoadSettingXmlString(@"
<settings>
    <table>MES_PurchaseOrderDetail</table>
    <where>
        <field name='ID' cp='equal'></field>      
    </where>
</settings>"));
            if (data.form["BillCode"] == "系统生成")
            {
                string documentNo = MmsHelper.GetOrderNumber("MES_PurchaseOrderMain", "BillCode", "CGDD", "", "");
                data.form["BillCode"] = documentNo;
            }
            var service = new MES_PurchaseOrderMainService();
            var result  = service.EditPage(data, formWrapper, tabsWrapper);
        }