private void SetNavicert()
        {
            string strError = "";
            if (txtEmptyCode.Text.Trim() == "" || txtCarNo.Text.Trim() == "")
                strError += "请选择车辆登记信息";
            if (StaticParameter.IsRemoteReader == "1")
            {
                if (strReadRemoteCode == "")
                    strError += "没有读到电子标签";
                else
                {
                    if (strReadRemoteCode.Split(',').Length > 1)
                    {
                        strError += "读到了多个电子标签,请确认周围是否只有一个电子标签";
                    }
                    else
                    {
                        string strSql = "Select [CardCode] from [TT_RFCard] where [CardCode]='" + strReadRemoteCode + "'";
                        try
                        {
                            string strID = DbHelperSQL.GetSingle(strSql).ToString();
                            if (strID == null || strID == "")
                            {
                                strError += "该电子标签未初始化";
                            }
                        }
                        catch
                        {
                            strError += "该电子标签未初始化";
                        }

                    }
                }
            }
            if (strError != "")
            {
                alarmSound.Alarm(strError);
                return;
            }

            if (txtNavicertCode.Text.Trim() != "")
            {
                strNavicertCode = txtNavicertCode.Text.Trim();

                SqlParameter[] parameters =
                    {
                        new SqlParameter("@CarNo", SqlDbType.VarChar,20),
                        new SqlParameter("@NavicertCode", SqlDbType.VarChar,20)
                    };

                parameters[0].Value = txtCarNo.Text.Trim();
                parameters[1].Value = txtNavicertCode.Text.Trim();

                DataSet dstNavicertJudge = DbHelperSQL.RunProcedure("PT_NavicertCardJudge", parameters, "NavicertJudge");

                if (dstNavicertJudge.Tables.Count > 0)
                {
                    if (dstNavicertJudge.Tables["NavicertJudge"].Rows.Count > 0)
                    {
                        string strNavicertJudge = dstNavicertJudge.Tables["NavicertJudge"].Rows[0]["ReturnValue"].ToString();

                        if (strNavicertJudge != "0" && strNavicertJudge != "3")  //0:已发给别人,不能办理 1:从未办理,可以办理 2:可以更新,可以办理 3:车辆已有准运卡,不能办理一张新的
                        {
                            try
                            {
                                CoalTraffic.BLL.TT_Navicert bllNavicertCard = new CoalTraffic.BLL.TT_Navicert();
                                CoalTraffic.Model.TT_Navicert modelNavicertCard = new CoalTraffic.Model.TT_Navicert();
                                CoalTraffic.Model.TT_CarInfo modelCarInfo = new CoalTraffic.BLL.TT_CarInfo().GetModel(txtEmptyCode.Text.Trim().Replace("'", "''"));

                                modelNavicertCard.NavicertCode = strNavicertCode;
                                modelNavicertCard.ClaimPersonName = txtClaimPerson.Text.Trim();
                                modelNavicertCard.CarCode = txtEmptyCode.Text.Trim();
                                modelNavicertCard.NavicertCode = strNavicertCode;
                                modelNavicertCard.Remark = txtRemark.Text.Trim();
                                modelNavicertCard.CarNo = modelCarInfo.CarNo;
                                modelNavicertCard.CarType = modelCarInfo.CarType;
                                modelNavicertCard.EmptyWeight = modelCarInfo.EmptyWeight;
                                modelNavicertCard.MostWeight = modelCarInfo.MostWeight;
                                modelNavicertCard.RoomCode = ini.IniReadValue("RoomSetting", "RoomCode");
                                modelNavicertCard.CarOwnerIDCard = modelCarInfo.CarOwnerIDCard;
                                modelNavicertCard.CarOwnerName = modelCarInfo.CarOwnerName;
                                modelNavicertCard.CarOwnerPhone = modelCarInfo.CarOwnerPhone;
                                modelNavicertCard.StartTime = DateTime.Now;
                                modelNavicertCard.EndTime = DateTime.MaxValue;
                                modelNavicertCard.NavicertState = "1";
                                modelNavicertCard.CardType = "1";
                                modelNavicertCard.SendPerson = StaticParameter.UserName;
                                modelNavicertCard.IsForbid = "0";
                                modelNavicertCard.RemoteCardCode = strReadRemoteCode.Trim(',');
                                if (StaticParameter.CardType == "IC")
                                {
                                    modelNavicertCard.NavicertNo = strNavicertCode;
                                }
                                else
                                {
                                    modelNavicertCard.NavicertNo = (decimal.Parse(strNavicertCode)+dNavicert).ToString();
                                }

                                string strSuccess = "";
                                if (strNavicertJudge == "1")
                                {
                                    strSuccess = bllNavicertCard.Add(modelNavicertCard);

                                    #region 数据同步
                                    if (strSuccess != "")
                                    {
                                        //MSMQClient MC = new MSMQClient();
                                        StringBuilder sbInsert = new StringBuilder();
                                        sbInsert.Append("insert into TT_Navicert (NavicertCode,RoomCode,CarCode,CarNo,CarType,CarOwnerName,NavicertState,");
                                        sbInsert.Append("CardType,StartTime,EndTime,SendPerson,ClaimPersonName,CarOwnerPhone,CarOwnerIDCard,MostWeight,");
                                        sbInsert.Append("EmptyWeight,IsForbid,Remark,NavicertNo) values ('" + modelNavicertCard.NavicertCode + "','" + modelNavicertCard.RoomCode + "',");
                                        sbInsert.Append("'" + modelNavicertCard.CarCode + "','" + modelNavicertCard.CarNo + "','" + modelNavicertCard.CarType + "','" + modelNavicertCard.CarOwnerName + "',");
                                        sbInsert.Append("'" + modelNavicertCard.NavicertState + "','" + modelNavicertCard.CardType + "','" + modelNavicertCard.StartTime + "','" + modelNavicertCard.EndTime + "',");
                                        sbInsert.Append("'" + modelNavicertCard.SendPerson + "','" + modelNavicertCard.ClaimPersonName + "','" + modelNavicertCard.CarOwnerPhone + "',");
                                        sbInsert.Append("'" + modelNavicertCard.CarOwnerIDCard + "','" + modelNavicertCard.MostWeight + "','" + modelNavicertCard.EmptyWeight + "',");
                                        sbInsert.Append("'" + modelNavicertCard.IsForbid + "','" + modelNavicertCard.Remark + "','"+modelNavicertCard.NavicertNo+"')");

                                        #region 修改了同步方式
                                        string isConnection = ini.IniReadValue("Connection", "isConnection");
                                        if (isConnection == "0")
                                        {
                                            mqServer.AddMsmq(MC.AllStation + MC.Prefix + "TT_Navicert" + MC.Prefix + MC.AddFlg + MC.Prefix + DateTime.Now.ToString("yyyy-MM-dd hh:mm;ss") + MC.Prefix + sbInsert.ToString());
                                        }
                                        else
                                        {
                                            MC.AddNewSqlText(MC.AllStation + MC.Prefix + "TT_Navicert" + MC.Prefix + MC.AddFlg + MC.Prefix + DateTime.Now.ToString("yyyy-MM-dd hh:mm;ss") + MC.Prefix + sbInsert.ToString());//原来的通过消息队列进行发送消息
                                        }
                                        #endregion

                                        if (modelNavicertCard.RemoteCardCode != "")
                                        {
                                            string strUpdateCarInfo = "Update TT_CarInfo Set RemoteCardCode='" + modelNavicertCard.RemoteCardCode + "' where CarCode='" + modelNavicertCard.CarCode + "'";
                                            if (isConnection == "0")
                                            {
                                                mqServer.AddMsmq(MC.AllStation + MC.Prefix + "TT_CarInfo" + MC.Prefix + MC.AddFlg + MC.Prefix + DateTime.Now.ToString("yyyy-MM-dd hh:mm;ss") + MC.Prefix + strUpdateCarInfo);
                                            }
                                            else
                                            {
                                                MC.AddNewSqlText(MC.AllStation + MC.Prefix + "TT_CarInfo" + MC.Prefix + MC.AddFlg + MC.Prefix + DateTime.Now.ToString("yyyy-MM-dd hh:mm;ss") + MC.Prefix + strUpdateCarInfo);
                                            }
                                        }
                                        //try
                                        //{
                                        //    CoalTraffic.MessagingService.LocalWeightServiceClient loalclient = new CoalTraffic.MessagingService.LocalWeightServiceClient();
                                        //    loalclient.AddNavicerCard(modelNavicertCard);
                                        //}
                                        //catch
                                        //{ }
                                    }
                                    #endregion
                                }
                                else if (strNavicertJudge == "2")
                                {
                                    string strSql = "Select NavicertCode from TT_Navicert where CarNo='" + modelNavicertCard.CarNo.Replace("'", "''") + "' and NavicertState<>'2'";
                                    string strID = DbHelperSQL.GetSingle(strSql).ToString();

                                    DialogResult dResult = CommonMethod.MessageBox("该车辆已办理该准运卡,是否更新该卡?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                                    if (dResult == DialogResult.No)
                                    {
                                        ClearAllText();
                                        return;
                                    }
                                    modelNavicertCard.NavicertCode = strID;
                                    strSuccess = bllNavicertCard.Update(modelNavicertCard);
                                    string isConnection = ini.IniReadValue("Connection", "isConnection");
                                    #region 数据同步

                                    if (strSuccess != "")
                                    {
                                        //MSMQClient MC = new MSMQClient();
                                        StringBuilder strUpdate = new StringBuilder();
                                        strUpdate.Append("update TT_Navicert set RoomCode='" + modelNavicertCard.RoomCode + "',CarCode='" + modelNavicertCard.CarCode + "',");
                                        strUpdate.Append("CarNo='" + modelNavicertCard.CarNo + "',CarType='" + modelNavicertCard.CarType + "',");
                                        strUpdate.Append("CarOwnerName='" + modelNavicertCard.CarOwnerName + "',NavicertState='" + modelNavicertCard.NavicertState + "',");
                                        strUpdate.Append("CardType='" + modelNavicertCard.CardType + "',StartTime='" + modelNavicertCard.StartTime + "',");
                                        strUpdate.Append("EndTime='" + modelNavicertCard.EndTime + "',SendPerson='" + modelNavicertCard.SendPerson + "',");
                                        strUpdate.Append("ClaimPersonName='" + modelNavicertCard.ClaimPersonName + "',CarOwnerPhone='" + modelNavicertCard.CarOwnerPhone + "',");
                                        strUpdate.Append("CarOwnerIDCard='" + modelNavicertCard.CarOwnerIDCard + "',MostWeight='" + modelNavicertCard.MostWeight + "',");
                                        strUpdate.Append("EmptyWeight='" + modelNavicertCard.EmptyWeight + "',IsForbid='" + modelNavicertCard.IsForbid + "',");
                                        strUpdate.Append("Remark='" + modelNavicertCard.Remark + "',NavicertNo='"+modelNavicertCard.NavicertNo+"' where NavicertCode='" + modelNavicertCard.NavicertCode + "'");
                                        if (isConnection == "0")
                                        {
                                            mqServer.AddMsmq(MC.AllStation + MC.Prefix + "TT_Navicert" + MC.Prefix + MC.EditFlg + MC.Prefix + DateTime.Now.ToString("yyyy-MM-dd hh:mm;ss") + MC.Prefix + strUpdate.ToString());
                                        }
                                        else
                                        {
                                            MC.AddNewSqlText(MC.AllStation + MC.Prefix + "TT_Navicert" + MC.Prefix + MC.EditFlg + MC.Prefix + DateTime.Now.ToString("yyyy-MM-dd hh:mm;ss") + MC.Prefix + strUpdate.ToString());
                                        }
                                        if (modelNavicertCard.RemoteCardCode != "")
                                        {
                                            if (isConnection == "0")
                                            {
                                                mqServer.AddMsmq(MC.AllStation + MC.Prefix + "TT_Navicert" + MC.Prefix + MC.EditFlg + MC.Prefix + DateTime.Now.ToString("yyyy-MM-dd hh:mm;ss") + MC.Prefix + "Update TT_CarInfo Set RemoteCardCode='" + modelNavicertCard.RemoteCardCode + "' where CarCode='" + modelNavicertCard.CarCode + "'");
                                            }
                                            else
                                            {
                                                MC.AddNewSqlText(MC.AllStation + MC.Prefix + "TT_Navicert" + MC.Prefix + MC.EditFlg + MC.Prefix + DateTime.Now.ToString("yyyy-MM-dd hh:mm;ss") + MC.Prefix + "Update TT_CarInfo Set RemoteCardCode='" + modelNavicertCard.RemoteCardCode + "' where CarCode='" + modelNavicertCard.CarCode + "'");
                                            }
                                        }
                                        //try
                                        //{
                                        //    CoalTraffic.MessagingService.LocalWeightServiceClient loalclient = new CoalTraffic.MessagingService.LocalWeightServiceClient();
                                        //    loalclient.UpdateNavicerCard(modelNavicertCard);
                                        //}
                                        //catch
                                        //{ }
                                    }
                                    #endregion
                                }
                                if (strSuccess != string.Empty)
                                {
                                    alarmSound.Alarm("准运卡办理成功,即将打印办理凭证");

                                    Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
                                    string strFileName = "";
                                    if (StaticParameter.ReportFile == "FuYuan.")
                                    {
                                        strFileName = "ZiChang.";
                                    }
                                    else
                                    {
                                        strFileName = StaticParameter.ReportFile;
                                    }

                                    Type type = assembly.GetType("CoalTraffic.Report." + strFileName + "NavicertCardPrint");
                                    object obj = Activator.CreateInstance(type, strSuccess, true); Form formToShow = (Form)obj; formToShow.ShowDialog();
                                }
                                else
                                    alarmSound.Alarm("准运卡办理失败");
                                ClearAllText();
                            }
                            catch (Exception ex)
                            {
                                CommonMethod.MessageBox(ex.ToString(), MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            }
                        }
                        else if (strNavicertJudge == "0")
                        {
                            ClearAllText();
                            alarmSound.Alarm("该准运卡已发给其它车辆,不能再次办理");
                        }
                        else if (strNavicertJudge == "3")
                        {
                            ClearAllText();
                            alarmSound.Alarm("该车辆已有准运卡,不能再为其办理一张新的准运卡,如需更换,请先将原准运卡挂失");
                        }

                    }
                }

            }
            else
            {
                alarmSound.Alarm("请刷准运卡");
            }
            txtNavicertCode.Focus();
        }
        private void btnSend_Click(object sender, EventArgs e)
        {
            string strError = "";
            //txtRemoteCard.Text = "123";
            //txtNavicertCode.Text = "00000789";

            if (txtEmptyCode.Text.Trim() == "" || txtCarNo.Text.Trim() == "")
                strError += "请选择车辆登记信息";
            if (IsHaveRemote == "1")
            {
                if (strReadRemoteCode == "")
                    strError += "没有读到电子标签";
                else
                {
                    if (strReadRemoteCode.Split(',').Length > 1)
                        strError += "读到了多个电子标签,请确认周围是否只有一个电子标签";
                }
            }
            if (strError != "")
            {
                alarmSound.Alarm(strError);
                return;
            }

            if (txtNavicertCode.Text.Trim() != "")
            {
                strNavicertCode = txtNavicertCode.Text.Trim();

                SqlParameter[] parameters =
                    {
                        new SqlParameter("@CarNo", SqlDbType.VarChar,20),
                        new SqlParameter("@NavicertCode", SqlDbType.VarChar,20)
                    };

                parameters[0].Value = txtCarNo.Text.Trim();
                parameters[1].Value = txtNavicertCode.Text.Trim();

                DataSet dstNavicertJudge = DbHelperSQL.RunProcedure("PT_NavicertCardJudge", parameters, "NavicertJudge");

                if (dstNavicertJudge.Tables.Count > 0)
                {
                    if (dstNavicertJudge.Tables["NavicertJudge"].Rows.Count > 0)
                    {
                        string strNavicertJudge = dstNavicertJudge.Tables["NavicertJudge"].Rows[0]["ReturnValue"].ToString();

                        if (strNavicertJudge != "0" && strNavicertJudge != "3")  //0:已发给别人,不能办理 1:从未办理,可以办理 2:可以更新,可以办理 3:车辆已有准运卡,不能办理一张新的
                        {
                            try
                            {
                                CoalTraffic.BLL.TT_Navicert bllNavicertCard = new CoalTraffic.BLL.TT_Navicert();
                                CoalTraffic.Model.TT_Navicert modelNavicertCard = new CoalTraffic.Model.TT_Navicert();
                                CoalTraffic.Model.TT_CarInfo modelCarInfo = new CoalTraffic.BLL.TT_CarInfo().GetModel(txtEmptyCode.Text.Trim().Replace("'", "''"));

                                modelNavicertCard.NavicertCode = strNavicertCode;
                                modelNavicertCard.ClaimPersonName = txtClaimPerson.Text.Trim();
                                modelNavicertCard.CarCode = txtEmptyCode.Text.Trim();
                                //modelNavicertCard.NavicertCode = strNavicertCode;
                                modelNavicertCard.Remark = txtRemark.Text.Trim();
                                modelNavicertCard.CarNo = modelCarInfo.CarNo;
                                modelNavicertCard.CarType = modelCarInfo.CarType;
                                modelNavicertCard.EmptyWeight = modelCarInfo.EmptyWeight;
                                modelNavicertCard.MostWeight = modelCarInfo.MostWeight;
                                modelNavicertCard.RoomCode = "0";
                                modelNavicertCard.CarOwnerIDCard = modelCarInfo.CarOwnerIDCard;
                                modelNavicertCard.CarOwnerName = modelCarInfo.CarOwnerName;
                                modelNavicertCard.CarOwnerPhone = modelCarInfo.CarOwnerPhone;
                                modelNavicertCard.StartTime = DateTime.Now;
                                modelNavicertCard.EndTime = DateTime.MaxValue;
                                modelNavicertCard.NavicertState = "1";
                                modelNavicertCard.CardType = "1";
                                modelNavicertCard.SendPerson = StaticParameter.UserName;
                                modelNavicertCard.IsForbid = "0";
                                modelNavicertCard.RemoteCardCode=strReadRemoteCode.TrimEnd(',');
                                //modelNavicertCard.RemoteCardCode = txtRemoteCard.Text;
                                modelNavicertCard.NavicertNo = strNavicertCode;

                                string strSuccess = "";
                                if (strNavicertJudge == "1")
                                {
                                    strSuccess = bllNavicertCard.Add(modelNavicertCard);
                                    #region 数据同步到各磅房
                                    if (strSuccess != "")
                                    {
                                        StringBuilder sbInsert = new StringBuilder();
                                        sbInsert.Append("insert into TT_Navicert(NavicertCode,RoomCode,CarCode,CarNo,CarType,CarOwnerName,NavicertState,");
                                        sbInsert.Append("CardType,StartTime,EndTime,SendPerson,ClaimPersonName,CarOwnerPhone,CarOwnerIDCard,MostWeight,");
                                        sbInsert.Append("EmptyWeight,IsForbid,Remark) values ('" + modelNavicertCard.NavicertCode + "','" + modelNavicertCard.RoomCode + "',");
                                        sbInsert.Append("'" + modelNavicertCard.CarCode + "','" + modelNavicertCard.CarNo + "','" + modelNavicertCard.CarType + "','" + modelNavicertCard.CarOwnerName + "',");
                                        sbInsert.Append("'" + modelNavicertCard.NavicertState + "','" + modelNavicertCard.CardType + "','" + modelNavicertCard.StartTime + "','" + modelNavicertCard.EndTime + "',");
                                        sbInsert.Append("'" + modelNavicertCard.SendPerson + "','" + modelNavicertCard.ClaimPersonName + "','" + modelNavicertCard.CarOwnerPhone + "',");
                                        sbInsert.Append("'" + modelNavicertCard.CarOwnerIDCard + "','" + modelNavicertCard.MostWeight + "','" + modelNavicertCard.EmptyWeight + "',");
                                        sbInsert.Append("'" + modelNavicertCard.IsForbid + "','" + modelNavicertCard.Remark + "');");
                                        if (modelNavicertCard.RemoteCardCode != "")
                                            sbInsert.Append("Update TT_CarInfo Set RemoteCardCode='" + modelNavicertCard.RemoteCardCode + "' where CarCode='" + modelNavicertCard.CarCode + "'");
                                        MsmqManage mq = new MsmqManage();
                                        string strMq = mq.AllStation + mq.Prefix + "TT_Navicert" + mq.Prefix + mq.AddFlg + mq.Prefix + DateTime.Now.ToString("yyyy-MM-dd hh:mm;ss") + mq.Prefix + sbInsert.ToString();
                                        mq.AddMsmq(strMq.ToString());
                                        //MsmqManage mq = new MsmqManage();
                                        //mq.AddMsmq(sbInsert.ToString());
                                    }
                                    #endregion
                                }
                                else if (strNavicertJudge == "2")
                                {
                                    string strSql = "Select NavicertCode from TT_Navicert where CarNo='" + modelNavicertCard.CarNo.Replace("'", "''") + "' and NavicertState='1'";
                                    string strID = DbHelperSQL.GetSingle(strSql).ToString();

                                    DialogResult dResult = CommonMethod.MessageBox("该车辆已办理准运卡,是否将此卡更新?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                                    if (dResult == DialogResult.No)
                                    {
                                        ClearAllText();
                                        return;
                                    }
                                    modelNavicertCard.NavicertCode = strID;
                                    strSuccess = bllNavicertCard.Update(modelNavicertCard);

                                    #region 数据同步到各磅房
                                    if (strSuccess != "")
                                    {
                                        StringBuilder strUpdate = new StringBuilder();
                                        strUpdate.Append("update TT_Navicert set RoomCode='" + modelNavicertCard.RoomCode + "',CarCode='" + modelNavicertCard.CarCode + "',");
                                        strUpdate.Append("CarNo='" + modelNavicertCard.CarNo + "',CarType='" + modelNavicertCard.CarType + "',");
                                        strUpdate.Append("CarOwnerName='" + modelNavicertCard.CarOwnerName + "',NavicertState='" + modelNavicertCard.NavicertState + "',");
                                        strUpdate.Append("CardType='" + modelNavicertCard.CardType + "',StartTime='" + modelNavicertCard.StartTime + "',");
                                        strUpdate.Append("EndTime='" + modelNavicertCard.EndTime + "',SendPerson='" + modelNavicertCard.SendPerson + "',");
                                        strUpdate.Append("ClaimPersonName='" + modelNavicertCard.ClaimPersonName + "',CarOwnerPhone='" + modelNavicertCard.CarOwnerPhone + "',");
                                        strUpdate.Append("CarOwnerIDCard='" + modelNavicertCard.CarOwnerIDCard + "',MostWeight='" + modelNavicertCard.MostWeight + "',");
                                        strUpdate.Append("EmptyWeight='" + modelNavicertCard.EmptyWeight + "',IsForbid='" + modelNavicertCard.IsForbid + "',");
                                        strUpdate.Append("Remark='" + modelNavicertCard.Remark + "' where NavicertCode='" + modelNavicertCard.NavicertCode + "';");
                                        if(modelNavicertCard.RemoteCardCode!="")
                                            strUpdate.Append("Update TT_CarInfo Set RemoteCardCode='" + modelNavicertCard.RemoteCardCode + "' where CarCode='" + modelNavicertCard.CarCode + "'");
                                        MsmqManage mq = new MsmqManage();
                                        string strMq = mq.AllStation + mq.Prefix + "TT_Navicert" + mq.Prefix + mq.EditFlg + mq.Prefix + DateTime.Now.ToString("yyyy-MM-dd hh:mm;ss") + mq.Prefix + strUpdate.ToString();
                                        mq.AddMsmq(strMq.ToString());
                                        //new MsmqManage().AddMsmq(strUpdate.ToString());
                                    }
                                    #endregion
                                }

                                if (strSuccess != "")//if (strSuccess != string.Empty)
                                {
                                    alarmSound.Alarm("准运卡办理成功即将打印办理凭证");
                                    new report.NavicertCardPrint(strSuccess, true).ShowDialog();
                                }
                                else
                                {
                                    alarmSound.Alarm("准运卡办理失败");
                                }
                                ClearAllText();
                            }
                            catch (Exception ex)
                            {
                                CommonMethod.MessageBox(ex.ToString(), MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            }
                        }
                        else if (strNavicertJudge == "0")
                        {
                            ClearAllText();
                            alarmSound.Alarm("该准运卡已发给其它车辆不能再次办理");

                        }
                        else if (strNavicertJudge == "3")
                        {
                            ClearAllText();
                            alarmSound.Alarm("该车辆已有准运卡不能再为其办理一张新的准运卡如需更换请先将原准运卡注销");
                        }
                    }
                }
            }
            else
            {
                alarmSound.Alarm("请刷准运卡");
            }
        }
        /// <summary>
        /// 补卡的方法
        /// </summary>
        public void Send()
        {
            if (txtBNavicertCode.Text.Trim() == "")
            {
                alarmSound.Alarm("请刷准运卡");
                return;
            }

            string sSQL = "select NavicertCode from TT_Navicert where NavicertCode='" + txtBNavicertCode.Text.Trim() + "'and NavicertState='1'";
            object OResult = DbHelperSQL.GetSingle(sSQL);
            if (OResult != null)
            {
                alarmSound.Alarm("此卡已经和其它车辆绑定请另外刷卡");
                return;
            }

            strNavicertCode = txtBNavicertCode.Text.Trim();

            CoalTraffic.BLL.TT_Navicert bll = new CoalTraffic.BLL.TT_Navicert();
            DataSet ds = new DataSet();
            ds = bll.GetList("CarCode='" + this.txtBEmptyCode.Text.Trim() + "'");

            if (ds.Tables[0].Rows.Count > 0)
            {
                //注销准运卡表里该条记录
                SendCard.Public.SWPublic dal = new SendCard.Public.SWPublic();
                CoalTraffic.Model.TT_Navicert model = new CoalTraffic.Model.TT_Navicert();
                model.CarCode = this.txtBEmptyCode.Text;
                model.NavicertState = "3";

                dal.Add(model);

                //增加一条新准运卡记录
                CoalTraffic.Model.TT_Navicert model2 = new CoalTraffic.Model.TT_Navicert();
                CoalTraffic.Model.TT_CarInfo modelCarInfo = new CoalTraffic.BLL.TT_CarInfo().GetModel(txtBEmptyCode.Text.Trim().Replace("'", "''"));
                if (model2 != null)
                {
                    model2.NavicertCode = strNavicertCode;
                    model2.RoomCode = modelCarInfo.RoomCode;
                    model2.CarCode = txtBEmptyCode.Text.Trim();
                    model2.CarNo = modelCarInfo.CarNo;
                    model2.CarType = modelCarInfo.CarType;
                    model2.CarOwnerName = modelCarInfo.CarOwnerName;
                    model2.CarOwnerPhone = modelCarInfo.CarOwnerPhone;
                    model2.CarOwnerIDCard = modelCarInfo.CarOwnerIDCard;
                    model2.MostWeight = modelCarInfo.MostWeight;
                    model2.EmptyWeight = modelCarInfo.EmptyWeight;
                    model2.NavicertState = "1";
                    model2.CardType = "1";
                    model2.StartTime = DateTime.Now;
                    model2.EndTime = DateTime.MaxValue;
                    model2.SendPerson = StaticParameter.UserName;
                    model2.ClaimPersonName = txtBClaimPerson.Text.Trim();
                    model2.IsForbid = "0";
                    model2.Remark = txtBRemark.Text.Trim();
                    model2.NavicertNo = strNavicertCode;
                }

                string strSuccess = "";
                strSuccess = bll.Add(model2);
                if (strSuccess != "")
                {
                    //发送消息到磅房
                    //发送修改信息到队列和增加的队列。
                    StringBuilder sbInsert = new StringBuilder();
                    sbInsert.Append("insert into TT_Navicert(NavicertCode,RoomCode,CarCode,CarNo,CarType,CarOwnerName,NavicertState,");
                    sbInsert.Append("CardType,StartTime,EndTime,SendPerson,ClaimPersonName,CarOwnerPhone,CarOwnerIDCard,MostWeight,");
                    sbInsert.Append("EmptyWeight,IsForbid,Remark) values ('" + model2.NavicertCode + "','" + model2.RoomCode + "',");
                    sbInsert.Append("'" + model2.CarCode + "','" + model2.CarNo + "','" + model2.CarType + "','" + model2.CarOwnerName + "',");
                    sbInsert.Append("'" + model2.NavicertState + "','" + model2.CardType + "','" + model2.StartTime + "','" + model2.EndTime + "',");
                    sbInsert.Append("'" + model2.SendPerson + "','" + model2.ClaimPersonName + "','" + model2.CarOwnerPhone + "',");
                    sbInsert.Append("'" + model2.CarOwnerIDCard + "','" + model2.MostWeight + "','" + model2.EmptyWeight + "',");
                    sbInsert.Append("'" + model2.IsForbid + "','" + model2.Remark + "');");
                    sbInsert.Append("update TT_Navicert set NavicertState='3'");
                    sbInsert.Append("where CarCode='" + this.txtBEmptyCode.Text.Trim() + "'and NavicertState='1'");
                    MsmqManage mq = new MsmqManage();
                    string strMq = mq.AllStation + mq.Prefix + "TT_Navicert" + mq.Prefix + mq.AddFlg + mq.Prefix + DateTime.Now.ToString("yyyy-MM-dd hh:mm;ss") + mq.Prefix + sbInsert.ToString();
                    mq.AddMsmq(strMq.ToString());
                    alarmSound.Alarm("准运卡办理成功,即将打印办理凭证");
                    new report.NavicertCardPrint(strSuccess, true).ShowDialog();
                }
            }
        }
        private void SetNavicert()
        {
            string strError = "";
            if (txtEmptyCode.Text.Trim() == "" || txtCarNo.Text.Trim() == "")
                strError += "请选择空车过磅信息";
            if (StaticParameter.IsRemoteReader == "1")
            {
                if (strReadRemoteCode == "")
                    strError += "没有读到电子标签";
                else
                {
                    if (strReadRemoteCode.Split(',').Length > 1)
                        strError += "读到了多个电子标签,请确认周围是否只有一个电子标签";
                }
            }
            if (strError != "")
            {
                alarmSound.Alarm(strError);
                return;
            }

            if (txtNavicertCode.Text.Trim() != "")
            {
                strNavicertCode = txtNavicertCode.Text.Trim();

                SqlParameter[] parameters =
                    {
                        new SqlParameter("@CarNo", SqlDbType.VarChar,20),
                        new SqlParameter("@NavicertCode", SqlDbType.VarChar,20)
                    };

                parameters[0].Value = txtCarNo.Text.Trim();
                parameters[1].Value = txtNavicertCode.Text.Trim();

                DataSet dstNavicertJudge = DbHelperSQL.RunProcedure("PT_NavicertCardJudge", parameters, "NavicertJudge");

                if (dstNavicertJudge.Tables.Count > 0)
                {
                    if (dstNavicertJudge.Tables["NavicertJudge"].Rows.Count > 0)
                    {
                        string strNavicertJudge = dstNavicertJudge.Tables["NavicertJudge"].Rows[0]["ReturnValue"].ToString();

                        if (strNavicertJudge != "0" && strNavicertJudge != "3")  //0:已发给别人,不能办理 1:从未办理,可以办理 2:可以更新,可以办理 3:车辆已有准运卡,不能办理一张新的
                        {
                            try
                            {
                                CoalTraffic.BLL.TT_Navicert bllNavicertCard = new CoalTraffic.BLL.TT_Navicert();
                                CoalTraffic.Model.TT_Navicert modelNavicertCard = new CoalTraffic.Model.TT_Navicert();
                                CoalTraffic.Model.TT_CarInfo modelCarInfo = new CoalTraffic.BLL.TT_CarInfo().GetModel(txtEmptyCode.Text.Trim().Replace("'", "''"));

                                modelNavicertCard.NavicertCode = strNavicertCode;
                                modelNavicertCard.ClaimPersonName = txtClaimPerson.Text.Trim();
                                modelNavicertCard.CarCode = txtEmptyCode.Text.Trim();
                                modelNavicertCard.NavicertCode = strNavicertCode;
                                modelNavicertCard.Remark = txtRemark.Text.Trim();
                                modelNavicertCard.CarNo = modelCarInfo.CarNo;
                                modelNavicertCard.CarType = modelCarInfo.CarType;
                                modelNavicertCard.EmptyWeight = modelCarInfo.EmptyWeight;
                                modelNavicertCard.MostWeight = modelCarInfo.MostWeight;
                                modelNavicertCard.RoomCode = ini.IniReadValue("RoomSetting", "RoomCode");
                                modelNavicertCard.CarOwnerIDCard = modelCarInfo.CarOwnerIDCard;
                                modelNavicertCard.CarOwnerName = modelCarInfo.CarOwnerName;
                                modelNavicertCard.CarOwnerPhone = modelCarInfo.CarOwnerPhone;
                                modelNavicertCard.StartTime = DateTime.Now;
                                modelNavicertCard.EndTime = DateTime.MaxValue;
                                modelNavicertCard.NavicertState = "1";
                                modelNavicertCard.CardType = "1";
                                modelNavicertCard.SendPerson = StaticParameter.UserName;
                                modelNavicertCard.IsForbid = "0";
                                modelNavicertCard.RemoteCardCode = strReadRemoteCode.Trim(',');
                                if (StaticParameter.CardType == "IC")
                                {
                                    modelNavicertCard.NavicertNo = strNavicertCode;
                                }
                                else
                                {
                                    modelNavicertCard.NavicertNo = (decimal.Parse(strNavicertCode)+dNavicert).ToString();
                                }

                                string strSuccess = "";
                                if (strNavicertJudge == "1")
                                {
                                    strSuccess = bllNavicertCard.Add(modelNavicertCard);
                                }
                                else if (strNavicertJudge == "2")
                                {
                                    string strSql = "Select NavicertCode from TT_Navicert where CarNo='" + modelNavicertCard.CarNo.Replace("'", "''") + "' and NavicertState<>'2'";
                                    string strID = DbHelperSQL.GetSingle(strSql).ToString();

                                    DialogResult dResult = CommonMethod.MessageBox("该车辆已办理该准运卡,是否更新该卡?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                                    if (dResult == DialogResult.No)
                                    {
                                        ClearAllText();
                                        return;
                                    }
                                    modelNavicertCard.NavicertCode = strID;
                                    strSuccess = bllNavicertCard.Update(modelNavicertCard);

                                }
                                if (strSuccess != string.Empty)
                                {
                                    alarmSound.Alarm("准运卡办理成功,即将打印办理凭证");

                                    Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
                                    string strFileName = "";
                                    if (StaticParameter.ReportFile == "FuYuan.")
                                    {
                                        strFileName = "ZiChang.";
                                    }
                                    else
                                    {
                                        strFileName = StaticParameter.ReportFile;
                                    }

                                    Type type = assembly.GetType("CoalTraffic.Report." + strFileName + "NavicertCardPrint");
                                    object obj = Activator.CreateInstance(type, strSuccess, true); Form formToShow = (Form)obj; formToShow.ShowDialog();
                                }
                                else
                                    alarmSound.Alarm("准运卡办理失败");
                                ClearAllText();
                            }
                            catch (Exception ex)
                            {
                                CommonMethod.MessageBox(ex.ToString(), MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            }
                        }
                        else if (strNavicertJudge == "0")
                        {
                            ClearAllText();
                            alarmSound.Alarm("该准运卡已发给其它车辆,不能再次办理");
                        }
                        else if (strNavicertJudge == "3")
                        {
                            ClearAllText();
                            alarmSound.Alarm("该车辆已有准运卡,不能再为其办理一张新的准运卡,如需更换,请先将原准运卡挂失");
                        }

                    }
                }

            }
            else
            {
                alarmSound.Alarm("请刷准运卡");
            }
            txtNavicertCode.Focus();
        }
        public void Send()
        {
            if (txtBNavicertCode.Text.Trim() == "")
            {
                alarmSound.Alarm("请刷准运卡");
                return;
            }

            string sSQL = "select NavicertCode from TT_Navicert where NavicertCode='" + txtBNavicertCode.Text.Trim() + "'and NavicertState='1'";
            object OResult = DbHelperSQL.GetSingle(sSQL);
            if (OResult != null)
            {
                alarmSound.Alarm("此卡已经和其它车辆绑定请另外刷卡");
                return;
            }

            strNavicertCode = txtBNavicertCode.Text.Trim();

            CoalTraffic.BLL.TT_Navicert bll = new CoalTraffic.BLL.TT_Navicert();
            DataSet ds = new DataSet();
            ds = bll.GetList("CarCode='" + this.txtBEmptyCode.Text.Trim() + "'");

            if (ds.Tables[0].Rows.Count > 0)
            {

                //禁用准运卡表里该条记录

                CoalTraffic.Model.TT_Navicert model = new CoalTraffic.Model.TT_Navicert();
                model.NavicertCode = ds.Tables[0].Rows[0]["NavicertCode"].ToString();
                model.RoomCode = ds.Tables[0].Rows[0]["RoomCode"].ToString();
                model.CarCode = ds.Tables[0].Rows[0]["CarCode"].ToString();
                model.CarNo = ds.Tables[0].Rows[0]["CarNo"].ToString();
                model.CarType = ds.Tables[0].Rows[0]["CarType"].ToString();
                model.CarOwnerName = ds.Tables[0].Rows[0]["CarOwnerName"].ToString();
                model.CarOwnerPhone = ds.Tables[0].Rows[0]["CarOwnerPhone"].ToString();
                model.CarOwnerIDCard = ds.Tables[0].Rows[0]["CarOwnerIDCard"].ToString();
                model.MostWeight = Convert.ToDecimal( ds.Tables[0].Rows[0]["MostWeight"]);
                model.EmptyWeight = Convert.ToDecimal(ds.Tables[0].Rows[0]["EmptyWeight"]);
                model.NavicertState = "1";
                model.CardType = "1";
                model.StartTime = DateTime.Now;
                model.EndTime = DateTime.MaxValue;
                model.SendPerson = ds.Tables[0].Rows[0]["SendPerson"].ToString();
                model.ClaimPersonName = ds.Tables[0].Rows[0]["ClaimPersonName"].ToString();
                model.IsForbid = "1";
                model.Remark = ds.Tables[0].Rows[0]["Remark"].ToString()+"— 因补办被禁用";
                model.NavicertNo = ds.Tables[0].Rows[0]["NavicertCode"].ToString();

                bll.Update(model);

                //增加一条新准运卡记录
                CoalTraffic.Model.TT_Navicert model2 = new CoalTraffic.Model.TT_Navicert();
                CoalTraffic.Model.TT_CarInfo modelCarInfo = new CoalTraffic.BLL.TT_CarInfo().GetModel(txtBEmptyCode.Text.Trim().Replace("'", "''"));
                if (model2 != null)
                {
                    model2.NavicertCode = strNavicertCode;
                    model2.RoomCode = modelCarInfo.RoomCode;
                    model2.CarCode = txtBEmptyCode.Text.Trim();
                    model2.CarNo = modelCarInfo.CarNo;
                    model2.CarType = modelCarInfo.CarType;
                    model2.CarOwnerName = modelCarInfo.CarOwnerName;
                    model2.CarOwnerPhone = modelCarInfo.CarOwnerPhone;
                    model2.CarOwnerIDCard = modelCarInfo.CarOwnerIDCard;
                    model2.MostWeight = modelCarInfo.MostWeight;
                    model2.EmptyWeight = modelCarInfo.EmptyWeight;
                    model2.NavicertState = "1";
                    model2.CardType = "1";
                    model2.StartTime = DateTime.Now;
                    model2.EndTime = DateTime.MaxValue;
                    model2.SendPerson = StaticParameter.UserName;
                    model2.ClaimPersonName = txtBClaimPerson.Text.Trim();
                    model2.IsForbid = "0";
                    model2.Remark = txtBRemark.Text.Trim();
                    model2.NavicertNo = strNavicertCode;
                }

                string strSuccess = "";
                strSuccess = bll.Add(model2);
                if (strSuccess != "")
                {
                    //发送消息到磅房
                    //发送修改信息到队列和增加的队列。
                    string isConnection = ini.IniReadValue("Connection", "isConnection");
                    StringBuilder sbInsert = new StringBuilder();
                    sbInsert.Append("insert into TT_Navicert(NavicertCode,RoomCode,CarCode,CarNo,CarType,CarOwnerName,NavicertState,");
                    sbInsert.Append("CardType,StartTime,EndTime,SendPerson,ClaimPersonName,CarOwnerPhone,CarOwnerIDCard,MostWeight,");
                    sbInsert.Append("EmptyWeight,IsForbid,Remark) values ('" + model2.NavicertCode + "','" + model2.RoomCode + "',");
                    sbInsert.Append("'" + model2.CarCode + "','" + model2.CarNo + "','" + model2.CarType + "','" + model2.CarOwnerName + "',");
                    sbInsert.Append("'" + model2.NavicertState + "','" + model2.CardType + "','" + model2.StartTime + "','" + model2.EndTime + "',");
                    sbInsert.Append("'" + model2.SendPerson + "','" + model2.ClaimPersonName + "','" + model2.CarOwnerPhone + "',");
                    sbInsert.Append("'" + model2.CarOwnerIDCard + "','" + model2.MostWeight + "','" + model2.EmptyWeight + "',");
                    sbInsert.Append("'" + model2.IsForbid + "','" + model2.Remark + "');");
                    sbInsert.Append("update TT_Navicert set IsForbid = '1'");
                    sbInsert.Append("where CarCode='" + this.txtBEmptyCode.Text.Trim() + "'and IsForbid = '0'");
                    if (isConnection == "0")
                    {
                        mqServer.AddMsmq(mq.AllStation + mq.Prefix + "TT_Navicert" + mq.Prefix + mq.AddFlg + mq.Prefix + DateTime.Now.ToString("yyyy-MM-dd hh:mm;ss") + mq.Prefix + sbInsert.ToString());
                    }
                    else
                    {
                        mq.AddNewSqlText(mq.AllStation + mq.Prefix + "TT_Navicert" + mq.Prefix + mq.AddFlg + mq.Prefix + DateTime.Now.ToString("yyyy-MM-dd hh:mm;ss") + mq.Prefix + sbInsert.ToString());
                    }
                    alarmSound.Alarm("准运卡办理成功,即将打印办理凭证");
                    new Report.NavicertCardPrint(strSuccess, true,"补办").ShowDialog();
                }
            }
        }
        public void Send()
        {
            #region 条件判断
            if (txtBNavicertCode.Text.Trim() == "")
            {
                alarmSound.Alarm("请刷准运卡");
                MessageBox.Show("请刷准运卡", "天大天科", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }

            string sSQL = "select NavicertCode from TT_Navicert where NavicertCode='" + txtBNavicertCode.Text.Trim() + "'and NavicertState='1'";
            object OResult = DbHelperSQL.GetSingle(sSQL);
            if (OResult != null)
            {
                alarmSound.Alarm("此卡已经和其它车辆绑定请另外刷卡");
                MessageBox.Show("此卡已经和其它车辆绑定请另外刷卡", "天大天科", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }
            #endregion

            strNavicertCode = txtBNavicertCode.Text.Trim();

            CoalTraffic.BLL.TT_Navicert bll = new CoalTraffic.BLL.TT_Navicert();
            DataSet ds = new DataSet();
            ds = bll.GetList("CarCode='" + this.txtBEmptyCode.Text.Trim() + "'");

            if (ds.Tables[0].Rows.Count > 0)
            {

                //禁用准运卡表里该条记录

                #region 构造原准运卡实体对象
                CoalTraffic.Model.TT_Navicert model = new CoalTraffic.Model.TT_Navicert();
                model.NavicertCode = ds.Tables[0].Rows[0]["NavicertCode"].ToString();
                model.RoomCode = ds.Tables[0].Rows[0]["RoomCode"].ToString();
                model.CarCode = ds.Tables[0].Rows[0]["CarCode"].ToString();
                model.CarNo = ds.Tables[0].Rows[0]["CarNo"].ToString();
                model.CarType = ds.Tables[0].Rows[0]["CarType"].ToString();
                model.CarOwnerName = ds.Tables[0].Rows[0]["CarOwnerName"].ToString();
                model.CarOwnerPhone = ds.Tables[0].Rows[0]["CarOwnerPhone"].ToString();
                model.CarOwnerIDCard = ds.Tables[0].Rows[0]["CarOwnerIDCard"].ToString();
                model.MostWeight = Convert.ToDecimal(ds.Tables[0].Rows[0]["MostWeight"]);
                model.EmptyWeight = Convert.ToDecimal(ds.Tables[0].Rows[0]["EmptyWeight"]);
                model.NavicertState = "1";
                model.CardType = "1";
                model.StartTime = DateTime.Now;
                model.EndTime = DateTime.MaxValue;
                model.SendPerson = ds.Tables[0].Rows[0]["SendPerson"].ToString();
                model.ClaimPersonName = ds.Tables[0].Rows[0]["ClaimPersonName"].ToString();
                model.IsForbid = "1";
                model.Remark = ds.Tables[0].Rows[0]["Remark"].ToString() + "— 因补办被禁用";
                model.NavicertNo = ds.Tables[0].Rows[0]["NavicertCode"].ToString();
                #endregion
                bll.Update(model);//禁用原有准运卡

                //增加一条新准运卡记录
                CoalTraffic.Model.TT_Navicert model2 = new CoalTraffic.Model.TT_Navicert();
                CoalTraffic.Model.TT_CarInfo modelCarInfo = new CoalTraffic.BLL.TT_CarInfo().GetModel(txtBEmptyCode.Text.Trim().Replace("'", "''"));
                #region 构造补办准运卡实体对象
                if (model2 != null)
                {
                    model2.NavicertCode = strNavicertCode;
                    model2.RoomCode = modelCarInfo.RoomCode;
                    model2.CarCode = txtBEmptyCode.Text.Trim();
                    model2.CarNo = modelCarInfo.CarNo;
                    model2.CarType = modelCarInfo.CarType;
                    model2.CarOwnerName = modelCarInfo.CarOwnerName;
                    model2.CarOwnerPhone = modelCarInfo.CarOwnerPhone;
                    model2.CarOwnerIDCard = modelCarInfo.CarOwnerIDCard;
                    model2.MostWeight = modelCarInfo.MostWeight;
                    model2.EmptyWeight = modelCarInfo.EmptyWeight;
                    model2.NavicertState = "1";
                    model2.CardType = "1";
                    model2.StartTime = DateTime.Now;
                    model2.EndTime = DateTime.MaxValue;
                    model2.SendPerson = StaticParameter.UserName;
                    model2.ClaimPersonName = txtBClaimPerson.Text.Trim();
                    model2.IsForbid = "0";
                    model2.Remark = txtBRemark.Text.Trim();
                    model2.NavicertNo = strNavicertCode;
                }

                #endregion
                string strSuccess = "";
                strSuccess = bll.Add(model2);//添加新准运卡信息

                string isConnection = ini.IniReadValue("Connection", "isConnection");

                #region 当联网的时:插入同步sql语句到服务器,sql语句本地执行
                if (isConnection == "0")
                {
                    StringBuilder sbInsert = new StringBuilder();
                    sbInsert.Append("insert into TT_Navicert(NavicertCode,RoomCode,CarCode,CarNo,CarType,CarOwnerName,NavicertState,");
                    sbInsert.Append("CardType,StartTime,EndTime,SendPerson,ClaimPersonName,CarOwnerPhone,CarOwnerIDCard,MostWeight,");
                    sbInsert.Append("EmptyWeight,IsForbid,Remark) values ('" + model2.NavicertCode + "','" + model2.RoomCode + "',");
                    sbInsert.Append("'" + model2.CarCode + "','" + model2.CarNo + "','" + model2.CarType + "','" + model2.CarOwnerName + "',");
                    sbInsert.Append("'" + model2.NavicertState + "','" + model2.CardType + "','" + model2.StartTime + "','" + model2.EndTime + "',");
                    sbInsert.Append("'" + model2.SendPerson + "','" + model2.ClaimPersonName + "','" + model2.CarOwnerPhone + "',");
                    sbInsert.Append("'" + model2.CarOwnerIDCard + "','" + model2.MostWeight + "','" + model2.EmptyWeight + "',");
                    sbInsert.Append("'" + model2.IsForbid + "','" + model2.Remark + "');");
                    sbInsert.Append("update TT_Navicert set IsForbid = '1'");
                    sbInsert.Append("where CarCode='" + this.txtBEmptyCode.Text.Trim() + "'and IsForbid = '0'");

                    string sqlInsertLog = "insert [NetWorkDisconnectionLog] (ID, SQLcontext, datetime, IP) values (@ID,@SQLcontext,@datetime,@IP)";
                    SqlParameter[] sqlpars = new SqlParameter[]
                        {
                            new SqlParameter("@ID",DateTime.Now.ToString("yyyyMMddHHmmss")),
                            new SqlParameter("@SQLcontext",sbInsert.ToString()),
                            new SqlParameter("@datetime",DateTime.Now.ToString()),
                            new SqlParameter("@IP",ini.IniReadValue("Connection","LServer"))
                        };
                    DbHelperSQL.ExecuteSql(sqlInsertLog,sqlpars); //插入同步sql语句
                    DbHelperSQL.ExecuteSql2(sbInsert.ToString(), "1");//sql语句本地执行
                }
                #endregion

                if (strSuccess != "")
                {

                    #region 断网时,添加准运卡禁用和补办准运卡sql语句

                    if (isConnection == "1")
                    {
                        StringBuilder sbInsert = new StringBuilder();
                        sbInsert.Append("insert into TT_Navicert(NavicertCode,RoomCode,CarCode,CarNo,CarType,CarOwnerName,NavicertState,");
                        sbInsert.Append("CardType,StartTime,EndTime,SendPerson,ClaimPersonName,CarOwnerPhone,CarOwnerIDCard,MostWeight,");
                        sbInsert.Append("EmptyWeight,IsForbid,Remark) values ('" + model2.NavicertCode + "','" + model2.RoomCode + "',");
                        sbInsert.Append("'" + model2.CarCode + "','" + model2.CarNo + "','" + model2.CarType + "','" + model2.CarOwnerName + "',");
                        sbInsert.Append("'" + model2.NavicertState + "','" + model2.CardType + "','" + model2.StartTime + "','" + model2.EndTime + "',");
                        sbInsert.Append("'" + model2.SendPerson + "','" + model2.ClaimPersonName + "','" + model2.CarOwnerPhone + "',");
                        sbInsert.Append("'" + model2.CarOwnerIDCard + "','" + model2.MostWeight + "','" + model2.EmptyWeight + "',");
                        sbInsert.Append("'" + model2.IsForbid + "','" + model2.Remark + "');");
                        sbInsert.Append("update TT_Navicert set IsForbid = '1'");
                        sbInsert.Append("where CarCode='" + this.txtBEmptyCode.Text.Trim() + "'and IsForbid = '0'");
                        string id = DateTime.Now.ToString("yyyyMMddHHmmss");
                        StringBuilder sbsqlcontext = new StringBuilder();
                        sbsqlcontext.Append("insert into NetWorkDisconnection (ID, SQLcontext, DateTime) values(@id,@sqlcontext,@datetime)");
                        SqlParameter[] parameters = new SqlParameter[] {
                                                                                            new SqlParameter("@id",id),
                                                                                            new SqlParameter("@sqlcontext",sbInsert.ToString()),
                                                                                            new SqlParameter("@datetime",DateTime.Now)
                                                                                             };
                        DbHelperSQL.ExecuteSql(sbsqlcontext.ToString(), parameters);
                    }
                    #endregion
                    alarmSound.Alarm("准运卡办理成功,即将打印办理凭证");
                    new Report.NavicertCardPrint(strSuccess, true, "补办").ShowDialog();
                }
            }
        }
        private void SetNavicert()
        {
            string strError = "";
            if (txtEmptyCode.Text.Trim() == "" || txtCarNo.Text.Trim() == "")
                strError += "请选择车辆登记信息";
            if (StaticParameter.IsRemoteReader == "1")
            {
                if (strReadRemoteCode == "")
                    strError += "没有读到电子标签";
                else
                {
                    if (strReadRemoteCode.Split(',').Length > 1)
                    {
                        strError += "读到了多个电子标签,请确认周围是否只有一个电子标签";
                    }
                    else
                    {
                        string strSql = "Select [CardCode] from [TT_RFCard] where [CardCode]='" + strReadRemoteCode + "'";
                        try
                        {
                            string strID = DbHelperSQL.GetSingle(strSql).ToString();
                            if (strID == null || strID == "")
                            {
                                strError += "该电子标签未初始化";
                            }
                        }
                        catch
                        {
                            strError += "该电子标签未初始化";
                        }

                    }
                }
            }
            if (strError != "")
            {
                alarmSound.Alarm(strError);
                MessageBox.Show(strError, "天大天科", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (txtNavicertCode.Text.Trim() != "")
            {
                strNavicertCode = txtNavicertCode.Text.Trim();

                SqlParameter[] parameters =
                    {
                        new SqlParameter("@CarNo", SqlDbType.VarChar,20),
                        new SqlParameter("@NavicertCode", SqlDbType.VarChar,20)
                    };

                parameters[0].Value = txtCarNo.Text.Trim();
                parameters[1].Value = txtNavicertCode.Text.Trim();

                DataSet dstNavicertJudge = DbHelperSQL.RunProcedure("PT_NavicertCardJudge", parameters, "NavicertJudge");

                if (dstNavicertJudge.Tables.Count > 0)
                {
                    if (dstNavicertJudge.Tables["NavicertJudge"].Rows.Count > 0)
                    {
                        string strNavicertJudge = dstNavicertJudge.Tables["NavicertJudge"].Rows[0]["ReturnValue"].ToString();

                        if (strNavicertJudge != "0" && strNavicertJudge != "3")  //0:已发给别人,不能办理 1:从未办理,可以办理 2:可以更新,可以办理 3:车辆已有准运卡,不能办理一张新的
                        {
                            try
                            {
                                #region 添加实体对象
                                CoalTraffic.BLL.TT_Navicert bllNavicertCard = new CoalTraffic.BLL.TT_Navicert();
                                CoalTraffic.Model.TT_Navicert modelNavicertCard = new CoalTraffic.Model.TT_Navicert();
                                CoalTraffic.Model.TT_CarInfo modelCarInfo = new CoalTraffic.BLL.TT_CarInfo().GetModel(txtEmptyCode.Text.Trim().Replace("'", "''"));
                                modelNavicertCard.NavicertCode = strNavicertCode;
                                modelNavicertCard.ClaimPersonName = txtClaimPerson.Text.Trim();
                                modelNavicertCard.CarCode = txtEmptyCode.Text.Trim();
                                modelNavicertCard.NavicertCode = strNavicertCode;
                                modelNavicertCard.Remark = txtRemark.Text.Trim();
                                modelNavicertCard.CarNo = modelCarInfo.CarNo;
                                modelNavicertCard.CarType = modelCarInfo.CarType;
                                modelNavicertCard.EmptyWeight = modelCarInfo.EmptyWeight;
                                modelNavicertCard.MostWeight = modelCarInfo.MostWeight;
                                modelNavicertCard.RoomCode = ini.IniReadValue("RoomSetting", "RoomCode");
                                modelNavicertCard.CarOwnerIDCard = modelCarInfo.CarOwnerIDCard;
                                modelNavicertCard.CarOwnerName = modelCarInfo.CarOwnerName;
                                modelNavicertCard.CarOwnerPhone = modelCarInfo.CarOwnerPhone;
                                modelNavicertCard.StartTime = DateTime.Now;
                                modelNavicertCard.EndTime = DateTime.MaxValue;
                                modelNavicertCard.NavicertState = "1";
                                modelNavicertCard.CardType = "1";
                                modelNavicertCard.SendPerson = StaticParameter.UserName;
                                modelNavicertCard.IsForbid = "0";
                                modelNavicertCard.RemoteCardCode = strReadRemoteCode.Trim(',');
                                if (StaticParameter.CardType == "IC")
                                {
                                    modelNavicertCard.NavicertNo = strNavicertCode;
                                }
                                else
                                {
                                    modelNavicertCard.NavicertNo = (decimal.Parse(strNavicertCode) + dNavicert).ToString();
                                }
                                #endregion

                                string strSuccess = "";
                                if (strNavicertJudge == "1")//可以办理
                                {
                                    strSuccess = bllNavicertCard.Add(modelNavicertCard);

                                    string isConnection = ini.IniReadValue("Connection", "isConnection");

                                    #region 当联网的时:插入同步sql语句到服务器,sql语句本地执行
                                    if (isConnection == "0")
                                    {
                                        StringBuilder sbInsertLocal = new StringBuilder();
                                        sbInsertLocal.Append("insert into TT_Navicert (NavicertCode,RoomCode,CarCode,CarNo,CarType,CarOwnerName,NavicertState,");
                                        sbInsertLocal.Append("CardType,StartTime,EndTime,SendPerson,ClaimPersonName,CarOwnerPhone,CarOwnerIDCard,MostWeight,");
                                        sbInsertLocal.Append("EmptyWeight,IsForbid,Remark,NavicertNo) values ('" + modelNavicertCard.NavicertCode + "','" + modelNavicertCard.RoomCode + "',");
                                        sbInsertLocal.Append("'" + modelNavicertCard.CarCode + "','" + modelNavicertCard.CarNo + "','" + modelNavicertCard.CarType + "','" + modelNavicertCard.CarOwnerName + "',");
                                        sbInsertLocal.Append("'" + modelNavicertCard.NavicertState + "','" + modelNavicertCard.CardType + "','" + modelNavicertCard.StartTime + "','" + modelNavicertCard.EndTime + "',");
                                        sbInsertLocal.Append("'" + modelNavicertCard.SendPerson + "','" + modelNavicertCard.ClaimPersonName + "','" + modelNavicertCard.CarOwnerPhone + "',");
                                        sbInsertLocal.Append("'" + modelNavicertCard.CarOwnerIDCard + "','" + modelNavicertCard.MostWeight + "','" + modelNavicertCard.EmptyWeight + "',");
                                        sbInsertLocal.Append("'" + modelNavicertCard.IsForbid + "','" + modelNavicertCard.Remark + "','" + modelNavicertCard.NavicertNo + "')");

                                        string sqlInsertLog = "insert [NetWorkDisconnectionLog] (ID, SQLcontext, datetime, IP) values (@ID,@SQLcontext,@datetime,@IP)";
                                        SqlParameter[] sqlpars = new SqlParameter[]
                        {
                            new SqlParameter("@ID",DateTime.Now.ToString("yyyyMMddHHmmss")),
                            new SqlParameter("@SQLcontext",sbInsertLocal.ToString()),
                            new SqlParameter("@datetime",DateTime.Now.ToString()),
                            new SqlParameter("@IP",ini.IniReadValue("Connection","LServer"))
                        };
                                        DbHelperSQL.ExecuteSql(sqlInsertLog,sqlpars); //插入同步sql语句
                                        DbHelperSQL.ExecuteSql2(sbInsertLocal.ToString(), "1");//sql语句本地执行
                                    }
                                    #endregion

                                    #region 当断网时
                                    if (strSuccess != "")
                                    {

                                        #region 当断网时,添加准运卡补办sql语句
                                        if (isConnection == "1")
                                        {
                                            StringBuilder sbInsert = new StringBuilder();
                                            sbInsert.Append("insert into TT_Navicert (NavicertCode,RoomCode,CarCode,CarNo,CarType,CarOwnerName,NavicertState,");
                                            sbInsert.Append("CardType,StartTime,EndTime,SendPerson,ClaimPersonName,CarOwnerPhone,CarOwnerIDCard,MostWeight,");
                                            sbInsert.Append("EmptyWeight,IsForbid,Remark,NavicertNo) values ('" + modelNavicertCard.NavicertCode + "','" + modelNavicertCard.RoomCode + "',");
                                            sbInsert.Append("'" + modelNavicertCard.CarCode + "','" + modelNavicertCard.CarNo + "','" + modelNavicertCard.CarType + "','" + modelNavicertCard.CarOwnerName + "',");
                                            sbInsert.Append("'" + modelNavicertCard.NavicertState + "','" + modelNavicertCard.CardType + "','" + modelNavicertCard.StartTime + "','" + modelNavicertCard.EndTime + "',");
                                            sbInsert.Append("'" + modelNavicertCard.SendPerson + "','" + modelNavicertCard.ClaimPersonName + "','" + modelNavicertCard.CarOwnerPhone + "',");
                                            sbInsert.Append("'" + modelNavicertCard.CarOwnerIDCard + "','" + modelNavicertCard.MostWeight + "','" + modelNavicertCard.EmptyWeight + "',");
                                            sbInsert.Append("'" + modelNavicertCard.IsForbid + "','" + modelNavicertCard.Remark + "','" + modelNavicertCard.NavicertNo + "')");

                                            string id = DateTime.Now.ToString("yyyyMMddHHmmss");
                                            StringBuilder sbsqlcontext = new StringBuilder();
                                            sbsqlcontext.Append("insert into NetWorkDisconnection (ID, SQLcontext, DateTime) values(@id,@sqlcontext,@datetime)");
                                            SqlParameter[] parameters1 = new SqlParameter[] {
                                                                                            new SqlParameter("@id",id),
                                                                                            new SqlParameter("@sqlcontext",sbInsert.ToString()),
                                                                                            new SqlParameter("@datetime",DateTime.Now)
                                                                                             };
                                            DbHelperSQL.ExecuteSql(sbsqlcontext.ToString(), parameters1);

                                            if (modelNavicertCard.RemoteCardCode != "")//电子标签更新
                                            {
                                                string strUpdateCarInfo = "Update TT_CarInfo Set RemoteCardCode='" +
                                                                          modelNavicertCard.RemoteCardCode +
                                                                          "' where CarCode='" +
                                                                          modelNavicertCard.CarCode + "'";
                                                string id2 = DateTime.Now.ToString("yyyyMMddHHmmss");
                                                StringBuilder sbsqlcontext2 = new StringBuilder();
                                                sbsqlcontext.Append("insert into NetWorkDisconnection (ID, SQLcontext, DateTime) values(@id,@sqlcontext,@datetime)");
                                                SqlParameter[] parameters2 = new SqlParameter[] {
                                                                                            new SqlParameter("@id",id2),
                                                                                            new SqlParameter("@sqlcontext",strUpdateCarInfo),
                                                                                            new SqlParameter("@datetime",DateTime.Now)
                                                                                             };
                                                DbHelperSQL.ExecuteSql(sbsqlcontext.ToString(), parameters2);
                                            }
                                        }

                                        #endregion
                                    }
                                    #endregion
                                }
                                else if (strNavicertJudge == "2")//更新准运卡
                                {
                                    string strSql = "Select NavicertCode from TT_Navicert where CarNo='" + modelNavicertCard.CarNo.Replace("'", "''") + "' and NavicertState<>'2'";
                                    string strID = DbHelperSQL.GetSingle(strSql).ToString();

                                    DialogResult dResult = CommonMethod.MessageBox("该车辆已办理该准运卡,是否更新该卡?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                                    if (dResult == DialogResult.No)
                                    {
                                        ClearAllText();
                                        return;
                                    }
                                    modelNavicertCard.NavicertCode = strID;
                                    strSuccess = bllNavicertCard.Update(modelNavicertCard);

                                    string isConnection = ini.IniReadValue("Connection", "isConnection");

                                   #region 当联网的时:插入同步sql语句到服务器,sql语句本地执行
                                    if (isConnection == "0")
                                    {
                                        StringBuilder strUpdateLocal = new StringBuilder();
                                        strUpdateLocal.Append("update TT_Navicert set RoomCode='" + modelNavicertCard.RoomCode + "',CarCode='" + modelNavicertCard.CarCode + "',");
                                        strUpdateLocal.Append("CarNo='" + modelNavicertCard.CarNo + "',CarType='" + modelNavicertCard.CarType + "',");
                                        strUpdateLocal.Append("CarOwnerName='" + modelNavicertCard.CarOwnerName + "',NavicertState='" + modelNavicertCard.NavicertState + "',");
                                        strUpdateLocal.Append("CardType='" + modelNavicertCard.CardType + "',StartTime='" + modelNavicertCard.StartTime + "',");
                                        strUpdateLocal.Append("EndTime='" + modelNavicertCard.EndTime + "',SendPerson='" + modelNavicertCard.SendPerson + "',");
                                        strUpdateLocal.Append("ClaimPersonName='" + modelNavicertCard.ClaimPersonName + "',CarOwnerPhone='" + modelNavicertCard.CarOwnerPhone + "',");
                                        strUpdateLocal.Append("CarOwnerIDCard='" + modelNavicertCard.CarOwnerIDCard + "',MostWeight='" + modelNavicertCard.MostWeight + "',");
                                        strUpdateLocal.Append("EmptyWeight='" + modelNavicertCard.EmptyWeight + "',IsForbid='" + modelNavicertCard.IsForbid + "',");
                                        strUpdateLocal.Append("Remark='" + modelNavicertCard.Remark + "',NavicertNo='" + modelNavicertCard.NavicertNo + "' where NavicertCode='" + modelNavicertCard.NavicertCode + "'");

                                        string sqlInsertLog = "insert [NetWorkDisconnectionLog] (ID, SQLcontext, datetime, IP) values (@ID,@SQLcontext,@datetime,@IP)";
                                        SqlParameter[] sqlpars = new SqlParameter[]
                        {
                            new SqlParameter("@ID",DateTime.Now.ToString("yyyyMMddHHmmss")),
                            new SqlParameter("@SQLcontext",strUpdateLocal.ToString()),
                            new SqlParameter("@datetime",DateTime.Now.ToString()),
                            new SqlParameter("@IP",ini.IniReadValue("Connection","LServer"))
                        };
                                        DbHelperSQL.ExecuteSql(sqlInsertLog,sqlpars); //插入同步sql语句
                                        DbHelperSQL.ExecuteSql2(strUpdateLocal.ToString(), "1");//sql语句本地执行
                                    }
                                    #endregion

                                    #region 当断网时,添加准运卡补办sql语句
                                    if (strSuccess != "")
                                    {

                                        if (isConnection == "1")
                                        {
                                            StringBuilder strUpdate = new StringBuilder();
                                            strUpdate.Append("update TT_Navicert set RoomCode='" + modelNavicertCard.RoomCode + "',CarCode='" + modelNavicertCard.CarCode + "',");
                                            strUpdate.Append("CarNo='" + modelNavicertCard.CarNo + "',CarType='" + modelNavicertCard.CarType + "',");
                                            strUpdate.Append("CarOwnerName='" + modelNavicertCard.CarOwnerName + "',NavicertState='" + modelNavicertCard.NavicertState + "',");
                                            strUpdate.Append("CardType='" + modelNavicertCard.CardType + "',StartTime='" + modelNavicertCard.StartTime + "',");
                                            strUpdate.Append("EndTime='" + modelNavicertCard.EndTime + "',SendPerson='" + modelNavicertCard.SendPerson + "',");
                                            strUpdate.Append("ClaimPersonName='" + modelNavicertCard.ClaimPersonName + "',CarOwnerPhone='" + modelNavicertCard.CarOwnerPhone + "',");
                                            strUpdate.Append("CarOwnerIDCard='" + modelNavicertCard.CarOwnerIDCard + "',MostWeight='" + modelNavicertCard.MostWeight + "',");
                                            strUpdate.Append("EmptyWeight='" + modelNavicertCard.EmptyWeight + "',IsForbid='" + modelNavicertCard.IsForbid + "',");
                                            strUpdate.Append("Remark='" + modelNavicertCard.Remark + "',NavicertNo='" + modelNavicertCard.NavicertNo + "' where NavicertCode='" + modelNavicertCard.NavicertCode + "'");

                                            if (modelNavicertCard.RemoteCardCode != "")
                                            {
                                                string strUpdateCarInfo = "Update TT_CarInfo Set RemoteCardCode='" +
                                                                          modelNavicertCard.RemoteCardCode +
                                                                          "' where CarCode='" +
                                                                          modelNavicertCard.CarCode + "'";
                                                strUpdate.Append(";" + strUpdateCarInfo);
                                            }
                                            string id3 = DateTime.Now.ToString("yyyyMMddHHmmss");
                                            StringBuilder sbsqlcontext = new StringBuilder();
                                            sbsqlcontext.Append("insert into NetWorkDisconnection (ID, SQLcontext, DateTime) values(@id,@sqlcontext,@datetime)");
                                            SqlParameter[] parameters3 = new SqlParameter[] {
                                                                                            new SqlParameter("@id",id3),
                                                                                            new SqlParameter("@sqlcontext",strUpdate.ToString()),
                                                                                            new SqlParameter("@datetime",DateTime.Now)
                                                                                             };
                                            DbHelperSQL.ExecuteSql(sbsqlcontext.ToString(), parameters3);
                                        }

                                    }
                                    #endregion
                                }

                                if (strSuccess != string.Empty)
                                {
                                    alarmSound.Alarm("准运卡办理成功,即将打印办理凭证");
                                    MessageBox.Show("准运卡办理成功,即将打印办理凭证", "天大天科", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                                    #region 打印相关
                                    Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
                                    string strFileName = "";
                                    if (StaticParameter.ReportFile == "FuYuan.")
                                    {
                                        strFileName = "ZiChang.";
                                    }
                                    else
                                    {
                                        strFileName = StaticParameter.ReportFile;
                                    }

                                    Type type = assembly.GetType("CoalTraffic.Report." + strFileName + "NavicertCardPrint");
                                    object obj = Activator.CreateInstance(type, strSuccess, true); Form formToShow = (Form)obj; formToShow.ShowDialog();
                                    #endregion
                                }
                                else
                                {
                                    alarmSound.Alarm("准运卡办理失败");
                                    MessageBox.Show("准运卡办理成功,即将打印办理凭证", "天大天科", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                }

                                ClearAllText();
                            }
                            catch (Exception ex)
                            {
                                CommonMethod.MessageBox(ex.ToString(), MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            }
                        }
                        else if (strNavicertJudge == "0")
                        {
                            ClearAllText();
                            alarmSound.Alarm("该准运卡已发给其它车辆,不能再次办理");
                            MessageBox.Show("该准运卡已发给其它车辆,不能再次办理", "天大天科", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                        else if (strNavicertJudge == "3")
                        {
                            ClearAllText();
                            alarmSound.Alarm("该车辆已有准运卡,不能再为其办理一张新的准运卡,如需更换,请先将原准运卡挂失");
                            MessageBox.Show("该车辆已有准运卡,不能再为其办理一张新的准运卡,如需更换,请先将原准运卡挂失", "天大天科", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }

                    }
                }

            }
            else
            {
                alarmSound.Alarm("请刷准运卡");
            }
            txtNavicertCode.Focus();
        }