Esempio n. 1
0
        /// <summary>
        /// 发指令后台进程
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void backgroundWorker2_DoWork(object sender, DoWorkEventArgs e)
        {
            //调用控制柜子公共类,返回值标识是否正常打开枪柜门
            bool control_status = Utils.ControlGunark.control(task_info, ListToByte.List2Byte(gun_number), ListToByte.List2Byte(magazine_number));

            //判断是否正常打开柜门,如果未正常打开,重新执行该任务
            if (!control_status)
            {
                MessageBox.Show(this, "超时未开门,请重新做任务", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information, MessageBoxDefaultButton.Button2);
                this.button1.Enabled = true;
                this.button2.Enabled = true;
            }
            else
            {
                this.Close();
                //上传任务信息为“执行中”(调用webService接口)
                //webService.setDoingTask(task_info.TASK_ID, DateTime.Now,true,GetUserByFingerId.getUser(PubFlag.verifyUserId_1).USER_POLICENUMB, GetUserByFingerId.getUser(PubFlag.verifyUserId_2).USER_POLICENUMB);
                //检测对比取枪弹状态,返回值为true表示无异常枪位
                _isUsual = Utils.CheckGun.Check(gun_number);
                //如果没有异常枪位
                if (_isUsual)
                {
                    //更改数据库任务,枪支,枪位,子弹信息,并插入操作日志
                    switch (task_info.TASK_BIGTYPE)
                    {
                    //枪弹入柜
                    case 2:
                        Utils.AddLog.add(1, "枪弹入柜", list_gun.Count.ToString(), list_bullet.Count.ToString());
                        //更新本地数据库任务状态,建立执行中任务
                        UpdateTaskInfo.update(task_info, "6", "1", "3", "还弹", gun_info_id, gun_pos_id, magazine_id, list_bullet);
                        //调用WebService接口,更改枪位状态
                        for (int i = 0; i < gun_number.Count; i++)
                        {
                            webService.setGunInStore(gun_info_id[i]);
                            webService.setGunOnPosition(task_info.UNIT_ID, task_info.GUNARK_ID, gun_pos_id[i]);
                        }
                        //调用webservice接口,更改子弹库存量
                        for (int i = 0; i < magazine_id.Count; i++)
                        {
                            webService.setMagazineStock(magazine_id[i], (int)magazine_info_bll.GetModel(magazine_id[i]).STOCK_QTY);
                        }
                        //调用WebService接口,更改任务状态为已完成
                        webService.setFinishTask(task_info.TASK_ID, DateTime.Now, true, PubFlag.policeNum, PubFlag.dutyLeaderNum);
                        break;

                    //申请枪弹
                    case 3:
                        if (task_info.TASK_STATUS == "3")
                        {
                            Utils.AddLog.add(1, "领取枪弹", list_gun.Count.ToString(), list_bullet.Count.ToString());
                            //更新本地数据库任务状态,建立执行中任务
                            UpdateTaskInfo.update(task_info, "5", "3", "2", "取弹", gun_info_id, gun_pos_id, magazine_id, list_bullet);
                            //调用WebService接口,更改枪位状态
                            for (int i = 0; i < gun_number.Count; i++)
                            {
                                webService.setgunInUse(gun_info_id[i]);
                                webService.setGunNotOnPosition(task_info.UNIT_ID, task_info.GUNARK_ID, gun_pos_id[i]);
                            }
                            //调用webservice接口,更改子弹库存量
                            for (int i = 0; i < magazine_id.Count; i++)
                            {
                                webService.setMagazineStock(magazine_id[i], (int)magazine_info_bll.GetModel(magazine_id[i]).STOCK_QTY);
                            }
                            //调用WebService接口,更改任务状态为执行中
                            webService.setDoingTask(task_info.task_ID, DateTime.Now, true, PubFlag.policeNum, PubFlag.dutyLeaderNum);
                        }
                        else if (task_info.TASK_STATUS == "5")
                        {
                            Utils.AddLog.add(1, "归还枪弹", list_gun.Count.ToString(), list_bullet.Count.ToString());
                            //更新本地数据库任务状态,建立执行中任务
                            UpdateTaskInfo.update(task_info, "6", "1", "3", "还弹", gun_info_id, gun_pos_id, magazine_id, list_bullet);
                            //调用WebService接口,更改枪位状态
                            for (int i = 0; i < gun_number.Count; i++)
                            {
                                webService.setGunInStore(gun_info_id[i]);
                                webService.setGunOnPosition(task_info.UNIT_ID, task_info.GUNARK_ID, gun_pos_id[i]);
                            }
                            //调用webservice接口,更改子弹库存量
                            for (int i = 0; i < magazine_id.Count; i++)
                            {
                                webService.setMagazineStock(magazine_id[i], (int)magazine_info_bll.GetModel(magazine_id[i]).STOCK_QTY);
                            }
                            //调用WebService接口,更改任务状态为已完成
                            webService.setFinishTask(task_info.TASK_ID, DateTime.Now, true, PubFlag.policeNum, PubFlag.dutyLeaderNum);
                        }
                        else if (task_info.TASK_STATUS == "7")
                        {
                            Utils.AddLog.add(1, "超期归还", list_gun.Count.ToString(), list_bullet.Count.ToString());
                            //更新本地数据库任务状态,建立执行中任务
                            UpdateTaskInfo.update(task_info, "6", "1", "3", "还弹", gun_info_id, gun_pos_id, magazine_id, list_bullet);
                            //调用WebService接口,更改枪位状态
                            for (int i = 0; i < gun_number.Count; i++)
                            {
                                webService.setGunInStore(gun_info_id[i]);
                                webService.setGunOnPosition(task_info.UNIT_ID, task_info.GUNARK_ID, gun_pos_id[i]);
                            }
                            //调用webservice接口,更改子弹库存量
                            for (int i = 0; i < magazine_id.Count; i++)
                            {
                                webService.setMagazineStock(magazine_id[i], (int)magazine_info_bll.GetModel(magazine_id[i]).STOCK_QTY);
                            }
                            //调用WebService接口,更改任务状态为已完成
                            webService.setFinishTask(task_info.TASK_ID, DateTime.Now, true, PubFlag.policeNum, PubFlag.dutyLeaderNum);
                        }
                        break;

                    //枪支封存
                    case 4:
                        Utils.AddLog.add(1, "枪支封存", list_gun.Count.ToString(), list_bullet.Count.ToString());
                        //更新本地数据库任务状态,建立执行中任务
                        UpdateTaskInfo.update(task_info, "6", "8", "5", "", gun_info_id, gun_pos_id, magazine_id, list_bullet);
                        //调用WebService接口,更改枪位状态
                        for (int i = 0; i < gun_number.Count; i++)
                        {
                            webService.setGunBeSeal(gun_info_id[i]);
                            webService.setGunPositionSeal(task_info.UNIT_ID, task_info.GUNARK_ID, gun_pos_id[i]);
                        }
                        //调用WebService接口,更改任务状态为已完成
                        webService.setFinishTask(task_info.TASK_ID, DateTime.Now, true, PubFlag.policeNum, PubFlag.dutyLeaderNum);
                        break;

                    //枪支报废
                    case 5:
                        Utils.AddLog.add(1, "枪支报废", list_gun.Count.ToString(), list_bullet.Count.ToString());
                        //更新本地数据库任务状态,建立执行中任务
                        UpdateTaskInfo.update(task_info, "6", "5", "0", "取弹", gun_info_id, gun_pos_id, magazine_id, list_bullet);
                        //调用WebService接口,更改枪位状态
                        for (int i = 0; i < gun_number.Count; i++)
                        {
                            webService.setGunBeScrap(gun_info_id[i]);
                            //webService.setGunPosNotOnGunark(task_info.UNIT_ID, task_info.GUNARK_ID, gun_pos_id[i]);
                            webService.setGunPosNotOnGunark(task_info.UNIT_ID, task_info.GUNARK_ID, gun_pos_id[i]);
                        }
                        //调用WebService接口,更改任务状态为已完成
                        webService.setFinishTask(task_info.TASK_ID, DateTime.Now, true, PubFlag.policeNum, PubFlag.dutyLeaderNum);
                        break;

                    //枪支保养
                    case 6:
                        if (task_info.TASK_STATUS == "3")
                        {
                            Utils.AddLog.add(1, "枪支保养", list_gun.Count.ToString(), list_bullet.Count.ToString());
                            //更新本地数据库任务状态,建立执行中任务
                            UpdateTaskInfo.update(task_info, "5", "3", "2", "", gun_info_id, gun_pos_id, magazine_id, list_bullet);
                            //调用WebService接口,更改枪位状态
                            for (int i = 0; i < gun_number.Count; i++)
                            {
                                webService.setgunInUse(gun_info_id[i]);
                                webService.setGunNotOnPosition(task_info.UNIT_ID, task_info.GUNARK_ID, gun_pos_id[i]);
                            }
                            //调用WebService接口,更改任务状态为执行中
                            webService.setDoingTask(task_info.task_ID, DateTime.Now, true, PubFlag.policeNum, PubFlag.dutyLeaderNum);
                        }
                        else if (task_info.TASK_STATUS == "5")
                        {
                            Utils.AddLog.add(1, "归还枪弹(保养)", list_gun.Count.ToString(), list_bullet.Count.ToString());
                            //更新本地数据库任务状态,建立执行中任务
                            UpdateTaskInfo.update(task_info, "6", "1", "3", "", gun_info_id, gun_pos_id, magazine_id, list_bullet);
                            //调用WebService接口,更改枪位状态
                            for (int i = 0; i < gun_number.Count; i++)
                            {
                                webService.setGunInStore(gun_info_id[i]);
                                webService.setGunOnPosition(task_info.UNIT_ID, task_info.GUNARK_ID, gun_pos_id[i]);
                                webService.setMaintainconfig(task_info.gunarkId);
                            }
                            //调用WebService接口,更改任务状态为已完成
                            webService.setFinishTask(task_info.TASK_ID, DateTime.Now, true, PubFlag.policeNum, PubFlag.dutyLeaderNum);
                        }
                        break;

                    //枪支调拨
                    case 7:
                        Utils.AddLog.add(1, "枪支调拨", list_gun.Count.ToString(), list_bullet.Count.ToString());
                        //更新本地数据库任务状态,建立执行中任务
                        UpdateTaskInfo.update(task_info, "6", "9", "0", "取弹", gun_info_id, gun_pos_id, magazine_id, list_bullet);
                        //调用WebService接口,更改枪位状态
                        for (int i = 0; i < gun_number.Count; i++)
                        {
                            webService.setGunBeAllot(gun_info_id[i]);
                            webService.setGunPosNotOnGunark(task_info.UNIT_ID, task_info.GUNARK_ID, gun_pos_id[i]);
                        }
                        //调用webservice接口,更改子弹库存量
                        for (int i = 0; i < magazine_id.Count; i++)
                        {
                            Console.WriteLine((int)magazine_info_bll.GetModel(magazine_id[i]).STOCK_QTY);
                            webService.setMagazineStock(magazine_id[i], (int)magazine_info_bll.GetModel(magazine_id[i]).STOCK_QTY);
                        }
                        //调用WebService接口,更改任务状态为已完成
                        webService.setFinishTask(task_info.TASK_ID, DateTime.Now, true, PubFlag.policeNum, PubFlag.dutyLeaderNum);
                        break;

                    //紧急取枪
                    case 8:
                        if (task_info.TASK_STATUS == "5")
                        {
                            Utils.AddLog.add(1, "归还枪弹(紧急)", list_gun.Count.ToString(), list_bullet.Count.ToString());
                            //更新本地数据库任务状态,建立执行中任务
                            UpdateTaskInfo.update(task_info, "6", "1", "3", "还弹", gun_info_id, gun_pos_id, magazine_id, list_bullet);
                            //更新调用接口参数
                            foreach (Model.task_info_detail item in list)
                            {
                                item.FLAG_TYPE = 2;
                                bll.Update(item);
                            }
                        }
                        else if (task_info.TASK_STATUS == "7")
                        {
                            Utils.AddLog.add(1, "超期归还(紧急取枪)", list_gun.Count.ToString(), list_bullet.Count.ToString());
                            //更新本地数据库任务状态,建立执行中任务
                            UpdateTaskInfo.update(task_info, "6", "1", "3", "还弹", gun_info_id, gun_pos_id, magazine_id, list_bullet);
                            //更新调用接口参数
                            foreach (Model.task_info_detail item in list)
                            {
                                item.FLAG_TYPE = 2;
                                bll.Update(item);
                            }
                        }
                        break;

                    //枪弹检查(取出枪支)
                    case 9:
                        if (task_info.TASK_STATUS == "3")
                        {
                            Utils.AddLog.add(1, "枪弹检查", list_gun.Count.ToString(), list_bullet.Count.ToString());
                            //更新本地数据库任务状态,建立执行中任务
                            UpdateTaskInfo.update(task_info, "5", "3", "2", "", gun_info_id, gun_pos_id, magazine_id, list_bullet);
                            //枪支点验不开枪锁,所以不更新数据库状态
                            //调用WebService接口,更改枪位状态
                            for (int i = 0; i < gun_number.Count; i++)
                            {
                                webService.setgunInUse(gun_info_id[i]);
                                webService.setGunNotOnPosition(task_info.UNIT_ID, task_info.GUNARK_ID, gun_pos_id[i]);
                            }
                            //调用WebService接口,更改任务状态为已完成
                            webService.setDoingTask(task_info.TASK_ID, DateTime.Now, true, PubFlag.policeNum, PubFlag.dutyLeaderNum);
                        }
                        else if (task_info.TASK_STATUS == "5")
                        {
                            Utils.AddLog.add(1, "归还枪弹(检查)", list_gun.Count.ToString(), list_bullet.Count.ToString());
                            //更新本地数据库任务状态,建立执行中任务
                            UpdateTaskInfo.update(task_info, "6", "1", "3", "", gun_info_id, gun_pos_id, magazine_id, list_bullet);
                            //调用WebService接口,更改枪位状态
                            for (int i = 0; i < gun_number.Count; i++)
                            {
                                webService.setGunInStore(gun_info_id[i]);
                                webService.setGunOnPosition(task_info.UNIT_ID, task_info.GUNARK_ID, gun_pos_id[i]);
                            }
                            for (int i = 0; i < magazine_id.Count; i++)
                            {
                                webService.setMagazineInfoCheck(magazine_id[i]);
                            }
                            //调用WebService接口,更改任务状态为已完成
                            webService.setFinishTask(task_info.TASK_ID, DateTime.Now, true, PubFlag.policeNum, PubFlag.dutyLeaderNum);
                        }
                        break;

                    //枪支解封
                    case 10:
                        Utils.AddLog.add(1, "枪支解封", list_gun.Count.ToString(), list_bullet.Count.ToString());
                        //更新本地数据库任务状态,建立执行中任务
                        UpdateTaskInfo.update(task_info, "6", "1", "3", "", gun_info_id, gun_pos_id, magazine_id, list_bullet);
                        //调用WebService接口,更改枪位状态
                        for (int i = 0; i < gun_number.Count; i++)
                        {
                            webService.setGunInStore(gun_info_id[i]);
                            webService.setGunOnPosition(task_info.unitId, task_info.gunarkId, gun_pos_id[i]);
                        }
                        //调用WebService接口,更改任务状态为已完成
                        webService.setFinishTask(task_info.TASK_ID, DateTime.Now, true, PubFlag.policeNum, PubFlag.dutyLeaderNum);
                        break;

                    //枪支寄存11
                    case 11:
                        Utils.AddLog.add(1, "枪支寄存", list_gun.Count.ToString(), list_bullet.Count.ToString());
                        //更新本地数据库任务状态,建立执行中任务
                        UpdateTaskInfo.update(task_info, "6", "10", "1", "", gun_info_id, gun_pos_id, magazine_id, list_bullet);
                        //调用WebService接口,更改枪位状态
                        for (int i = 0; i < gun_number.Count; i++)
                        {
                            webService.setgunLuggage(gun_info_id[i]);
                            webService.setgunpositionLuggage(gun_pos_id[i]);
                            //webService.setGunOnPosition(task_info.unitId, task_info.gunarkId, gun_info_id[i]);
                        }
                        //调用WebService接口,更改任务状态为已完成
                        webService.setFinishTask(task_info.TASK_ID, DateTime.Now, true, PubFlag.policeNum, PubFlag.dutyLeaderNum);
                        break;

                    //枪支解存12
                    case 12:
                        Utils.AddLog.add(1, "枪支解存", list_gun.Count.ToString(), list_bullet.Count.ToString());
                        //更新本地数据库任务状态,建立执行中任务
                        UpdateTaskInfo.update(task_info, "6", "11", "2", "", gun_info_id, gun_pos_id, magazine_id, list_bullet);
                        //调用WebService接口,更改枪位状态
                        for (int i = 0; i < gun_number.Count; i++)
                        {
                            webService.setgunExport(gun_info_id[i]);
                            webService.setGunPosNotOnGunark(task_info.unitId, task_info.gunarkId, gun_pos_id[i]);
                        }
                        //调用WebService接口,更改任务状态为已完成
                        webService.setFinishTask(task_info.TASK_ID, DateTime.Now, true, PubFlag.policeNum, PubFlag.dutyLeaderNum);
                        break;

                    //快速取枪
                    case 13:
                        if (task_info.TASK_STATUS == "5")
                        {
                            Utils.AddLog.add(1, "归还枪弹(快速取枪)", list_gun.Count.ToString(), list_bullet.Count.ToString());
                            //更新本地数据库任务状态,建立执行中任务
                            UpdateTaskInfo.update(task_info, "6", "1", "3", "还弹", gun_info_id, gun_pos_id, magazine_id, list_bullet);
                            //更新调用接口参数
                            foreach (Model.task_info_detail item in list)
                            {
                                item.FLAG_TYPE = 2;
                                bll.Update(item);
                            }
                        }
                        else if (task_info.TASK_STATUS == "7")
                        {
                            Utils.AddLog.add(1, "超期归还(快速取枪)", list_gun.Count.ToString(), list_bullet.Count.ToString());
                            //更新本地数据库任务状态,建立执行中任务
                            UpdateTaskInfo.update(task_info, "6", "1", "3", "还弹", gun_info_id, gun_pos_id, magazine_id, list_bullet);
                            //更新调用接口参数
                            foreach (Model.task_info_detail item in list)
                            {
                                item.FLAG_TYPE = 2;
                                bll.Update(item);
                            }
                        }
                        break;

                    //枪支点验
                    case 14:
                        Utils.AddLog.add(1, "枪支点验", list_gun.Count.ToString(), list_bullet.Count.ToString());
                        //更新本地数据库任务状态,建立执行中任务
                        UpdateTaskInfo.update(task_info, "6", "1", "3", "", gun_info_id, gun_pos_id, magazine_id, list_bullet);
                        //调用WebService接口,更改枪位状态
                        webService.setgunarkcheckingSuccess(task_info.gunarkId, task_info.unitId);
                        //调用WebService接口,更改任务状态为已完成
                        webService.setFinishTask(task_info.TASK_ID, DateTime.Now, true, PubFlag.policeNum, PubFlag.dutyLeaderNum);
                        break;

                    default:
                        break;
                    }
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 任务执行
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            if (comboBox1.Text.Equals("") && task_type.Equals("quick"))
            {
                MessageBox.Show("请选择任务类型");
                return;
            }
            if (comboBox2.Text.Equals("") && task_type.Equals("quick"))
            {
                MessageBox.Show("请选择任务时间");
                return;
            }
            int count = 0;

            //获取选中的行数
            for (int i = 0; i < dataGridView1.RowCount; i++)
            {
                if ((bool)dataGridView1.Rows[i].Cells[0].EditedFormattedValue)
                {
                    count++;
                }
            }
            if (count <= 0)
            {
                MessageBox.Show("请选择枪支!", "提示");
                return;
            }
            //身份验证界面
            Verify v = new Verify();

            v.Flag = 3;
            v.ShowDialog();
            //如果身份验证通过
            if (v.Result)
            {
                if (MessageBox.Show(this, "您确定要执行该任务么?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information).ToString() == "Yes")
                {
                    for (int i = 0; i < dataGridView1.RowCount; i++)
                    {
                        if ((bool)dataGridView1.Rows[i].Cells[0].EditedFormattedValue)
                        {
                            //枪支信息
                            gun_number.Add(dataGridView1.Rows[i].Cells[1].Value.ToString());
                            gun_info_id.Add(dataGridView1.Rows[i].Cells[3].Value.ToString());
                            gun_position_info_id.Add(dataGridView1.Rows[i].Cells[4].Value.ToString());
                            ////子弹信息
                            //magazine_number.Add(dataGridView2.Rows[i].Cells[0].Value.ToString());
                            //magazine_info_id.Add(dataGridView2.Rows[i].Cells[4].Value.ToString());
                            //try
                            //{
                            //    apply_bullet_qty.Add(Convert.ToInt32(dataGridView2.Rows[i].Cells[3].Value.ToString()));
                            //}
                            //catch (NullReferenceException n)
                            //{
                            //    MessageBox.Show("第【" + (i + 1) + "】行没有填写取弹数量!如果只取枪不取弹,请填写【0】!");
                            //    return;
                            //}
                            //if (Convert.ToInt32(dataGridView2.Rows[i].Cells[3].Value.ToString()) == 0)
                            //{
                            //    magazine_number.RemoveAt(i);
                            //    magazine_info_id.RemoveAt(i);
                            //}
                        }
                    }
                    Model.task_info task_info = new Gunark.Model.task_info();
                    //机构ID
                    task_info.UNIT_ID = ConfigurationManager.AppSettings["unit_id"];
                    //枪柜ID
                    task_info.gunarkId = ConfigurationManager.AppSettings["gunark_id"];
                    //任务类型(13代表快速取枪,8代表紧急取枪)
                    if (task_type.Equals("quick"))
                    {
                        task_info.TASK_BIGTYPE   = 13;
                        task_info.task_SmallType = "快速取枪";
                        //调用快速取枪接口
                        //...将任务id替换为调用接口返回的id值
                    }
                    else
                    {
                        task_info.TASK_BIGTYPE   = 8;
                        task_info.task_SmallType = "紧急取枪";
                    }
                    //任务状态
                    task_info.task_Status = "3";
                    this.button1.Enabled  = false;
                    this.button2.Enabled  = false;
                    //调用控制柜子公共类,返回值标识是否正常打开枪柜门
                    bool control_status = Utils.ControlGunark.control(task_info, ListToByte.List2Byte(gun_number), ListToByte.List2Byte(magazine_number));
                    //判断是否正常打开柜门,如果未正常打开,重新执行该任务
                    if (!control_status)
                    {
                        MessageBox.Show(this, "超时未开门,请重新做任务", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information, MessageBoxDefaultButton.Button2);
                    }
                    else
                    {
                        //生成任务信息
                        //32位GUID
                        task_info.TASK_ID = System.Guid.NewGuid().ToString();
                        //任务开始时间
                        task_info.task_Plan_BeginTime = string.Format("{0:yyyy-MM-dd HH:mm:ss.f}", DateTime.Now);
                        switch (comboBox2.Text)
                        {
                        case "4小时":
                            task_info.task_Plan_FinishTime = string.Format("{0:yyyy-MM-dd HH:mm:ss.f}", DateTime.Now.AddHours(+4d));
                            break;

                        case "8小时":
                            task_info.task_Plan_FinishTime = string.Format("{0:yyyy-MM-dd HH:mm:ss.f}", DateTime.Now.AddHours(+8d));
                            break;

                        case "12小时":
                            task_info.task_Plan_FinishTime = string.Format("{0:yyyy-MM-dd HH:mm:ss.f}", DateTime.Now.AddHours(+12d));
                            break;

                        default:
                            //紧急任务(默认执勤时间为24小时)
                            task_info.task_Plan_FinishTime = string.Format("{0:yyyy-MM-dd HH:mm:ss.f}", DateTime.Now.AddHours(+24d));
                            break;
                        }

                        //任务申请人
                        task_info.TASK_APPLY_USERID = PubFlag.policeNum;
                        //任务审批人
                        task_info.TASK_APPROVAL_USERID = PubFlag.bossLeaderNum;
                        task_info_bll.Add(task_info);
                        //生成任务详情信息
                        for (int i = 0; i < gun_number.Count; i++)
                        {
                            Model.task_info_detail task_info_details = new Gunark.Model.task_info_detail();
                            try
                            {
                                //任务详情ID
                                task_info_details.task_Detail_ID = System.Guid.NewGuid().ToString();
                                //任务ID
                                task_info_details.TASK_ID = task_info.task_ID;
                                //机构ID
                                task_info_details.UNIT_ID = task_info.unitId;
                                //枪柜ID
                                task_info_details.GUNARK_ID = task_info.gunarkId;
                                //枪支ID
                                task_info_details.GUN_INFO_ID = gun_info_id[i];
                                //枪位ID
                                task_info_details._gun_position_info_id = gun_position_info_bll.GetModelByGunInfo(task_info_details.GUN_INFO_ID).GUN_POSITION_INFO_ID;
                                //用枪人
                                task_info_details.GUN_DUTY_USER = PubFlag.policeNum;
                                //如果有子弹
                                if (magazine_number.Count > 0)
                                {
                                    //弹仓ID
                                    task_info_details.MAGAZINE_INFO_ID = magazine_info_id[i];
                                    //子弹类型
                                    task_info_details.BULLET_TYPE = magazine_info_bll.GetModel(magazine_info_id[i]).BULLET_MODEL;
                                    //取弹数量
                                    task_info_details.apply_Bullet_Qty = apply_bullet_qty[i];
                                }
                                task_info_details.FLAG_TYPE = 1;
                                task_info_details_bll.Add(task_info_details);
                            }
                            catch (ArgumentOutOfRangeException a) { task_info_details_bll.Add(task_info_details); }
                        }
                        if (task_type.Equals("quick"))
                        {
                            //插入日志
                            Utils.AddLog.add(1, "快速取枪弹", gun_number.Count.ToString(), magazine_number.Count.ToString());
                        }
                        else
                        {
                            //插入日志
                            Utils.AddLog.add(1, "紧急取枪弹", gun_number.Count.ToString(), magazine_number.Count.ToString());
                            //webService.setUrgentGunBulletTaskNew(task_info.task_ID,);
                        }
                        //更新本地数据库任务状态,建立执行中任务
                        UpdateTaskInfo.update(task_info, "5", "3", "2", "取弹", gun_info_id, gun_position_info_id, magazine_info_id, task_info_details_bll.GetModelList("TASK_ID = '" + task_info.TASK_ID + "'"));
                        this.Close();
                    }
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 执行任务
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            int[] applyQty = new int[apply_bullet_qty.Count];
            if (comboBox1.Text.Equals("") && task_type.Equals("quick"))
            {
                MessageBox.Show("请选择任务类型");
                return;
            }
            if (comboBox2.Text.Equals("") && task_type.Equals("quick"))
            {
                MessageBox.Show("请选择任务时间");
                return;
            }
            int count = 0;

            //获取选中的行数
            for (int i = 0; i < listView1.Items.Count; i++)
            {
                if (listView1.Items[i].ImageIndex == 0)
                {
                    count++;
                    break;
                }
            }
            if (count <= 0)
            {
                MessageBox.Show("请选择枪支!", "提示");
                return;
            }
            //身份验证界面
            Verify v = new Verify();

            v.Flag = 3;
            v.ShowDialog();
            //如果身份验证通过
            if (v.Result)
            {
                if (MessageBox.Show(this, "您确定要执行该任务么?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information).ToString() == "Yes")
                {
                    Model.task_info task_info = new Gunark.Model.task_info();
                    //机构ID
                    task_info.UNIT_ID = ConfigurationManager.AppSettings["unit_id"];
                    //枪柜ID
                    task_info.gunarkId = ConfigurationManager.AppSettings["gunark_id"];
                    //任务类型(13代表快速取枪,8代表紧急取枪)
                    if (task_type.Equals("quick"))
                    {
                        task_info.TASK_BIGTYPE   = 13;
                        task_info.task_SmallType = "快速取枪";
                    }
                    else
                    {
                        task_info.TASK_BIGTYPE   = 8;
                        task_info.task_SmallType = "紧急取枪";
                    }
                    //任务状态
                    task_info.task_Status = "3";
                    this.button1.Enabled  = false;
                    this.button2.Enabled  = false;
                    //调用控制柜子公共类,返回值标识是否正常打开枪柜门
                    bool control_status = Utils.ControlGunark.control(task_info, ListToByte.List2Byte(gun_number), ListToByte.List2Byte(magazine_number));
                    //判断是否正常打开柜门,如果未正常打开,重新执行该任务
                    if (!control_status)
                    {
                        MessageBox.Show(this, "超时未开门,请重新做任务", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information, MessageBoxDefaultButton.Button2);
                    }
                    else
                    {
                        //生成任务信息
                        //32位GUID
                        task_info.TASK_ID = System.Guid.NewGuid().ToString();
                        //任务开始时间
                        task_info.task_Plan_BeginTime = string.Format("{0:yyyy-MM-dd HH:mm:ss.f}", DateTime.Now);
                        switch (comboBox2.Text)
                        {
                        case "4小时":
                            task_info.task_Plan_FinishTime = string.Format("{0:yyyy-MM-dd HH:mm:ss.f}", DateTime.Now.AddHours(+4d));
                            break;

                        case "8小时":
                            task_info.task_Plan_FinishTime = string.Format("{0:yyyy-MM-dd HH:mm:ss.f}", DateTime.Now.AddHours(+8d));
                            break;

                        case "12小时":
                            task_info.task_Plan_FinishTime = string.Format("{0:yyyy-MM-dd HH:mm:ss.f}", DateTime.Now.AddHours(+12d));
                            break;

                        default:
                            //紧急任务(默认执勤时间为24小时)
                            task_info.task_Plan_FinishTime = string.Format("{0:yyyy-MM-dd HH:mm:ss.f}", DateTime.Now.AddHours(+24d));
                            break;
                        }

                        //任务申请人
                        task_info.TASK_APPLY_USERID = PubFlag.policeNum;
                        //任务申请时间
                        task_info.TASK_APPLY_TIME = string.Format("{0:yyyy-MM-dd HH:mm:ss.f}", DateTime.Now);
                        //任务审批人
                        task_info.TASK_APPROVAL_USERID = PubFlag.bossLeaderNum;
                        //将同步状态设为未同步(0:未同步,1:已同步)
                        task_info.taskFlagType = "0";
                        //如果是快速取枪,调用webservice接口,将任务信息上传

                        task_info_bll.Add(task_info);
                        //生成任务详情信息(枪)
                        for (int i = 0; i < gun_number.Count; i++)
                        {
                            Model.task_info_detail task_info_details = new Gunark.Model.task_info_detail();
                            try
                            {
                                //任务详情ID
                                task_info_details.task_Detail_ID = System.Guid.NewGuid().ToString();
                                //任务ID
                                task_info_details.TASK_ID = task_info.task_ID;
                                //机构ID
                                task_info_details.UNIT_ID = task_info.unitId;
                                //枪柜ID
                                task_info_details.GUNARK_ID = task_info.gunarkId;
                                //枪支ID
                                task_info_details.GUN_INFO_ID = gun_info_id[i];
                                //枪位ID
                                task_info_details._gun_position_info_id = gun_position_info_bll.GetModelByGunInfo(task_info_details.GUN_INFO_ID).GUN_POSITION_INFO_ID;
                                //用枪人
                                task_info_details.GUN_DUTY_USER = PubFlag.policeNum;
                                task_info_details.FLAG_TYPE     = 1;

                                task_info_details_bll.Add(task_info_details);
                            }
                            catch  {  }
                        }
                        //生成任务详情信息(弹)
                        for (int i = 0; i < magazine_number.Count; i++)
                        {
                            try
                            {
                                Model.task_info_detail task_info_details = new Gunark.Model.task_info_detail();
                                //任务详情ID
                                task_info_details.task_Detail_ID = System.Guid.NewGuid().ToString();
                                //任务ID
                                task_info_details.TASK_ID = task_info.task_ID;
                                //机构ID
                                task_info_details.UNIT_ID = task_info.unitId;
                                //枪柜ID
                                task_info_details.GUNARK_ID = task_info.gunarkId;
                                //弹仓ID
                                task_info_details.MAGAZINE_INFO_ID = magazine_info_id[i];
                                //子弹类型
                                task_info_details.BULLET_TYPE = magazine_info_bll.GetModel(magazine_info_id[i]).BULLET_MODEL;
                                //取弹数量
                                int qty = 0;
                                apply_bullet_qty.TryGetValue(task_info_details.MAGAZINE_INFO_ID, out qty);
                                task_info_details.apply_Bullet_Qty = qty;
                                applyQty[i] = qty;

                                if (task_info.task_BigType == 8)
                                {
                                    task_info_details.FLAG_TYPE = 0;
                                    //用这个字段标识紧急取枪需要调用接口情况,(get:调“未置枪接口”;return:调“置枪接口”)
                                    task_info_details.BULLET_ID = "get";
                                }

                                task_info_details_bll.Add(task_info_details);
                            }
                            catch { }
                        }

                        if (task_type.Equals("quick"))
                        {
                            //插入日志
                            Utils.AddLog.add(1, "快速取枪弹", gun_number.Count.ToString(), magazine_number.Count.ToString());
                            //更新本地数据库任务状态,建立执行中任务
                            UpdateTaskInfo.update(task_info, "5", "3", "2", "取弹", gun_info_id, gun_position_info_id, magazine_info_id, task_info_details_bll.GetModelList("TASK_ID = '" + task_info.TASK_ID + "'"));
                            //调用webservice接口,上传快速取枪任务
                            //....
                            //调用WebService接口,更改枪位状态
                            for (int i = 0; i < gun_number.Count; i++)
                            {
                                webService.setgunInUse(gun_info_id[i]);
                                webService.setGunNotOnPosition(task_info.UNIT_ID, task_info.GUNARK_ID, gun_position_info_id[i]);
                            }
                            //调用webservice接口,更改子弹库存量
                            for (int i = 0; i < magazine_info_id.Count; i++)
                            {
                                webService.setMagazineStock(magazine_info_id[i], (int)magazine_info_bll.GetModel(magazine_info_id[i]).STOCK_QTY);
                            }
                        }
                        else
                        {
                            //插入日志
                            Utils.AddLog.add(1, "紧急取枪弹", gun_number.Count.ToString(), magazine_number.Count.ToString());
                            //更新本地数据库任务状态,建立执行中任务
                            UpdateTaskInfo.update(task_info, "5", "3", "2", "取弹", gun_info_id, gun_position_info_id, magazine_info_id, task_info_details_bll.GetModelList("TASK_ID = '" + task_info.TASK_ID + "'"));
                            //调用webservice接口,上传紧急取枪任务
                            //....
                        }
                        this.Close();
                    }
                }
            }
        }