public Object AddFeedback([FromBody] FeedbackData PostData)
        {
            ResultData result = new ResultData();

            using (SqlConnection sqlconnection = new SqlConnection(conString))
            {
                bool flag = true;
                FeedbackBaseService service  = new FeedbackBaseService(sqlconnection);
                List <FeedbackBase> BaseList = service.GetOrderInfoByWhere(" where OrderNo='" + PostData.OrderNo + "'");
                if (sqlconnection.State == ConnectionState.Closed)
                {
                    sqlconnection.Open();
                }
                SqlTransaction transaction = sqlconnection.BeginTransaction();
                try
                {
                    FeedbackBase feedbackbase = new FeedbackBase();
                    feedbackbase.OrderNo     = PostData.OrderNo;
                    feedbackbase.Model       = PostData.Model;
                    feedbackbase.FeedbackMan = PostData.FeedbackMan;
                    //feedbackbase.FeedbackTime = DateTime.Now;
                    feedbackbase.Qty           = PostData.Qty;
                    feedbackbase.WorkProcedure = PostData.WorkProcedure;
                    feedbackbase.BatchNo       = PostData.BatchNo;
                    feedbackbase.EquipmentName = PostData.EquipmentName;
                    feedbackbase.EquipmentNo   = PostData.EquipmentNo;
                    feedbackbase.ProductClass  = PostData.ProductClass;
                    if (PostData.FeedbackTime == "")
                    {
                        feedbackbase.FeedbackTime = DateTime.Now;
                    }
                    else
                    {
                        feedbackbase.FeedbackTime = Convert.ToDateTime(PostData.FeedbackTime);
                    }

                    feedbackbase.Status       = PostData.Status;
                    feedbackbase.ProblemLevel = PostData.ProblemLevel;
                    //FeedbackBaseService service = new FeedbackBaseService(sqlconnection);
                    //List<FeedbackBase> BaseList= service.GetOrderInfoByWhere(" where OrderNo='" + PostData.OrderNo + "'",transaction);
                    if (BaseList != null && BaseList.Count > 0)
                    {
                        flag = service.Delete(PostData.OrderNo, transaction);
                    }
                    if (!Directory.Exists(SavePath))
                    {
                        Directory.CreateDirectory(SavePath);
                    }
                    if (service.AddFeedbackBase(feedbackbase, transaction))
                    {
                        FeedbackExProblemService PService = new FeedbackExProblemService(sqlconnection);
                        FeedbackExReasonService  RService = new FeedbackExReasonService(sqlconnection);
                        BllProductCard           BllCard  = new BllProductCard(sqlconnection);
                        FeedbackExProblem        Problem  = new FeedbackExProblem();
                        FeedbackExReason         Reason   = new FeedbackExReason();
                        foreach (var list in PostData.ReasonData)
                        {
                            if (list.ReasonType != "" && list.ReasonDetails != "")
                            {
                                Reason.ReasonType    = list.ReasonType;
                                Reason.ReasonDetails = list.ReasonDetails;
                                Reason.OrderNo       = PostData.OrderNo;
                                if (!RService.AddReason(Reason, transaction))
                                {
                                    flag = false;
                                    break;
                                }
                            }
                        }
                        foreach (var list in PostData.ProblemData)
                        {
                            if (list.CodeString != "" || list.PicturePath != "" || list.ProblemDetails != "")
                            {
                                Problem.CodeString = list.CodeString;
                                Problem.OrderNo    = PostData.OrderNo;
                                string PicturePath = list.PicturePath;
                                string filePath    = "";
                                if (PicturePath != "" && PicturePath != null)
                                {
                                    var chrPath = PicturePath.Split('|');
                                    for (int iPath = 0; iPath < chrPath.Length; iPath++)
                                    {
                                        if (chrPath[iPath].Contains("base64"))
                                        {
                                            SaveImage save     = new SaveImage();
                                            string    fileName = DateTime.Now.Ticks.ToString();
                                            save.SaveInageForBase(chrPath[iPath].Split(',')[1], SavePath, fileName);
                                            filePath = filePath + "ProblemPicture/" + fileName + ".png" + ",";
                                        }
                                        else if (chrPath[iPath] != "")
                                        {
                                            string tempPath = "";
                                            for (var i = 0; i < chrPath[iPath].Split('/').Length; i++)
                                            {
                                                if (i >= 3)
                                                {
                                                    tempPath = tempPath + chrPath[iPath].Split('/')[i] + "/";
                                                }
                                            }
                                            if (tempPath != "")
                                            {
                                                tempPath = tempPath.Substring(0, tempPath.LastIndexOf("/"));
                                                filePath = filePath + tempPath + ",";
                                            }
                                        }
                                    }
                                }
                                if (filePath != "")
                                {
                                    filePath = filePath.Substring(0, filePath.LastIndexOf(","));
                                }

                                Problem.PicturePath    = filePath;
                                Problem.ProblemDetails = list.ProblemDetails;
                                if (!PService.AddProblem(Problem, transaction))
                                {
                                    flag = false;
                                    break;
                                }
                            }
                        }
                        foreach (var list in PostData.CardList)
                        {
                            list.FKOrderNo = PostData.OrderNo;
                            if (!BllCard.InsertCard(list, transaction))
                            {
                                flag = false;
                                break;
                            }
                        }
                        if (PostData.IfQC)
                        {
                            FeedbackExHandleService BllHandler = new FeedbackExHandleService(sqlconnection);
                            FeedbackExHandle        Handler    = new FeedbackExHandle();
                            Handler.HandleMan        = PostData.HandleMan;
                            Handler.HandleNote       = PostData.HandleNote;
                            Handler.HandleSuggestion = PostData.HandleSuggestion;
                            Handler.HandleTime       = DateTime.Now;
                            Handler.QualityClass     = PostData.QualityClass;
                            Handler.OrderNo          = PostData.OrderNo;
                            if (!BllHandler.AddHandle(Handler, transaction))
                            {
                                flag = false;
                            }
                        }
                        if (flag)
                        {
                            transaction.Commit();
                            result.ErrMsg = "";
                            result.Result = true;
                            return(result);
                        }
                        else
                        {
                            transaction.Rollback();
                            result.ErrMsg = "反馈失败";
                            result.Result = false;
                            return(result);
                        }
                    }
                    else
                    {
                        transaction.Rollback();
                        result.ErrMsg = "反馈失败";
                        result.Result = false;
                        return(result);
                    }
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    result.Result = false;
                    if (ex.Message.Contains("重复键"))
                    {
                        result.ErrMsg = "已存在相同的单号,编码不能重复添加";
                    }
                    else
                    {
                        result.ErrMsg = ex.Message;
                    }
                    return(result);
                }
            }
        }
Example #2
0
        public Object InsertOrder(OrderInfo PostData)
        {
            ResultData    result = new ResultData();//返回数据类型
            SqlConnection con    = new SqlConnection(conString);

            if (con.State == ConnectionState.Closed)
            {
                con.Open();
            }
            //验证是否已存在该单号的单据,存在删除,再添加,不存在直接添加
            bool   Delete  = false;//false:不存在,true:存在
            string OrderNo = PostData.OrderNo != null? PostData.OrderNo:"";

            OrderNo = OrderNo.Trim();
            FeedbackBaseService BllBase = new FeedbackBaseService(con);
            Guid NewID = BllBase.GetNewID();

            FeedbackBase Base = BllBase.GetOrderInfoByWhere(" where OrderNo='" + OrderNo + "'").FirstOrDefault();

            if (Base != null)
            {
                Delete = true;
            }
            SqlTransaction tran = con.BeginTransaction();

            try
            {
                if (Delete)
                {
                    if (!BllBase.Delete(OrderNo, tran))//删除旧单据
                    {
                        result.ErrMsg = "提交失败,原因:删除原始信息异常";
                        result.Result = false;
                        return(result);
                    }
                }
                //定义保存的数据

                string       EmployeeID = PostData.EmployeeID;
                FeedbackBase Domain     = new FeedbackBase();
                Domain.ID            = NewID;
                Domain.OrderNo       = OrderNo;//单号,控制表以KZ开头,反馈单已FK开头
                Domain.BatchNo       = PostData.BatchNo;
                Domain.Model         = PostData.Model;
                Domain.Qty           = PostData.Qty;
                Domain.Status        = "0";//默认T1顺序审批人
                Domain.WorkProcedure = PostData.WorkProcedure;
                Domain.EquipmentName = PostData.EquipmentName;
                Domain.EquipmentNo   = PostData.EquipmentNo;
                Domain.FeedbackMan   = PostData.FeedbackMan;
                Domain.ProblemLevel  = PostData.ProblemLevel;//审批流程代号
                Domain.ImageList     = PostData.ImageList;
                Domain.ImageHtml     = PostData.ImageHtml;

                if (PostData.FeedbackTime == null || PostData.FeedbackTime == "")
                {
                    PostData.FeedbackTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
                }
                Domain.FeedbackTime = Convert.ToDateTime(PostData.FeedbackTime);
                Domain.ProductClass = PostData.ProductClass;
                int OrderType  = 0;
                int FlowTempId = 1;
                if (OrderNo.StartsWith("FK"))
                {
                    FlowTempId = 0;
                    OrderType  = 0;
                }
                else
                {
                    FlowTempId = 1;
                    OrderType  = 1;
                }
                Domain.OrderType  = OrderType;
                Domain.Measure    = PostData.Measure != null ? PostData.Measure : "";
                Domain.Report     = PostData.Report != null ? PostData.Report : "";
                Domain.EmployeeID = EmployeeID;
                List <ProductCard.CardInfo> CardList    = PostData.CardList;
                List <OrderReason>          ReasonData  = PostData.ReasonData;
                List <OrderProblem>         ProblemData = PostData.ProblemData;

                #region ======Post请求:录入审批系统=====
                //GeneralMethod Method = new GeneralMethod();
                string title = "";
                if (FlowTempId == 1)
                {
                    title = "质量控制流程(" + OrderNo + ")";
                }
                else
                {
                    title = "质量反馈流程(" + OrderNo + ")";
                }

                string urls = new ConfigurationBuilder()
                              .SetBasePath(Directory.GetCurrentDirectory())
                              .AddJsonFile("host.json", optional: true).Build().GetSection("ApprovalPostAddress").Value;
                using (HttpClient Client = new HttpClient())
                {
                    var values = new List <KeyValuePair <string, string> >();
                    values.Add(new KeyValuePair <string, string>("Title", title));
                    values.Add(new KeyValuePair <string, string>("InstanceID", NewID.ToString()));
                    values.Add(new KeyValuePair <string, string>("FlowID", "D3BBCCBF-8968-4833-8A0F-CE5B19B718E2"));
                    values.Add(new KeyValuePair <string, string>("Account", EmployeeID));
                    values.Add(new KeyValuePair <string, string>("WorkProcedure", PostData.WorkProcedure));
                    var content  = new FormUrlEncodedContent(values);
                    var response = Client.PostAsync(urls, content);
                    response.Wait();

                    HttpResponseMessage resp = response.Result;

                    var res2 = resp.Content.ReadAsStringAsync();
                    res2.Wait();
                    string  Message = res2.Result;
                    JObject Robj    = JObject.Parse(Message);
                    if (Robj["result"].ToString() == "1")
                    {
                        Domain.TechnologistMembers = Robj["msg"].ToString();
                    }
                    else
                    {
                        Exception ex = new Exception(Robj["msg"] + "(远端接入失败)");
                        throw ex;
                    }
                }
                #endregion



                if (BllBase.Insert(Domain, tran))
                {
                    FeedbackExProblemService BllProblem = new FeedbackExProblemService(con);
                    FeedbackExReasonService  BllReason  = new FeedbackExReasonService(con);
                    BllProductCard           BllCard    = new BllProductCard(con);
                    for (int i = 0; i < ProblemData.Count; i++)
                    {
                        FeedbackExProblem Problem = new FeedbackExProblem();
                        Problem.OrderNo        = OrderNo;
                        Problem.CodeString     = ProblemData[i].codeString;
                        Problem.TopClass       = ProblemData[i].topClass;
                        Problem.RoomName       = ProblemData[i].roomName;
                        Problem.Problem        = ProblemData[i].problem;
                        Problem.TypeName       = ProblemData[i].typeName;
                        Problem.Present        = ProblemData[i].present;
                        Problem.ProblemDetails = ProblemData[i].problemDetails;
                        Problem.Suggestion     = ProblemData[i].suggestion;
                        Problem.QualityClass   = ProblemData[i].qualityClass;
                        Problem.ProblemLevel   = ProblemData[i].problemLevel;
                        if (ProblemData[i].suggestion != "" && ProblemData[i].suggestion != null && ProblemData[i].suggestion.Contains("suggestion"))
                        {
                            JArray JList = JArray.Parse(ProblemData[i].suggestion);
                            foreach (var node in JList)
                            {
                                string suggestion = node["suggestion"].ToString();
                                if (!BllBase.InsertOrderSuggestion(tran, suggestion, OrderNo, ProblemData[i].codeString))
                                {
                                    Exception ex = new Exception("提交失败,原因:保存质量问题编码处理意见失败");
                                    throw ex;
                                }
                            }
                        }

                        if (!BllProblem.AddProblem(Problem, tran))
                        {
                            Exception ex = new Exception("提交失败,原因:质量问题提交异常");
                            throw ex;
                        }
                    }
                    for (int i = 0; i < ReasonData.Count; i++)
                    {
                        FeedbackExReason Reason = new FeedbackExReason();
                        Reason.OrderNo       = OrderNo;
                        Reason.ReasonDetails = ReasonData[i].reasonDetails;
                        Reason.ReasonType    = ReasonData[i].reasonType;
                        if (!BllReason.AddReason(Reason, tran))
                        {
                            Exception ex = new Exception("提交失败,原因:原因分析提交异常");
                            throw ex;
                        }
                    }
                    foreach (var node in CardList)
                    {
                        node.FKOrderNo = OrderNo;
                        if (!BllCard.InsertCard(node, tran))
                        {
                            Exception ex = new Exception("提交失败,原因:客户信息提交异常");
                            throw ex;
                        }
                    }

                    tran.Commit();
                    result.Result = true;
                    result.ErrMsg = "提交成功";
                }
                else
                {
                    result.Result = false;
                    result.ErrMsg = "提交失败,原因:基础信息提交异常";
                    BllBase.DeleteWorkFlowTask(NewID.ToString(), tran);
                    tran.Commit();
                }
                return(result);
            }
            catch (Exception ex)
            {
                tran.Rollback();
                tran.Dispose();
                try
                {
                    BllBase.DeleteWorkFlowTask(NewID.ToString());
                }
                catch (Exception ex2)
                {
                }
                result.Result = false;
                result.ErrMsg = ex.Message;
                return(result);
            }
            finally
            {
                con.Close();
            }
        }