Пример #1
0
 //加密
 private void BtnEncrypt_Click(object sender, EventArgs e)
 {
     if (string.IsNullOrEmpty(txtSourceText.Text))
     {
         MessageBox.Show("没数据加毛密-_-!");
         return;
     }
     else
     {
         txtResultText.Text = AESEncryptHelper.Encrypt(txtSourceText.Text);
     }
 }
Пример #2
0
        public Resp_Binary_Member <AlarmDTO> Add_One(CaptureDTO model)
        {
            var alert   = false;
            var capture = model.GetPrototype <CaptureDTO, Capture>();

            if (capture.Pass == 1)  //without代表该车出场
            {
                capture.WithOut = 0;
            }
            if (capture.Pass == 0)
            {
                capture.WithOut = 1;
            }


            var result = false;
            var guid   = Guid.NewGuid().ToString();

            long layoutId = 0;

            using (var context = new SKContext())
            {
                using (var tran = new TransactionScope())
                {
                    var layout = context.Layouts.Where(d => d.CarNumber == model.CarNumber && d.IsValid == 1 && d.Channel == model.Channel).FirstOrDefault();
                    if (layout.IsNotNull())
                    {
                        if (layout.TriggerType == 2 || layout.TriggerType == model.Pass.ToInt()) //进出场控制
                        {
                            alert = true;
                            var lettercode = GetRandomNumberString(ConfigPara.LetterCount);

                            var alarm = new Alarm
                            {
                                CarNumber  = model.CarNumber,
                                IsDeal     = 0,
                                GUID       = guid,
                                AlarmTime  = DateTime.Now,
                                Channel    = model.Channel,
                                LetterCode = AESEncryptHelper.Encrypt(lettercode)
                            };

                            _messageRepository.SendMessage(capture.ToJson(), capture.Channel);
                            capture.Alarms.Add(alarm);

                            layoutId = layout.ID;
                            //if (layout.Degree > 0)
                            //    --layout.Degree;
                            //if (layout.Degree == 0)
                            //    layout.IsValid = 0;
                        }
                    }

                    var captureback = model.GetPrototype <CaptureDTO, CaptureBackup>();
                    //当车出场时,将该车的进场记录的是否出场改为已出场
                    if (model.Pass.ToInt() == 0)
                    {
                        var in_captures = context.Captures.Where(t => t.CarNumber == model.CarNumber && t.Pass == 1 && t.WithOut == 0);
                        foreach (var item in in_captures)
                        {
                            item.WithOut = 1;
                        }
                    }

                    var recordM = context.RecordManagers.Where(t => t.CarNumber == model.CarNumber).OrderByDescending(t => t.ID).FirstOrDefault();
                    if (recordM.IsNotNull())
                    {
                        capture.BeiAn     = recordM.Type;
                        captureback.BeiAn = recordM.Type;
                        if (model.Pass.ToInt() == 1) //进场修改备案最后一次进场时间
                        {
                            recordM.LastInTime = model.CreateTime.ToDateTime();
                        }
                        else if (model.Pass.ToInt() == 0) //出场修改备案最近一次出场时间
                        {
                            recordM.LastOutTime = model.CreateTime.ToDateTime();
                        }
                    }
                    else
                    {
                        capture.BeiAn     = 2;
                        captureback.BeiAn = 2;
                    }
                    context.Captures.Add(capture);

                    context.CaptureBackups.Add(captureback);

                    context.SaveChanges();
                    tran.Complete();
                    result = true;
                }
            }



            if (result)
            {
                if (alert)
                {
                    //    var req_dock = new Req_Warning
                    //    {
                    //        WARNINGDATE = DateTime.Now.ToString("yyyy-MM-dd hh: mm:ss"),
                    //        CARNO = model.CarNumber,
                    //        CARTYPE = model.CarType,
                    //        inout = model.Pass.Equals("1") ? "进" : "出",
                    //        bayonet = model.Channel,
                    //        Remark = model.Remark

                    //    };
                    //    Docking(req_dock); //报警通知第三方

                    var alam = _alarmRepository.GetByWhere(t => t.GUID == guid).FirstOrDefault();
                    var dto  = alam.ConvertoDto <Alarm, AlarmDTO>();
                    dto.LetterCode = alam.LetterCode;
                    return(new Resp_Binary_Member <AlarmDTO> {
                        message = "该车辆已中控报警!", flag = 2, LetterCode = dto.LetterCode, entity = dto, LayoutId = layoutId
                    });
                }
                return(new Resp_Binary_Member <AlarmDTO> {
                    message = "添加成功", flag = 1
                });
            }

            return(new Resp_Binary_Member <AlarmDTO> {
                message = "添加失败", flag = 0
            });
        }