Пример #1
0
        public static string UpdateFlowStatus(string Code, int oldStatus, int newStatus, string UpdateBy)
        {
            string str = string.Empty;

            try
            {
                AchieveDBEntities myDbContext = new AchieveDBEntities();
                tbFlow            main        = myDbContext.tbFlow.Where(p => p.Code == Code).ToList().FirstOrDefault();
                if (main == null)
                {
                    throw new Exception("未找到相关数据!");
                }
                if (main.status != oldStatus)
                {
                    throw new Exception("数据已经被其它人操作,请刷新!");
                }
                main.status     = newStatus;
                main.UpdateTime = DateTime.Now;
                main.UpdateBy   = UpdateBy;
                myDbContext.SaveChanges();
                str = ResponseHelper.ResponseMsg("1", "保存成功", "");
            }
            catch (Exception ex)
            {
                str = ResponseHelper.ResponseMsg("-1", ex.Message, "");
            }

            return(str);
        }
Пример #2
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);
        }
Пример #3
0
        public static string DeleteFlow(string[] FlowList)
        {
            string str = string.Empty;

            try
            {
                AchieveDBEntities myDbContext = new AchieveDBEntities();
                int i = 0;
                foreach (string temp in FlowList)
                {
                    tbFlow deltbFlow = myDbContext.tbFlow.Where(p => p.Code == temp).FirstOrDefault();
                    if (deltbFlow == null)
                    {
                        continue;
                    }
                    if (deltbFlow.status != 0)
                    {
                        continue;
                    }
                    myDbContext.tbFlow.Remove(deltbFlow);
                    List <tbFlowStep> delFlowStep = myDbContext.tbFlowStep.Where(p => p.FlowCode == temp).ToList();
                    if (delFlowStep != null && delFlowStep.Count > 0)
                    {
                        foreach (var st in delFlowStep)
                        {
                            myDbContext.tbFlowStep.Remove(st);
                        }
                    }
                    List <tbFlowStepUser> delFlowStepUser = myDbContext.tbFlowStepUser.Where(p => p.FlowCode == temp).ToList();
                    if (delFlowStepUser != null && delFlowStepUser.Count > 0)
                    {
                        foreach (var st in delFlowStepUser)
                        {
                            myDbContext.tbFlowStepUser.Remove(st);
                        }
                    }
                }



                myDbContext.SaveChanges();
                string msg = string.Format("提交{0}条数据,成功删除{1}条", FlowList.Length, i);
                str = ResponseHelper.ResponseMsg("1", msg, "");
            }
            catch (Exception ex)
            {
                str = ResponseHelper.ResponseMsg("-1", ex.Message, "");
            }

            return(str);
        }
Пример #4
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);
        }