Пример #1
0
        public static string AddFlow(string Flowstr)
        {
            string str = string.Empty;

            try
            {
                DateTime          now         = DateTime.Now;
                AchieveDBEntities myDbContext = new AchieveDBEntities();
                FlowModel         tb          = JsonConvert.DeserializeObject <FlowModel>(Flowstr);
                tbFlow            Flow        = new tbFlow();
                ObjectHelper.CopyValue(tb.Flow, Flow);
                List <tbFlowStep>             FlowStep     = tb.FlowStep;
                List <v_FlowStepUserViewInfo> FlowStepUser = tb.FlowStepUser;
                if (tb == null)
                {
                    throw new Exception("流程数据异常!");
                }
                if (FlowStep == null || FlowStep.Count <= 0)
                {
                    throw new Exception("流程步骤数据异常!");
                }
                //if (FlowStepUser == null || FlowStepUser.Count <= 0)
                //{
                //    throw new Exception("流程步骤数据异常!");
                //}
                //string Code = Guid.NewGuid().ToString();
                string No = BillNoBill.GetBillNo(myDbContext, "LC");

                Flow.CreateTime = now;
                Flow.UpdateTime = now;
                Flow.status     = 0;
                //Flow.Code = Code;
                Flow.No = No;
                myDbContext.tbFlow.Add(Flow);
                foreach (var st in FlowStep)
                {
                    st.CreateTime = now;
                    st.UpdateTime = now;
                    myDbContext.tbFlowStep.Add(st);
                }
                foreach (var st in FlowStepUser)
                {
                    st.CreateTime = now;
                    st.UpdateTime = now;
                    tbFlowStepUser temp = new tbFlowStepUser();
                    string[]       keys = { "Id" };
                    ObjectHelper.CopyValue(st, temp);
                    myDbContext.tbFlowStepUser.Add(temp);
                }
                myDbContext.SaveChanges();
                str = ResponseHelper.ResponseMsg("1", "保存成功", Flow.Code);
            }
            catch (Exception ex)
            {
                str = ResponseHelper.ResponseMsg("-1", ex.Message, "");
            }

            return(str);
        }
Пример #2
0
        public static string UpdateFlow(string Flowstr)
        {
            string str = string.Empty;

            try
            {
                DateTime  now  = DateTime.Now;
                FlowModel tb   = JsonConvert.DeserializeObject <FlowModel>(Flowstr);
                tbFlow    Flow = new tbFlow();
                ObjectHelper.CopyValue(tb.Flow, Flow);
                List <tbFlowStep>             FlowStep     = tb.FlowStep;
                List <v_FlowStepUserViewInfo> FlowStepUser = tb.FlowStepUser;
                if (tb == null)
                {
                    throw new Exception("流程数据异常!");
                }
                if (FlowStep == null || FlowStep.Count <= 0)
                {
                    throw new Exception("流程步骤数据异常!");
                }
                if (FlowStepUser == null || FlowStepUser.Count <= 0)
                {
                    throw new Exception("流程步骤数据异常!");
                }
                AchieveDBEntities myDbContext = new AchieveDBEntities();
                tbFlow            newFlow     = myDbContext.tbFlow.Where(p => p.Code == Flow.Code).ToList().FirstOrDefault();
                string[]          keys        = { "Code" };
                ObjectHelper.CopyValueNotKey(Flow, newFlow, keys);
                newFlow.UpdateTime = now;
                if (FlowStep != null && FlowStep.Count > 0)
                {
                    string [] FlowStepCode = new string[FlowStep.Count];
                    int       count        = 0;
                    foreach (var st in FlowStep)
                    {
                        FlowStepCode[count] = st.Code;
                        count++;
                        tbFlowStep temp = myDbContext.tbFlowStep.Where(p => p.Code == st.Code).ToList().FirstOrDefault();
                        if (temp != null)
                        {
                            ObjectHelper.CopyValueNotKey(st, temp, keys);
                            temp.UpdateTime = now;
                        }
                        else
                        {
                            st.FlowCode   = Flow.Code;
                            st.UpdateTime = now;
                            myDbContext.tbFlowStep.Add(st);
                        }
                    }
                    List <tbFlowStep> tempList = myDbContext.tbFlowStep.Where(p => !(FlowStepCode).Contains(p.Code) && p.FlowCode == Flow.Code).ToList();
                    if (tempList != null && tempList.Count > 0)
                    {
                        foreach (var st in tempList)
                        {
                            myDbContext.tbFlowStep.Remove(st);
                        }
                    }
                }

                if (FlowStepUser != null && FlowStepUser.Count > 0)
                {
                    string[] FlowStepUserCode = new string[FlowStepUser.Count];
                    int      count            = 0;
                    foreach (var st in FlowStepUser)
                    {
                        FlowStepUserCode[count] = st.Code;
                        count++;
                        tbFlowStepUser temp = myDbContext.tbFlowStepUser.Where(p => p.Code == st.Code).ToList().FirstOrDefault();
                        if (temp != null)
                        {
                            ObjectHelper.CopyValue(st, temp);
                            temp.UpdateTime = now;
                        }
                        else
                        {
                            st.FlowCode   = Flow.Code;
                            st.UpdateTime = now;
                            tbFlowStepUser newtemp = new tbFlowStepUser();
                            ObjectHelper.CopyValue(st, newtemp);
                            myDbContext.tbFlowStepUser.Add(newtemp);
                        }
                    }
                    List <tbFlowStepUser> tempList = myDbContext.tbFlowStepUser.Where(p => !(FlowStepUserCode).Contains(p.Code) && p.FlowCode == Flow.Code).ToList();
                    if (tempList != null && tempList.Count > 0)
                    {
                        foreach (var st in tempList)
                        {
                            myDbContext.tbFlowStepUser.Remove(st);
                        }
                    }
                }
                myDbContext.SaveChanges();
                str = ResponseHelper.ResponseMsg("1", "保存成功", Flow.Code);
            }
            catch (Exception ex)
            {
                str = ResponseHelper.ResponseMsg("-1", ex.Message, "");
            }

            return(str);
        }