Exemplo n.º 1
0
        public AlarmRuleSaveResponse Execute(AlarmRuleSaveRequest request)
        {
            AlarmRuleSaveResponse ruleSaveResponse = new AlarmRuleSaveResponse();

            if (string.IsNullOrEmpty(request.AlarmRuleDID))
            {
                AlarmRuleInfo alarmRuleInfo = new AlarmRuleInfo();
                FacilityInfo  facility      = ServiceHelper.LoadService <IProductionService>().GetFacility(request.CraftDID);
                alarmRuleInfo.RuleDID      = ServiceHelper.LoadService <IAlarmService>().GetNextAlarmRuleDID(facility.Process.Craft.CraftNO);
                alarmRuleInfo.FacilityDID  = facility.FacilityDID;
                alarmRuleInfo.UnitDID      = facility.ProcessDID;
                alarmRuleInfo.CraftDID     = facility.Process.CraftDID;
                alarmRuleInfo.UnitDID      = request.UnitDID;
                alarmRuleInfo.AlarmContent = request.AlarmContent;
                alarmRuleInfo.AlarmReason  = request.AlarmReason;
                alarmRuleInfo.Solution     = new SolutionInfo()
                {
                    Content = request.SolutionText
                };
                alarmRuleInfo.AlarmTypeDID = request.AlarmTypeDID;
                string str1 = "Upload/SolutionImages/";
                string str2 = alarmRuleInfo.RuleDID + ".jpg";
                if (!Directory.Exists(this.Server.MapPath("~/" + str1)))
                {
                    Directory.CreateDirectory(this.Server.MapPath("~/" + str1));
                }
                ImageHelper.SaveImage(ImageHelper.BytesToImage(request.GetFileParameters()["SolutionImage"].GetContent()), this.Server.MapPath("~/" + str1 + str2));
                string str3 = "Upload/AlarmLocationImages/";
                string str4 = alarmRuleInfo.RuleDID + ".jpg";
                if (!Directory.Exists(this.Server.MapPath("~/" + str3)))
                {
                    Directory.CreateDirectory(this.Server.MapPath("~/" + str3));
                }
                ImageHelper.SaveImage(ImageHelper.BytesToImage(request.GetFileParameters()["AlarmLocationImage"].GetContent()), this.Server.MapPath("~/" + str3 + str4));
                alarmRuleInfo.AlarmLocationImage = new AlarmLocationImageInfo()
                {
                    Path = str3 + str4
                };
                alarmRuleInfo.SolutionImage = new SolutionImageInfo()
                {
                    Path = str1 + str2
                };
                ServiceHelper.LoadService <IAlarmService>().AddAlarmRule(alarmRuleInfo);
                ServiceHelper.LoadService <IAlarmService>().SaveAlarmRuleFields(alarmRuleInfo.RuleDID, request.Fields);
                ruleSaveResponse.AlarmRuleDID = alarmRuleInfo.RuleDID;
            }
            return(ruleSaveResponse);
        }
Exemplo n.º 2
0
        private void btnSubmit_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(this.model.AlarmContent))
            {
                MessageBox.Show("报警内容不能为空", "提示");
            }
            else if (string.IsNullOrEmpty(this.model.AlarmReason))
            {
                MessageBox.Show("异常原因不能为空", "提示");
            }
            else if (string.IsNullOrEmpty(this.model.SolutionText))
            {
                MessageBox.Show("解决方法不能为空", "提示");
            }
            else if (this.model.CraftDID == 0)
            {
                MessageBox.Show("请选择工艺", "提示");
            }
            else if (this.model.AlarmTypeDID == 0)
            {
                MessageBox.Show("请选择报警类型", "提示");
            }
            else if (string.IsNullOrEmpty(this.alarmLocationImagePath))
            {
                MessageBox.Show("请选择报警图片", "提示");
            }
            else if (string.IsNullOrEmpty(this.solutionImagePath))
            {
                MessageBox.Show("请选择报警处理图片", "提示");
            }
            else
            {
                AlarmRuleSaveRequest alarmRuleSaveRequest = new AlarmRuleSaveRequest()
                {
                    AlarmContent = this.model.AlarmContent,
                    AlarmReason  = this.model.AlarmReason,
                    SolutionText = this.model.SolutionText,
                    AlarmRuleDID = this.model.RuleDID,
                    CraftDID     = this.model.CraftDID,
                    UnitDID      = this.model.UnitDID,
                    AlarmTypeDID = this.model.AlarmTypeDID
                };

                Dictionary <string, string> dictionary = new Dictionary <string, string>();
                foreach (KeyValuePair <string, TextBox> dicField in this.dicFields)
                {
                    dictionary.Add(dicField.Key, dicField.Value.Text);
                }

                alarmRuleSaveRequest.Fields = dictionary;
                alarmRuleSaveRequest.GetFileParameters().Add("SolutionImage", new FileItem(this.solutionImagePath));
                alarmRuleSaveRequest.GetFileParameters().Add("AlarmLocationImage", new FileItem(this.alarmLocationImagePath));

                AlarmRuleSaveResponse ruleSaveResponse = LocalApi.Execute(alarmRuleSaveRequest);
                if (ruleSaveResponse.IsError)
                {
                    MessageBox.Show(ruleSaveResponse.ErrMsg, "提示");
                    this.btnSubmit.Visibility = Visibility.Collapsed;
                }
                else
                {
                    MessageBox.Show("提交成功,报警编号:" + ruleSaveResponse.AlarmRuleDID, "提示");
                    this.Reset();
                }
            }
        }