private void btnOK_Click(object sender, EventArgs e)
        {
            if (cmbCoalKind.SelectedValue.ToString() != "0" && cmbProType.SelectedValue.ToString() != "0" && txtCarNo.Text.Trim() != "")
            {

                #region 视频抓图
                //抓图信息
                byte[] byteFrontImage = null;
                byte[] byteBackImage = null;
                byte[] byteUpImage = null;
                byte[] byteRoomImage = null;

                //图片存储在SYS_FileSave的主键
                string strFrontImage = "";
                string strBackImage = "";
                string strUpImage = "";
                string strRoomImage = "";

                if (StaticParameter.IsVideo == "1")
                {
                    strFrontImage = Guid.NewGuid().ToString().Replace("-", "");
                    strBackImage = Guid.NewGuid().ToString().Replace("-", "");
                    strUpImage = Guid.NewGuid().ToString().Replace("-", "");
                    strRoomImage = Guid.NewGuid().ToString().Replace("-", "");

                    byteFrontImage = this.videoFrontImage.CapturePic();
                    byteBackImage = this.videoBackImage.CapturePic();
                    byteUpImage = this.videoUpImage.CapturePic();
                    byteRoomImage = this.videoRoomImage.CapturePic();
                }
                #endregion

                Model.TT_OutLoadWeight MOLW = new CoalTraffic.Model.TT_OutLoadWeight();
                BLL.TT_OutLoadWeight BOLW = new CoalTraffic.BLL.TT_OutLoadWeight();

                string strWeightCode = strRoomCode + DateTime.Now.ToString("yyyyMMddHHmmss");

                MOLW.Outweightcode = strWeightCode;
                MOLW.Currentweight = decimal.Parse(CommonMethod.ToDBC(txtHandDigital.Text.Trim()));
                MOLW.Emptyweight = decimal.Parse(CommonMethod.ToDBC(txtEmptyWeight.Text.Trim()));

                #region 根据是否是首站
                if (BIsFrist)
                {
                    MOLW.Otrafficcode = strWeightCode;
                    MOLW.Onetweight = MOLW.Currentweight-MOLW.Emptyweight;
                    MOLW.Overweight = 0.0m;
                }
                else
                {
                    MOLW.Otrafficcode = strTrafficCode;
                    MOLW.Onetweight = 0.0m;

                    decimal DOverWeight = 0.00m;

                    //获取这次运输中的最大值
                    string strsql = "select max(CurrentWeight) from TT_OutLoadWeight where OTrafficCode ='" + strTrafficCode + "'";
                    object OMCurrentWeight = DbHelperSQL.GetSingle(strsql);

                    #region 根据过磅类型判断重车重量
                    if (strCurrentMenu != "Person")
                    {
                        DOverWeight = decimal.Parse(lblDigital.Text.Trim()) - decimal.Parse(OMCurrentWeight.ToString());
                    }
                    else
                    {
                        #region 验证数据的正确性
                        if (txtHandDigital.Text.Trim() != "" && CommonMethod.IsDecimal(CommonMethod.ToDBC(txtHandDigital.Text.Trim())))
                        {
                            if (Convert.ToDecimal(CommonMethod.ToDBC(txtHandDigital.Text.Trim())) < Convert.ToDecimal(lblDigital.Text.Trim()))
                            {
                                alSound.Alarm("你输入的重车重量不能小于磅秤重量");
                                txtHandDigital.Text = "";
                                return;
                            }
                            else
                            {
                                DOverWeight = Convert.ToDecimal(CommonMethod.ToDBC(txtHandDigital.Text.Trim())) - Convert.ToDecimal(OMCurrentWeight.ToString());
                            }
                        }
                        else
                        {
                            alSound.Alarm("你输入的重车重量格式不对");
                            txtHandDigital.Text = "";
                            return;
                        }
                        #endregion
                    }
                    #endregion

                    decimal DLimitWeight = StaticParameter.WeightThreshold;

                    if (DOverWeight >= DLimitWeight)
                    {
                        MOLW.Overweight = DOverWeight;
                    }
                    else
                    {
                        MOLW.Overweight = 0.0m;
                    }
                }
                #endregion

                #region 实例化过境煤
                MOLW.Navicertcode = txtNavicert.Text.Trim();
                MOLW.Coalkindcode = cmbCoalKind.SelectedValue.ToString();
                MOLW.Coalkindname = cmbCoalKind.Text;
                MOLW.CollName = txtCollName.Text.Trim();
                MOLW.Carno = cmbProType.Text.Trim()+"-"+ txtCarNo.Text.Trim().ToUpper();

                MOLW.DriveLicense = txtDrivelicense.Text.Trim();
                MOLW.CarOwnerIDCard = txtCarOwnerIDCard.Text.Trim();
                MOLW.DriverPhone = txtPhoneNum.Text.Trim();

                MOLW.Taxtype = "";
                MOLW.Randomcode = CommonMethod.getRandom(4);

                MOLW.Frontimage = strFrontImage;
                MOLW.FrontImageContent = byteFrontImage;
                MOLW.Backimage = strBackImage;
                MOLW.BackImageContent = byteBackImage;
                MOLW.Upimage = strUpImage;
                MOLW.UpImageContent = byteUpImage;
                MOLW.Roomimage = strRoomImage;
                MOLW.RoomImageContent = byteRoomImage;

                MOLW.Roomcode = strRoomCode;
                MOLW.RoomName = strRoomName;
                MOLW.Operator = StaticParameter.UserName;
                MOLW.Weighttime = DateTime.Now;
                MOLW.Outtype = cmbOutType.SelectedValue.ToString();
                MOLW.Bangtype = "过境煤" + strBangType + "过磅";
                #endregion

                if (BOLW.Add(MOLW) != "")
                {
                    #region 数据上传
                    try
                    {
                        //MSMQClient MC = new MSMQClient();
                        StringBuilder sbInsert = new StringBuilder();
                        sbInsert.Append("PT_OutWeight '" + MOLW.Outweightcode + "','" + MOLW.Otrafficcode + "','" + MOLW.Navicertcode + "','" + MOLW.Coalkindcode + "',");
                        sbInsert.Append("'" + MOLW.Coalkindname + "','" + MOLW.Carno + "','" + MOLW.Currentweight + "','" + MOLW.Onetweight + "','" + MOLW.Overweight + "',");
                        sbInsert.Append("'" + MOLW.Taxtype + "','" + MOLW.Randomcode + "','" + MOLW.Frontimage + "','" + MOLW.Backimage + "','" + MOLW.Upimage + "',");
                        sbInsert.Append("'" + MOLW.Roomimage + "','" + MOLW.Roomcode + "','" + MOLW.RoomName + "','" + MOLW.Operator + "','" + MOLW.Weighttime + "',");
                        sbInsert.Append("'" + MOLW.Outtype + "','" + MOLW.Bangtype + "',null,null,");
                        sbInsert.Append("null,null,'"+MOLW.IsNormal+"','"+MOLW.SendUnits+"','"+MOLW.ToUnits+"'");
                        MC.AddNewSqlText(MC.AllStation + MC.Prefix + "TT_OutWeight" + MC.Prefix + MC.AddFlg + MC.Prefix + DateTime.Now.ToString("yyyy-MM-dd hh:mm;ss") + MC.Prefix + sbInsert.ToString());

                        //发送图片
                        string strIsSendPicToRoom = StaticParameter.IsSendPicToRoom;
                        int iSend = MC.ServerStation;
                        //是否发送磅房
                        if (strIsSendPicToRoom == "1")
                            iSend = MC.CheckStation;
                        string strPic = "";
                        if (MOLW.FrontImageContent != null)
                        {
                            strPic = iSend + MC.Prefix + "Sys_FileSave" + MC.Prefix + MC.AddFlg + MC.Prefix + DateTime.Now.ToString("yyyy-MM-dd hh:mm;ss") + MC.Prefix
                                + MOLW.Frontimage + ",jpg," + Convert.ToBase64String(MOLW.FrontImageContent, 0, MOLW.FrontImageContent.Length);
                            MC.AddNewSqlText(strPic);
                        }
                        if (MOLW.BackImageContent != null)
                        {
                            strPic = iSend + MC.Prefix + "Sys_FileSave" + MC.Prefix + MC.AddFlg + MC.Prefix + DateTime.Now.ToString("yyyy-MM-dd hh:mm;ss") + MC.Prefix
                                + MOLW.Backimage + ",jpg," + Convert.ToBase64String(MOLW.BackImageContent, 0, MOLW.BackImageContent.Length);
                            MC.AddNewSqlText(strPic);
                        }
                        if (MOLW.UpImageContent != null)
                        {
                            strPic = iSend + MC.Prefix + "Sys_FileSave" + MC.Prefix + MC.AddFlg + MC.Prefix + DateTime.Now.ToString("yyyy-MM-dd hh:mm;ss") + MC.Prefix
                                + MOLW.Upimage + ",jpg," + Convert.ToBase64String(MOLW.UpImageContent, 0, MOLW.UpImageContent.Length);
                            MC.AddNewSqlText(strPic);
                        }
                        if (MOLW.RoomImageContent != null)
                        {
                            strPic = iSend + MC.Prefix + "Sys_FileSave" + MC.Prefix + MC.AddFlg + MC.Prefix + DateTime.Now.ToString("yyyy-MM-dd hh:mm;ss") + MC.Prefix
                                + MOLW.Roomimage + ",jpg," + Convert.ToBase64String(MOLW.RoomImageContent, 0, MOLW.RoomImageContent.Length);
                            MC.AddNewSqlText(strPic);
                        }
                    }
                    catch
                    { }
                    #endregion

                    #region 根据是否是首站判断打印
                    if (BIsFrist)
                    {
                        alSound.Alarm("过境煤过磅成功,点击确定打印过境煤过磅单");
                        CommonMethod.MessageBox("过境煤过磅成功,点击确定打印过境煤过磅单!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);

                        Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
                        Type type = assembly.GetType("CoalTraffic.Report." + StaticParameter.ReportFile + "OutLoadWeightPrint");
                        object obj = Activator.CreateInstance(type, MOLW.Outweightcode, true); Form formToShow = (Form)obj; formToShow.ShowDialog();

                    }
                    else
                    {
                        if (MOLW.Overweight <= 0.0m)
                        {
                            alSound.Alarm("过境煤过磅成功");
                        }
                        else
                        {
                            alSound.Alarm("过境煤过磅成功,点击确定打印过境煤过磅单");
                            CommonMethod.MessageBox("过境煤过磅成功,点击确定打印过境煤过磅单!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);

                            Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
                            Type type = assembly.GetType("CoalTraffic.Report." + StaticParameter.ReportFile + "CheckOutLoadWeightPrint");
                            object obj = Activator.CreateInstance(type, MOLW.Outweightcode, true); Form formToShow = (Form)obj; formToShow.ShowDialog();

                        }
                    }
                    #endregion
                }
                else
                {
                    alSound.Alarm("该站的数据库异常");
                    InsertState = 0;

                    InsertBadReCordInfo("异常", MOLW.Carno, strRoomName + "的数据库异常");
                }

                ClearAllControl();
            }
            else
            {
                alSound.Alarm("请确保信息的完整性");
            }
        }
        private void btnOK_Click(object sender, EventArgs e)
        {
            string strError = string.Empty;
            if (strIsOut == "1")
            {

            }
            else
            {
                if (cmbCoalKind.SelectedText == "请选择煤种" || cmbCoalKind.SelectedIndex == 0)
                    strError += "请选择煤种!";
            }
            if (cmbProType.SelectedValue.ToString() == "0")
                strError += "请选择车牌所属地区!";
            if (txtCarNo.Text.Trim() == "")
                strError += "车牌号不能为空!";
            if (txtDrivelicense.Text.Trim() == "")
                strError += "行驶证号不能为空!";
            if (txtCarOwnerName.Text.Trim() == "")
                strError += "车主姓名不能为空!";
            if (txtPhone.Text.Trim() == "")
                strError += "联系电话不能为空";
            if (txtCarOwnerCardID.Text.Trim() == "")
            {
                strError += "车主身份证不能为空!";
            }
            else
            {
                if (txtCarOwnerCardID.Text.Trim().Length == 15 || txtCarOwnerCardID.Text.Trim().Length == 18)
                {
                    if (CommonMethod.isValidICCard(CommonMethod.ToDBC(txtCarOwnerCardID.Text.Trim())))
                    {

                    }
                    else
                    {
                        strError += "你输入的车主身份证号格式不正确!";

                    }
                }
                else
                {
                    strError += "你输入的车主身份证号长度不正确!";
                }
            }
            if (cmbCollName.SelectedIndex == 0)
                strError += "请选择煤炭来源!";
            if (cmbCustomers.SelectedIndex == 0)
                strError += "请选择煤炭去向!";
            if (bytWeightCode == null)
            {
                strError += "请扫描过磅单";
            }

            if (strError == string.Empty)
            {
                Model.TT_OutLoadWeight MOLW = new CoalTraffic.Model.TT_OutLoadWeight();
                BLL.TT_OutLoadWeight BOLW = new CoalTraffic.BLL.TT_OutLoadWeight();

                #region 视频抓图
                if (StaticParameter.IsVideo == "1")
                {
                    if (byteFrontImage == null && byteBackImage == null && byteUpImage == null && byteRoomImage == null)
                    {
                        strFrontImage = Guid.NewGuid().ToString().Replace("-", "");
                        strBackImage = Guid.NewGuid().ToString().Replace("-", "");
                        strUpImage = Guid.NewGuid().ToString().Replace("-", "");
                        strRoomImage = Guid.NewGuid().ToString().Replace("-", "");

                        byteFrontImage = this.videoFrontImage.CapturePic();
                        byteBackImage = this.videoBackImage.CapturePic();
                        byteUpImage = this.videoUpImage.CapturePic();
                        byteRoomImage = this.videoRoomImage.CapturePic();
                    }

                    MOLW.Frontimage = strFrontImage;
                    MOLW.FrontImageContent = byteFrontImage;
                    MOLW.Roomimage = strRoomImage;
                    MOLW.RoomImageContent = byteRoomImage;
                    MOLW.Upimage = strUpImage;
                    MOLW.UpImageContent = byteUpImage;
                    MOLW.Backimage = strBackImage;
                    MOLW.BackImageContent = byteBackImage;
                }
                else
                {
                    MOLW.Frontimage = "";
                    MOLW.FrontImageContent = null;
                    MOLW.Roomimage = "";
                    MOLW.RoomImageContent = null;
                    MOLW.Upimage = "";
                    MOLW.UpImageContent = null;
                    MOLW.Backimage = "";
                    MOLW.BackImageContent = null;
                }
                #endregion

                string strWeightCode = strRoomCode + DateTime.Now.ToString("yyyyMMddHHmmss");
                MOLW.Outweightcode = strWeightCode;
                MOLW.Currentweight = decimal.Parse(CommonMethod.ToDBC(txtHandDigital.Text.Trim()));

                if (strIsOut == "0")
                {
                    MOLW.Otrafficcode = strWeightCode;
                }
                else
                {
                    MOLW.Otrafficcode = strTrafficCode;
                }

                #region 实例化过境煤
                if (strIsOut == "0")
                {
                    MOLW.Coalkindname = cmbCoalKind.Text;
                }
                else
                {
                    MOLW.Coalkindname = strCoalKindName;
                }
                MOLW.CollName = cmbCollName.Text.Trim();
                MOLW.Carno = cmbProType.Text.Trim() + "-" + txtCarNo.Text.Trim().ToUpper();
                MOLW.Randomcode = CommonMethod.getRandom(4);

                MOLW.Frontimage = strFrontImage;
                MOLW.FrontImageContent = byteFrontImage;
                MOLW.Backimage = strBackImage;
                MOLW.BackImageContent = byteBackImage;
                MOLW.Upimage = strUpImage;
                MOLW.UpImageContent = byteUpImage;
                MOLW.Roomimage = strRoomImage;
                MOLW.RoomImageContent = byteRoomImage;

                MOLW.Roomcode = strRoomCode;
                MOLW.RoomName = strRoomName;
                MOLW.Operator = StaticParameter.UserName;
                MOLW.Weighttime = DateTime.Now;
                MOLW.Outtype = "1";
                MOLW.Bangtype = "过境煤" + strBangType + "过磅";
                MOLW.CarOwnerName = txtCarOwnerName.Text.Trim();
                MOLW.DriveLicense = txtDrivelicense.Text.Trim();
                MOLW.CarOwnerIDCard = txtCarOwnerCardID.Text.Trim();
                MOLW.DriverPhone = txtPhone.Text.Trim();
                MOLW.Customers = cmbCustomers.Text.Trim();

                if (StaticParameter.IsCarNo == "1")
                {
                    MOLW.CarNoImage = Guid.NewGuid().ToString().Replace("-", "");
                    MOLW.CarNoImageContent = bytGetCarNoInfo;
                }

                MOLW.OutWeightImage = Guid.NewGuid().ToString().Replace("-", "");
                MOLW.OutWeightImageContent = bytWeightCode;
                #endregion

                if (BOLW.Add(MOLW, "1") != "")
                {
                    #region 数据上传
                    try
                    {
                        //MSMQClient MC = new MSMQClient();
                        StringBuilder sbInsert = new StringBuilder();
                        sbInsert.Append("PT_OutWeightByFY '" + MOLW.Outweightcode + "','" + MOLW.Otrafficcode + "','" + MOLW.Coalkindname + "','" + MOLW.Carno + "',");
                        sbInsert.Append("'" + MOLW.Currentweight + "','" + MOLW.Randomcode + "','" + MOLW.Frontimage + "','" + MOLW.Backimage + "','" + MOLW.Upimage + "',");
                        sbInsert.Append("'" + MOLW.Roomimage + "','" + MOLW.Roomcode + "','" + MOLW.RoomName + "','" + MOLW.Operator + "','" + MOLW.Weighttime + "',");
                        sbInsert.Append("'" + MOLW.Outtype + "','" + MOLW.Bangtype + "',null,null,");
                        sbInsert.Append("null,null,'" + MOLW.CarOwnerName + "','" + MOLW.DriveLicense + "','" + MOLW.DriverPhone + "',");
                        sbInsert.Append("'" + MOLW.CarOwnerIDCard + "','" + MOLW.CollName + "','" + MOLW.CarNoImage + "','" + MOLW.OutWeightImage + "',");
                        sbInsert.Append("null,null,'" + MOLW.Customers + "'");

                        MC.AddNewSqlText(MC.AllStation + MC.Prefix + "TT_OutWeight" + MC.Prefix + MC.AddFlg + MC.Prefix + DateTime.Now.ToString("yyyy-MM-dd hh:mm;ss") + MC.Prefix + sbInsert.ToString());
                        //发送图片
                        string strIsSendPicToRoom = StaticParameter.IsSendPicToRoom;
                        int iSend = MC.ServerStation;
                        //是否发送磅房
                        if (strIsSendPicToRoom == "1")
                            iSend = MC.CheckStation;
                        string strPic = "";
                        if (MOLW.FrontImageContent != null)
                        {
                            strPic = iSend + MC.Prefix + "Sys_FileSave" + MC.Prefix + MC.AddFlg + MC.Prefix + DateTime.Now.ToString("yyyy-MM-dd hh:mm;ss") + MC.Prefix
                                + MOLW.Frontimage + ",jpg," + Convert.ToBase64String(MOLW.FrontImageContent, 0, MOLW.FrontImageContent.Length);
                            MC.AddNewSqlText(strPic);
                        }
                        if (MOLW.BackImageContent != null)
                        {
                            strPic = iSend + MC.Prefix + "Sys_FileSave" + MC.Prefix + MC.AddFlg + MC.Prefix + DateTime.Now.ToString("yyyy-MM-dd hh:mm;ss") + MC.Prefix
                                + MOLW.Backimage + ",jpg," + Convert.ToBase64String(MOLW.BackImageContent, 0, MOLW.BackImageContent.Length);
                            MC.AddNewSqlText(strPic);
                        }
                        if (MOLW.UpImageContent != null)
                        {
                            strPic = iSend + MC.Prefix + "Sys_FileSave" + MC.Prefix + MC.AddFlg + MC.Prefix + DateTime.Now.ToString("yyyy-MM-dd hh:mm;ss") + MC.Prefix
                                + MOLW.Upimage + ",jpg," + Convert.ToBase64String(MOLW.UpImageContent, 0, MOLW.UpImageContent.Length);
                            MC.AddNewSqlText(strPic);
                        }
                        if (MOLW.RoomImageContent != null)
                        {
                            strPic = iSend + MC.Prefix + "Sys_FileSave" + MC.Prefix + MC.AddFlg + MC.Prefix + DateTime.Now.ToString("yyyy-MM-dd hh:mm;ss") + MC.Prefix
                                + MOLW.Roomimage + ",jpg," + Convert.ToBase64String(MOLW.RoomImageContent, 0, MOLW.RoomImageContent.Length);
                            MC.AddNewSqlText(strPic);
                        }
                        if (MOLW.CarNoImageContent != null)
                        {
                            strPic = iSend + MC.Prefix + "Sys_FileSave" + MC.Prefix + MC.AddFlg + MC.Prefix + DateTime.Now.ToString("yyyy-MM-dd hh:mm;ss") + MC.Prefix
                                + MOLW.CarNoImage + ",jpg," + Convert.ToBase64String(MOLW.CarNoImageContent, 0, MOLW.CarNoImageContent.Length);
                            MC.AddNewSqlText(strPic);
                        }
                        if (MOLW.OutWeightImageContent != null)
                        {
                            strPic = iSend + MC.Prefix + "Sys_FileSave" + MC.Prefix + MC.AddFlg + MC.Prefix + DateTime.Now.ToString("yyyy-MM-dd hh:mm;ss") + MC.Prefix
                                + MOLW.OutWeightImage + ",jpg," + Convert.ToBase64String(MOLW.OutWeightImageContent, 0, MOLW.OutWeightImageContent.Length);
                            MC.AddNewSqlText(strPic);
                        }

                        //CoalTraffic.MessagingService.LocalWeightServiceClient Loalclient = new CoalTraffic.MessagingService.LocalWeightServiceClient();
                        //Loalclient.AddOutWeight(MOLW);
                    }
                    catch
                    { }
                    #endregion

                    alSound.Alarm("过境煤过磅成功");
                }
                else
                {
                    alSound.Alarm("该站的数据库异常");
                    InsertState = 0;

                    InsertBadReCordInfo("异常", MOLW.Carno, strRoomName + "的数据库异常");
                }

                ClearAllControl();
                ClearOwnerControl();
            }
            else
            {
                alSound.Alarm(strError);
            }
        }
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (cmbCoalKind.SelectedValue.ToString() != "0" && cmbProType.SelectedValue.ToString() != "0" && txtCarNo.Text.Trim() != "")
            {

                #region 视频抓图
                //抓图信息
                byte[] byteFrontImage = null;
                byte[] byteBackImage = null;
                byte[] byteUpImage = null;
                byte[] byteRoomImage = null;

                //图片存储在SYS_FileSave的主键
                string strFrontImage = "";
                string strBackImage = "";
                string strUpImage = "";
                string strRoomImage = "";

                if (StaticParameter.IsVideo == "1")
                {
                    strFrontImage = Guid.NewGuid().ToString().Replace("-", "");
                    strBackImage = Guid.NewGuid().ToString().Replace("-", "");
                    strUpImage = Guid.NewGuid().ToString().Replace("-", "");
                    strRoomImage = Guid.NewGuid().ToString().Replace("-", "");

                    byteFrontImage = this.videoFrontImage.CapturePic();
                    byteBackImage = this.videoBackImage.CapturePic();
                    byteUpImage = this.videoUpImage.CapturePic();
                    byteRoomImage = this.videoRoomImage.CapturePic();
                }
                #endregion

                Model.TT_OutLoadWeight MOLW = new CoalTraffic.Model.TT_OutLoadWeight();
                BLL.TT_OutLoadWeight BOLW = new CoalTraffic.BLL.TT_OutLoadWeight();

                string strWeightCode = strRoomCode + DateTime.Now.ToString("yyyyMMddHHmmss");

                MOLW.Outweightcode = strWeightCode;
                MOLW.Currentweight = decimal.Parse(CommonMethod.ToDBC(txtHandDigital.Text.Trim()));
                MOLW.Emptyweight = decimal.Parse(CommonMethod.ToDBC(txtEmptyWeight.Text.Trim()));

                #region 根据是否是首站
                if (BIsFrist)
                {
                    MOLW.Otrafficcode = strWeightCode;
                    MOLW.Onetweight = MOLW.Currentweight - MOLW.Emptyweight;
                    MOLW.Overweight = 0.0m;
                }
                else
                {
                    MOLW.Otrafficcode = strTrafficCode;
                    MOLW.Onetweight = 0.0m;

                    decimal DOverWeight = 0.00m;

                    //获取这次运输中的最大值
                    string strsql = "select max(CurrentWeight) from TT_OutLoadWeight where OTrafficCode ='" + strTrafficCode + "'";
                    object OMCurrentWeight = DbHelperSQL.GetSingle(strsql);

                    #region 根据过磅类型判断重车重量
                    if (strCurrentMenu != "Person")
                    {
                        DOverWeight = decimal.Parse(lblDigital.Text.Trim()) - decimal.Parse(OMCurrentWeight.ToString());
                    }
                    else
                    {
                        #region 验证数据的正确性
                        if (txtHandDigital.Text.Trim() != "" && CommonMethod.IsDecimal(CommonMethod.ToDBC(txtHandDigital.Text.Trim())))
                        {
                            if (Convert.ToDecimal(CommonMethod.ToDBC(txtHandDigital.Text.Trim())) < Convert.ToDecimal(lblDigital.Text.Trim()))
                            {
                                alSound.Alarm("你输入的重车重量不能小于磅秤重量");
                                txtHandDigital.Text = "";
                                return;
                            }
                            else
                            {
                                DOverWeight = Convert.ToDecimal(CommonMethod.ToDBC(txtHandDigital.Text.Trim())) - Convert.ToDecimal(OMCurrentWeight.ToString());
                            }
                        }
                        else
                        {
                            alSound.Alarm("你输入的重车重量格式不对");
                            txtHandDigital.Text = "";
                            return;
                        }
                        #endregion
                    }
                    #endregion

                    decimal DLimitWeight = StaticParameter.WeightThreshold;

                    if (DOverWeight >= DLimitWeight)
                    {
                        MOLW.Overweight = DOverWeight;
                    }
                    else
                    {
                        MOLW.Overweight = 0.0m;
                    }
                }
                #endregion

                #region 实例化过境煤
                MOLW.Navicertcode = txtNavicert.Text.Trim();
                MOLW.Coalkindcode = cmbCoalKind.SelectedValue.ToString();
                MOLW.Coalkindname = cmbCoalKind.Text;
                MOLW.CollName = txtCollName.Text.Trim();
                MOLW.Carno = cmbProType.Text.Trim() + "-" + txtCarNo.Text.Trim().ToUpper();

                MOLW.DriveLicense = txtDrivelicense.Text.Trim();
                MOLW.CarOwnerIDCard = txtCarOwnerIDCard.Text.Trim();
                MOLW.DriverPhone = txtPhoneNum.Text.Trim();

                MOLW.Taxtype = "";
                MOLW.Randomcode = CommonMethod.getRandom(4);

                MOLW.Frontimage = strFrontImage;
                MOLW.FrontImageContent = byteFrontImage;
                MOLW.Backimage = strBackImage;
                MOLW.BackImageContent = byteBackImage;
                MOLW.Upimage = strUpImage;
                MOLW.UpImageContent = byteUpImage;
                MOLW.Roomimage = strRoomImage;
                MOLW.RoomImageContent = byteRoomImage;

                MOLW.Roomcode = strRoomCode;
                MOLW.RoomName = strRoomName;
                MOLW.Operator = StaticParameter.UserName;
                MOLW.Weighttime = DateTime.Now;
                MOLW.Outtype = cmbOutType.SelectedValue.ToString();
                MOLW.Bangtype = "过境煤" + strBangType + "过磅";
                #endregion
                string isConnection = ini.IniReadValue("Connection", "isConnection");

                if (BOLW.Add(MOLW) != "")
                {
                    #region 当联网的时:插入同步sql语句到服务器,sql语句本地执行
                    if (isConnection == "0")
                    {
                        StringBuilder sbInsertLocal = new StringBuilder();
                        sbInsertLocal.Append("PT_OutWeight '" + MOLW.Outweightcode + "','" + MOLW.Otrafficcode + "','" + MOLW.Navicertcode + "','" + MOLW.Coalkindcode + "',");
                        sbInsertLocal.Append("'" + MOLW.Coalkindname + "','" + MOLW.Carno + "','" + MOLW.Currentweight + "','" + MOLW.Onetweight + "','" + MOLW.Overweight + "',");
                        sbInsertLocal.Append("'" + MOLW.Taxtype + "','" + MOLW.Randomcode + "','" + MOLW.Frontimage + "','" + MOLW.Backimage + "','" + MOLW.Upimage + "',");
                        sbInsertLocal.Append("'" + MOLW.Roomimage + "','" + MOLW.Roomcode + "','" + MOLW.RoomName + "','" + MOLW.Operator + "','" + MOLW.Weighttime + "',");
                        sbInsertLocal.Append("'" + MOLW.Outtype + "','" + MOLW.Bangtype + "',null,null,");
                        sbInsertLocal.Append("null,null,'" + MOLW.IsNormal + "','" + MOLW.SendUnits + "','" + MOLW.ToUnits + "'");

                        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 当断网时,添加重车过磅sql语句
                    StringBuilder sbInsert = new StringBuilder();
                    sbInsert.Append("PT_OutWeight '" + MOLW.Outweightcode + "','" + MOLW.Otrafficcode + "','" + MOLW.Navicertcode + "','" + MOLW.Coalkindcode + "',");
                    sbInsert.Append("'" + MOLW.Coalkindname + "','" + MOLW.Carno + "','" + MOLW.Currentweight + "','" + MOLW.Onetweight + "','" + MOLW.Overweight + "',");
                    sbInsert.Append("'" + MOLW.Taxtype + "','" + MOLW.Randomcode + "','" + MOLW.Frontimage + "','" + MOLW.Backimage + "','" + MOLW.Upimage + "',");
                    sbInsert.Append("'" + MOLW.Roomimage + "','" + MOLW.Roomcode + "','" + MOLW.RoomName + "','" + MOLW.Operator + "','" + MOLW.Weighttime + "',");
                    sbInsert.Append("'" + MOLW.Outtype + "','" + MOLW.Bangtype + "',null,null,");
                    sbInsert.Append("null,null,'" + MOLW.IsNormal + "','" + MOLW.SendUnits + "','" + MOLW.ToUnits + "'");
                    if (isConnection == "1")
                    {
                        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

                    #region 根据是否是首站判断打印
                    if (BIsFrist)
                    {
                        alSound.Alarm("过境煤过磅成功,点击确定打印过境煤过磅单");
                        CommonMethod.MessageBox("过境煤过磅成功,点击确定打印过境煤过磅单!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);

                        Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
                        Type type = assembly.GetType("CoalTraffic.Report." + StaticParameter.ReportFile + "OutLoadWeightPrint");
                        object obj = Activator.CreateInstance(type, MOLW.Outweightcode, true); Form formToShow = (Form)obj; formToShow.ShowDialog();

                    }
                    else
                    {
                        if (MOLW.Overweight <= 0.0m)
                        {
                            alSound.Alarm("过境煤过磅成功");
                        }
                        else
                        {
                            alSound.Alarm("过境煤过磅成功,点击确定打印过境煤过磅单");
                            CommonMethod.MessageBox("过境煤过磅成功,点击确定打印过境煤过磅单!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);

                            Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
                            Type type = assembly.GetType("CoalTraffic.Report." + StaticParameter.ReportFile + "CheckOutLoadWeightPrint");
                            object obj = Activator.CreateInstance(type, MOLW.Outweightcode, true); Form formToShow = (Form)obj; formToShow.ShowDialog();

                        }
                    }
                    #endregion
                }
                else
                {
                    if (isConnection == "0")
                    {
                        ini.IniWriteValue("Connection", "isConnection", CommonMethod.ToDBC("1"));
                        MessageBox.Show("系统与服务器断开连接,请联系中心机房!", "天大天科", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                        Application.ExitThread();
                        Application.Exit();
                    }
                    else
                    {
                        alSound.Alarm("数据连接字符串库异常");
                        MessageBox.Show("数据连接字符串库异常", "天大天科", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                        InsertState = 0;
                        InsertBadReCordInfo("异常", MOLW.Carno, strRoomName + "的数据库异常");
                    }
                }
                ClearAllControl();
            }
            else
            {
                alSound.Alarm("请确保信息的完整性");
            }
        }
        private void BangInOrOut()
        {
            if (txtNavicert.Text == "")
            {
                alSound.Alarm("请输入临时准运卡号");
                return;
            }

            //入境
            if (InRadBut.Checked)
            {
                if (CoalKindcmb.SelectedIndex == 0)
                {
                    alSound.Alarm("请选择煤种");
                    return;
                }
                if (OutBanCom.SelectedIndex == -1)
                {
                    alSound.Alarm("请选择出境磅房");
                    return;
                }
                if (InBanCom.SelectedIndex == OutBanCom.SelectedIndex)
                {
                    alSound.Alarm("入境和出境磅房相同请重新选择");
                    return;
                }

                if (cmbProType.SelectedIndex == 0)
                {
                    alSound.Alarm("请选择车牌号");
                    return;
                }

                if (txtCarNo.Text == "")
                {
                    alSound.Alarm("请输入车牌号");
                    txtCarNo.Focus();
                    return;
                }

                if (ComCarType.SelectedIndex == 0)
                {
                    alSound.Alarm("请选择车型");
                    return;
                }

                if (InWeightTxt.Text == "")
                {
                    alSound.Alarm("入境磅房重量为空");
                    return;
                }
                if (Convert.ToDouble(InWeightTxt.Text) == 0.00)
                {
                    alSound.Alarm("入境磅房重量为零");
                    return;
                }

            }

            //if (CoalKindcmb.SelectedValue.ToString() != "0" && cmbProType.SelectedValue.ToString() != "0" && txtCarNo.Text.Trim() != "")
            {
                int iCarNoLength;
                int.TryParse(ini.IniReadValue("CarNoSetting", "CarNoLength"), out iCarNoLength);
                //if (txtCarNo.Text.Trim().Length == iCarNoLength)
                {
                    #region 视频抓图

                    if (StaticParameter.IsVideo == "1")
                    {
                        if (byteFrontImage == null && byteBackImage == null && byteUpImage == null && byteRoomImage == null)
                        {
                            strFrontImage = Guid.NewGuid().ToString().Replace("-", "");
                            strBackImage = Guid.NewGuid().ToString().Replace("-", "");
                            strUpImage = Guid.NewGuid().ToString().Replace("-", "");
                            strRoomImage = Guid.NewGuid().ToString().Replace("-", "");

                            byteFrontImage = this.videoFrontImage.CapturePic();
                            byteBackImage = this.videoBackImage.CapturePic();
                            byteUpImage = this.videoUpImage.CapturePic();
                            byteRoomImage = this.videoRoomImage.CapturePic();
                        }
                    }
                    #endregion


                    Model.TT_OutLoadWeight MOLW = new CoalTraffic.Model.TT_OutLoadWeight();
                    BLL.TT_OutLoadWeight BOLW = new CoalTraffic.BLL.TT_OutLoadWeight();

                    string strWeightCode = strRoomCode + DateTime.Now.ToString("yyyyMMddHHmmss");
                    MOLW.Outweightcode = strWeightCode;
                    if (InRadBut.Checked)
                        MOLW.Otrafficcode = strWeightCode;
                    else
                        MOLW.Otrafficcode = LastOutWeightCode;
                    MOLW.Currentweight = decimal.Parse(CommonMethod.ToDBC(InWeightTxt.Text.Trim()));
                    MOLW.Emptyweight = 0.00m;
                    MOLW.BillWeight = 0.00m;

                    /*----
                    #region 根据是否是首站
                    if (BIsFrist)
                    {
                        MOLW.Otrafficcode = strWeightCode;
                        MOLW.Onetweight = MOLW.Currentweight - MOLW.Emptyweight;
                        MOLW.Overweight = 0.0m;
                    }
                    else
                    {
                        MOLW.Otrafficcode = strTrafficCode;
                        MOLW.Onetweight = 0.0m;

                        decimal DOverWeight = 0.00m;

                        //获取这次运输中的最大值
                        string strsql = "select max(CurrentWeight) from TT_OutLoadWeight where OTrafficCode ='" + strTrafficCode + "'";
                        object OMCurrentWeight = DbHelperSQL.GetSingle(strsql);

                        #region 根据过磅类型判断重车重量
                        if (strCurrentMenu != "Person")
                        {
                            DOverWeight = decimal.Parse(lblDigital.Text.Trim()) - decimal.Parse(OMCurrentWeight.ToString());
                        }
                        else
                        {
                            #region 验证数据的正确性
                            if (txtHandDigital.Text.Trim() != "" && CommonMethod.IsDecimal(CommonMethod.ToDBC(txtHandDigital.Text.Trim())))
                            {
                                if (Convert.ToDecimal(CommonMethod.ToDBC(txtHandDigital.Text.Trim())) < Convert.ToDecimal(lblDigital.Text.Trim()))
                                {
                                    alSound.Alarm("你输入的重车重量不能小于磅秤重量");
                                    txtHandDigital.Text = "";
                                    return;
                                }
                                else
                                {
                                    DOverWeight = Convert.ToDecimal(CommonMethod.ToDBC(txtHandDigital.Text.Trim())) - Convert.ToDecimal(OMCurrentWeight.ToString());
                                }
                            }
                            else
                            {
                                alSound.Alarm("你输入的重车重量格式不对");
                                txtHandDigital.Text = "";
                                return;
                            }
                            #endregion
                        }
                        #endregion

                        decimal DLimitWeight = StaticParameter.WeightThreshold;

                        if (DOverWeight >= DLimitWeight)
                        {
                            MOLW.Overweight = DOverWeight;
                        }
                        else
                        {
                            MOLW.Overweight = 0.0m;
                        }
                    }
                    #endregion
                    */
                    #region 实例化过境煤
                    MOLW.Navicertcode = txtNavicert.Text.Trim();
                    MOLW.Coalkindcode = CoalKindcmb.SelectedValue.ToString();
                    MOLW.Coalkindname = CoalKindcmb.Text;
                    MOLW.CollName = "";
                    MOLW.Carno = cmbProType.Text.Trim() + "-" + txtCarNo.Text.Trim().ToUpper();

                    MOLW.Taxtype = OutBanCom.SelectedValue.ToString();//作为出境磅房使用
                    MOLW.Randomcode = CommonMethod.getRandom(4);

                    MOLW.Frontimage = strFrontImage;
                    MOLW.FrontImageContent = byteFrontImage;
                    MOLW.Backimage = strBackImage;
                    MOLW.BackImageContent = byteBackImage;
                    MOLW.Upimage = strUpImage;
                    MOLW.UpImageContent = byteUpImage;
                    MOLW.Roomimage = strRoomImage;
                    MOLW.RoomImageContent = byteRoomImage;

                    if (InRadBut.Checked)
                    {
                        MOLW.Roomcode = strRoomCode;
                        MOLW.RoomName = strRoomName;
                    }
                    else
                    {
                        MOLW.Roomcode = InBanCom.SelectedValue.ToString();
                        MOLW.RoomName = InBanCom.Text;
                    }
                    MOLW.Operator = StaticParameter.UserName;
                    MOLW.Weighttime = DateTime.Now;
                    //MOLW.Outtype = cmbOutType.SelectedValue.ToString();
                    if (InRadBut.Checked)
                        MOLW.Outtype = "0";//入境
                    else
                        MOLW.Outtype = "2";//出境
                    MOLW.Bangtype = "过境煤" + strBangType + "过磅";
                    MOLW.IsTax = "1";

                    MOLW.DriveLicense = "";
                    MOLW.CarOwnerIDCard = "";
                    MOLW.DriverPhone = "";

                    MOLW.CarNoImage = "";
                    MOLW.CarNoImageContent = null;
                    MOLW.OutWeightImage = "";
                    MOLW.OutWeightImageContent = null;
                    MOLW.CarType = ComCarType.SelectedValue.ToString();
                    if (InRadBut.Checked)
                        MOLW.ExceptLeft = DateTime.Now.AddMinutes(dExcept);
                    else
                        MOLW.ExceptLeft = DateTime.Now;
                    #endregion

                    if (BOLW.Add(MOLW) != "")
                    {
                        #region 数据上传
                        try
                        {
                            //MSMQClient MC = new MSMQClient();
                            StringBuilder sbInsert = new StringBuilder();
                            sbInsert.Append("PT_OutWeight '" + MOLW.Outweightcode + "','" + MOLW.Otrafficcode + "','" + MOLW.Navicertcode + "','" + MOLW.Coalkindcode + "',");
                            sbInsert.Append("'" + MOLW.Coalkindname + "','" + MOLW.Carno + "','" + MOLW.Currentweight + "','" + MOLW.Onetweight + "','" + MOLW.Overweight + "',");
                            sbInsert.Append("'" + MOLW.Taxtype + "','" + MOLW.Randomcode + "','" + MOLW.Frontimage + "','" + MOLW.Backimage + "','" + MOLW.Upimage + "',");
                            sbInsert.Append("'" + MOLW.Roomimage + "','" + MOLW.Roomcode + "','" + MOLW.RoomName + "','" + MOLW.Operator + "','" + MOLW.Weighttime + "',");
                            sbInsert.Append("'" + MOLW.Outtype + "','" + MOLW.Bangtype + "',null,null,null,null,");
                            sbInsert.Append("null,null,null,null,null,'" + MOLW.IsTax + "',null,null,null,null,null,");
                            sbInsert.Append("'" + MOLW.IsNormal + "','" + MOLW.SendUnits + "','" + MOLW.ToUnits + "','" + MOLW.ExceptLeft.ToString() + "','" + MOLW.CarType + "'");
                            MC.AddNewSqlText(MC.AllStation + MC.Prefix + "TT_OutWeight" + MC.Prefix + MC.AddFlg + MC.Prefix + DateTime.Now.ToString("yyyy-MM-dd hh:mm;ss") + MC.Prefix + sbInsert.ToString());

                            //发送图片
                            string strIsSendPicToRoom = StaticParameter.IsSendPicToRoom;
                            int iSend = MC.ServerStation;
                            //是否发送磅房
                            if (strIsSendPicToRoom == "1")
                                iSend = MC.CheckStation;
                            string strPic = "";
                            if (MOLW.FrontImageContent != null)
                            {
                                strPic = iSend + MC.Prefix + "Sys_FileSave" + MC.Prefix + MC.AddFlg + MC.Prefix + DateTime.Now.ToString("yyyy-MM-dd hh:mm;ss") + MC.Prefix
                                    + MOLW.Frontimage + ",jpg," + Convert.ToBase64String(MOLW.FrontImageContent, 0, MOLW.FrontImageContent.Length);
                                MC.AddNewSqlText(strPic);
                            }
                            if (MOLW.BackImageContent != null)
                            {
                                strPic = iSend + MC.Prefix + "Sys_FileSave" + MC.Prefix + MC.AddFlg + MC.Prefix + DateTime.Now.ToString("yyyy-MM-dd hh:mm;ss") + MC.Prefix
                                    + MOLW.Backimage + ",jpg," + Convert.ToBase64String(MOLW.BackImageContent, 0, MOLW.BackImageContent.Length);
                                MC.AddNewSqlText(strPic);
                            }
                            if (MOLW.UpImageContent != null)
                            {
                                strPic = iSend + MC.Prefix + "Sys_FileSave" + MC.Prefix + MC.AddFlg + MC.Prefix + DateTime.Now.ToString("yyyy-MM-dd hh:mm;ss") + MC.Prefix
                                    + MOLW.Upimage + ",jpg," + Convert.ToBase64String(MOLW.UpImageContent, 0, MOLW.UpImageContent.Length);
                                MC.AddNewSqlText(strPic);
                            }
                            if (MOLW.RoomImageContent != null)
                            {
                                strPic = iSend + MC.Prefix + "Sys_FileSave" + MC.Prefix + MC.AddFlg + MC.Prefix + DateTime.Now.ToString("yyyy-MM-dd hh:mm;ss") + MC.Prefix
                                    + MOLW.Roomimage + ",jpg," + Convert.ToBase64String(MOLW.RoomImageContent, 0, MOLW.RoomImageContent.Length);
                                MC.AddNewSqlText(strPic);
                            }
                            //CoalTraffic.MessagingService.LocalWeightServiceClient Loalclient = new CoalTraffic.MessagingService.LocalWeightServiceClient();
                            //Loalclient.AddOutWeight(MOLW);
                        }
                        catch
                        { }
                        #endregion
                        #region 根据是否是首站判断打印
                        if (InRadBut.Checked)
                        {
                            //if (BIsFrist)
                            //{
                            alSound.Alarm("过境煤过磅成功,点击确定打印过境煤过磅单");
                            CommonMethod.MessageBox("过境煤过磅成功,点击确定打印过境煤过磅单!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                            Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
                            Type type = assembly.GetType("CoalTraffic.Report." + StaticParameter.ReportFile + "OutLoadWeightPrint");
                            object obj = Activator.CreateInstance(type, strRoomName, MOLW.Outweightcode, MOLW.Carno, MOLW.Navicertcode, ComCarType.Text,
                                   CoalKindcmb.Text, "入境", InWeightTxt.Text, "", OutBanCom.Text, MOLW.ExceptLeft.ToString(),
                                   MOLW.Randomcode.ToString(), MOLW.Weighttime.ToString(), MOLW.Operator, true);
                            Form formToShow = (Form)obj;
                            formToShow.ShowDialog();
                        }
                        else
                            alSound.Alarm("出境成功");
                        //}
                        /*-----------
                        else
                        {
                            if (MOLW.Overweight <= 0.0m)
                            {
                                alSound.Alarm("过境煤过磅成功");
                            }
                            else
                            {
                                alSound.Alarm("过境煤过磅成功,点击确定打印过境煤过磅单");
                                CommonMethod.MessageBox("过境煤过磅成功,点击确定打印过境煤过磅单!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);

                                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 + "CheckOutLoadWeightPrint");
                                object obj = Activator.CreateInstance(type, MOLW.Outweightcode, true); Form formToShow = (Form)obj; formToShow.ShowDialog();

                            }
                        }
                         */
                        #endregion
                    }
                    else
                    {
                        alSound.Alarm("该站的数据库异常");
                        InsertState = 0;
                        InsertBadReCordInfo("异常", MOLW.Carno, strRoomName + "的数据库异常");
                    }

                    ClearAllControl();
                }
                //else
                //{
                //    alSound.Alarm("车牌号输入长度不正确");
                //}
            }
            //else
            //{
            //    alSound.Alarm("请确保信息的完整性");
            //}
        }
        /// <summary>
        /// 确定方法
        /// </summary>
        private void BangInOrOut()
        {
            if (txtNavicert.Text == "")
            {
                alSound.Alarm("请输入临时准运卡号");
                MessageBox.Show("请输入临时准运卡号", "天大天科", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }
            #region 入境非空判断

            //入境
            if (InRadBut.Checked)
            {
                if (CoalKindcmb.SelectedIndex == 0)
                {
                    alSound.Alarm("请选择煤种");
                    return;
                }
                if (OutBanCom.SelectedIndex == -1)
                {
                    alSound.Alarm("请选择出境磅房");
                    return;
                }
                if (InBanCom.SelectedIndex == OutBanCom.SelectedIndex)
                {
                    alSound.Alarm("入境和出境磅房相同请重新选择");
                    return;
                }

                if (cmbProType.SelectedIndex == 0)
                {
                    alSound.Alarm("请选择车牌号");
                    return;
                }

                if (txtCarNo.Text == "")
                {
                    alSound.Alarm("请输入车牌号");
                    txtCarNo.Focus();
                    return;
                }

                if (ComCarType.SelectedIndex == 0)
                {
                    alSound.Alarm("请选择车型");
                    return;
                }

                if (InWeightTxt.Text == "")
                {
                    alSound.Alarm("入境磅房重量为空");
                    return;
                }
                if (Convert.ToDouble(InWeightTxt.Text) == 0.00)
                {
                    alSound.Alarm("入境磅房重量为零");
                    return;
                }

            }
            #endregion

            //if (CoalKindcmb.SelectedValue.ToString() != "0" && cmbProType.SelectedValue.ToString() != "0" && txtCarNo.Text.Trim() != "")
            {
                int iCarNoLength;
                int.TryParse(ini.IniReadValue("CarNoSetting", "CarNoLength"), out iCarNoLength);
                //if (txtCarNo.Text.Trim().Length == iCarNoLength)
                {
                    #region 视频抓图

                    if (StaticParameter.IsVideo == "1")
                    {
                        if (byteFrontImage == null && byteBackImage == null && byteUpImage == null && byteRoomImage == null)
                        {
                            strFrontImage = Guid.NewGuid().ToString().Replace("-", "");
                            strBackImage = Guid.NewGuid().ToString().Replace("-", "");
                            strUpImage = Guid.NewGuid().ToString().Replace("-", "");
                            strRoomImage = Guid.NewGuid().ToString().Replace("-", "");

                            byteFrontImage = this.videoFrontImage.CapturePic();
                            byteBackImage = this.videoBackImage.CapturePic();
                            byteUpImage = this.videoUpImage.CapturePic();
                            byteRoomImage = this.videoRoomImage.CapturePic();
                        }
                    }
                    #endregion

                    #region 定义变量
                    Model.TT_OutLoadWeight MOLW = new CoalTraffic.Model.TT_OutLoadWeight();
                    BLL.TT_OutLoadWeight BOLW = new CoalTraffic.BLL.TT_OutLoadWeight();

                    string strWeightCode = strRoomCode + DateTime.Now.ToString("yyyyMMddHHmmss");
                    MOLW.Outweightcode = strWeightCode;
                    if (InRadBut.Checked)
                        MOLW.Otrafficcode = strWeightCode;
                    else
                        MOLW.Otrafficcode = LastOutWeightCode;
                    MOLW.Currentweight = decimal.Parse(CommonMethod.ToDBC(InWeightTxt.Text.Trim()));
                    MOLW.Emptyweight = 0.00m;
                    MOLW.BillWeight = 0.00m;
                    #endregion

                    #region 实例化过境煤
                    MOLW.Navicertcode = txtNavicert.Text.Trim();
                    MOLW.Coalkindcode = CoalKindcmb.SelectedValue.ToString();
                    MOLW.Coalkindname = CoalKindcmb.Text;
                    MOLW.CollName = "";
                    MOLW.Carno = cmbProType.Text.Trim() + "-" + txtCarNo.Text.Trim().ToUpper();

                    MOLW.Taxtype = OutBanCom.SelectedValue.ToString();//作为出境磅房使用
                    MOLW.Randomcode = CommonMethod.getRandom(4);

                    MOLW.Frontimage = strFrontImage;
                    MOLW.FrontImageContent = byteFrontImage;
                    MOLW.Backimage = strBackImage;
                    MOLW.BackImageContent = byteBackImage;
                    MOLW.Upimage = strUpImage;
                    MOLW.UpImageContent = byteUpImage;
                    MOLW.Roomimage = strRoomImage;
                    MOLW.RoomImageContent = byteRoomImage;

                    if (InRadBut.Checked)
                    {
                        MOLW.Roomcode = strRoomCode;
                        MOLW.RoomName = strRoomName;
                    }
                    else
                    {
                        MOLW.Roomcode = InBanCom.SelectedValue.ToString();
                        MOLW.RoomName = InBanCom.Text;
                    }
                    MOLW.Operator = StaticParameter.UserName;
                    MOLW.Weighttime = DateTime.Now;
                    //MOLW.Outtype = cmbOutType.SelectedValue.ToString();
                    if (InRadBut.Checked)
                        MOLW.Outtype = "0";//入境
                    else
                        MOLW.Outtype = "2";//出境
                    MOLW.Bangtype = "过境煤" + strBangType + "过磅";
                    MOLW.IsTax = "1";

                    MOLW.DriveLicense = "";
                    MOLW.CarOwnerIDCard = "";
                    MOLW.DriverPhone = "";

                    MOLW.CarNoImage = "";
                    MOLW.CarNoImageContent = null;
                    MOLW.OutWeightImage = "";
                    MOLW.OutWeightImageContent = null;
                    MOLW.CarType = ComCarType.SelectedValue.ToString();
                    if (InRadBut.Checked)
                        MOLW.ExceptLeft = DateTime.Now.AddMinutes(dExcept);
                    else
                        MOLW.ExceptLeft = DateTime.Now;
                    #endregion
                    string isConnection = ini.IniReadValue("Connection", "isConnection");
                    if (BOLW.Add(MOLW) != "")
                    {

                        #region 当联网的时:插入同步sql语句到服务器,sql语句本地执行
                        if (isConnection == "0")
                        {
                            StringBuilder sbInsertLocal = new StringBuilder();
                            sbInsertLocal.Append("PT_OutWeight '" + MOLW.Outweightcode + "','" + MOLW.Otrafficcode + "','" + MOLW.Navicertcode + "','" + MOLW.Coalkindcode + "',");
                            sbInsertLocal.Append("'" + MOLW.Coalkindname + "','" + MOLW.Carno + "','" + MOLW.Currentweight + "','" + MOLW.Onetweight + "','" + MOLW.Overweight + "',");
                            sbInsertLocal.Append("'" + MOLW.Taxtype + "','" + MOLW.Randomcode + "','" + MOLW.Frontimage + "','" + MOLW.Backimage + "','" + MOLW.Upimage + "',");
                            sbInsertLocal.Append("'" + MOLW.Roomimage + "','" + MOLW.Roomcode + "','" + MOLW.RoomName + "','" + MOLW.Operator + "','" + MOLW.Weighttime + "',");
                            sbInsertLocal.Append("'" + MOLW.Outtype + "','" + MOLW.Bangtype + "',null,null,");
                            sbInsertLocal.Append("null,null,'" + MOLW.IsNormal + "','" + MOLW.SendUnits + "','" + MOLW.ToUnits + "'");
                            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 当断网时,添加重车过磅sql语句

                        if (isConnection == "1")
                        {
                            StringBuilder sbInsert = new StringBuilder();
                            sbInsert.Append("PT_OutWeight '" + MOLW.Outweightcode + "','" + MOLW.Otrafficcode + "','" + MOLW.Navicertcode + "','" + MOLW.Coalkindcode + "',");
                            sbInsert.Append("'" + MOLW.Coalkindname + "','" + MOLW.Carno + "','" + MOLW.Currentweight + "','" + MOLW.Onetweight + "','" + MOLW.Overweight + "',");
                            sbInsert.Append("'" + MOLW.Taxtype + "','" + MOLW.Randomcode + "','" + MOLW.Frontimage + "','" + MOLW.Backimage + "','" + MOLW.Upimage + "',");
                            sbInsert.Append("'" + MOLW.Roomimage + "','" + MOLW.Roomcode + "','" + MOLW.RoomName + "','" + MOLW.Operator + "','" + MOLW.Weighttime + "',");
                            sbInsert.Append("'" + MOLW.Outtype + "','" + MOLW.Bangtype + "',null,null,");
                            sbInsert.Append("null,null,'" + MOLW.IsNormal + "','" + MOLW.SendUnits + "','" + MOLW.ToUnits + "'");
                            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

                        #region 根据是否是首站判断打印
                        if (InRadBut.Checked)
                        {
                            //if (BIsFrist)
                            //{
                            alSound.Alarm("过境煤过磅成功,点击确定打印过境煤过磅单");
                            CommonMethod.MessageBox("过境煤过磅成功,点击确定打印过境煤过磅单!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);

                            #region 打印相关
                            Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
                            Type type = assembly.GetType("CoalTraffic.Report." + StaticParameter.ReportFile + "OutLoadWeightPrint");
                            object obj = Activator.CreateInstance(type, strRoomName, MOLW.Outweightcode, MOLW.Carno, MOLW.Navicertcode, ComCarType.Text,
                                   CoalKindcmb.Text, "入境", InWeightTxt.Text, "", OutBanCom.Text, MOLW.ExceptLeft.ToString(),
                                   MOLW.Randomcode.ToString(), MOLW.Weighttime.ToString(), MOLW.Operator, true);
                            Form formToShow = (Form)obj;
                            formToShow.ShowDialog();
                            #endregion
                        }
                        else
                            alSound.Alarm("出境成功");
                        //}
                        /*-----------
                        else
                        {
                            if (MOLW.Overweight <= 0.0m)
                            {
                                alSound.Alarm("过境煤过磅成功");
                            }
                            else
                            {
                                alSound.Alarm("过境煤过磅成功,点击确定打印过境煤过磅单");
                                CommonMethod.MessageBox("过境煤过磅成功,点击确定打印过境煤过磅单!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);

                                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 + "CheckOutLoadWeightPrint");
                                object obj = Activator.CreateInstance(type, MOLW.Outweightcode, true); Form formToShow = (Form)obj; formToShow.ShowDialog();

                            }
                        }
                         */
                        #endregion
                    }
                    else
                    {
                        if (isConnection == "0")
                        {
                            ini.IniWriteValue("Connection", "isConnection", CommonMethod.ToDBC("1"));
                            MessageBox.Show("系统与服务器断开连接,请联系中心机房!", "天大天科", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                            Application.ExitThread();
                            Application.Exit();
                        }
                        else
                        {
                            alSound.Alarm("数据连接字符串库异常");
                            MessageBox.Show("数据连接字符串库异常", "天大天科", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                            InsertState = 0;
                            InsertBadReCordInfo("异常", MOLW.Carno, strRoomName + "的数据库异常");
                        }
                    }

                    ClearAllControl();
                }
                //else
                //{
                //    alSound.Alarm("车牌号输入长度不正确");
                //}
            }
            //else
            //{
            //    alSound.Alarm("请确保信息的完整性");
            //}
        }
        private void BtnSave_Click(object sender, EventArgs e)
        {
            #region 数据完整性验证
            string strError = string.Empty;
            if (cmbCarType.SelectedValue.ToString() == "")
            {
                strError += "省份名称不能为空!";
            }
            if (txtCarNo.Text.Trim() == "")
                strError += "车牌号不能为空!";
            if (txtCarOwnerCardID.Text.Trim() == "")
            {
                strError += "车主身份证不能为空!";
            }
            else
            {
                if (txtCarOwnerCardID.Text.Trim().Length == 15 || txtCarOwnerCardID.Text.Trim().Length == 18)
                {
                    if (CommonMethod.isValidICCard(CommonMethod.ToDBC(txtCarOwnerCardID.Text.Trim())))
                    {

                    }
                    else
                    {
                        strError += "你输入的车主身份证号格式不正确!";

                    }
                }
                else
                {
                    strError += "你输入的车主身份证号长度不正确!";
                }
            }
            if (txtPhone.Text.Trim() == "")
                strError += "联系电话不能为空!";
            if (txtEmptyWeight.Text.Trim() != "")
            {
                if (!CommonMethod.IsNumber(CommonMethod.ToDBC(txtEmptyWeight.Text.Trim())) && !CommonMethod.IsDecimal(CommonMethod.ToDBC(txtEmptyWeight.Text.Trim())))
                {
                    strError += "空车重量必须为正整数或小数!";
                }
                else
                {
                    if (Convert.ToDecimal(CommonMethod.ToDBC(txtEmptyWeight.Text.Trim())) > 50m)
                    {
                        strError += "空车重量异常!";
                    }
                }
            }
            else
            {
                strError += "空车重量不能为空!";
            }
            if (txtDriveLinse.Text.Trim() == "")
                strError += "行驶证号不能为空!";
            if (txtCollName.Text.Trim() == "")
                strError += "煤矿名称不能为空!";
            if (cmbCoalKind.SelectedIndex == 0)
            {
                strError += "煤种名称不能为空!";
            }
            if (txtLoadWeight.Text.Trim() != "")
            {
                if (!CommonMethod.IsNumber(CommonMethod.ToDBC(txtLoadWeight.Text.Trim())) && !CommonMethod.IsDecimal(CommonMethod.ToDBC(txtLoadWeight.Text.Trim())))
                {
                    strError += "重车重量必须为正整数或小数!";
                }

            }
            else
            {
                strError += "重车重量不能为空!";
            }
            #endregion

            if (strError == string.Empty)
            {
                Model.TT_OutLoadWeight MOLW = new CoalTraffic.Model.TT_OutLoadWeight();
                BLL.TT_OutLoadWeight BOLW = new CoalTraffic.BLL.TT_OutLoadWeight();

                string strWeightCode = strRoomCode + DateTime.Now.ToString("yyyyMMddHHmmss");
                MOLW.Outweightcode = strWeightCode;

                MOLW.Currentweight = Convert.ToDecimal(txtLoadWeight.Text.Trim());
                MOLW.Otrafficcode = strWeightCode;
                MOLW.Emptyweight = Convert.ToDecimal(txtEmptyWeight.Text.Trim());
                MOLW.BillWeight = 0.00m;
                MOLW.Onetweight = MOLW.Currentweight - MOLW.Emptyweight;
                MOLW.Overweight = 0.0m;

                #region 实例化过境煤
                MOLW.Navicertcode = "";
                MOLW.Coalkindcode = cmbCoalKind.SelectedValue.ToString();
                MOLW.Coalkindname = cmbCoalKind.Text;
                MOLW.CollName = txtCollName.Text.Trim();
                MOLW.Carno = cmbCarType.Text.Trim() + "-" + txtCarNo.Text.Trim().ToUpper();

                MOLW.Taxtype = "";
                MOLW.Randomcode = CommonMethod.getRandom(4);

                MOLW.Frontimage = "";
                MOLW.FrontImageContent = null;
                MOLW.Backimage = "";
                MOLW.BackImageContent = null;
                MOLW.Upimage = "";
                MOLW.UpImageContent = null;
                MOLW.Roomimage = "";
                MOLW.RoomImageContent = null;

                MOLW.Roomcode = strRoomCode;
                MOLW.RoomName = strRoomName;
                MOLW.Operator = StaticParameter.UserName;
                MOLW.Weighttime = DateTime.Now;
                MOLW.Outtype = "2";
                MOLW.Bangtype = "过境煤自动过磅";
                MOLW.IsTax = "0";

                MOLW.DriveLicense = CommonMethod.ToDBC(txtDriveLinse.Text.Trim());
                MOLW.CarOwnerIDCard = CommonMethod.ToDBC(txtCarOwnerCardID.Text.Trim());
                MOLW.DriverPhone = CommonMethod.ToDBC(txtPhone.Text.Trim());

                MOLW.CarNoImage = "";
                MOLW.CarNoImageContent = null;
                MOLW.OutWeightImage = "";
                MOLW.OutWeightImageContent = null;
                #endregion

                if (BOLW.Add(MOLW) != "")
                {
                    #region 数据上传
                    try
                    {
                        //MSMQClient MC = new MSMQClient();
                        StringBuilder sbInsert = new StringBuilder();
                        sbInsert.Append("PT_OutWeight '" + MOLW.Outweightcode + "','" + MOLW.Otrafficcode + "','" + MOLW.Navicertcode + "','" + MOLW.Coalkindcode + "',");
                        sbInsert.Append("'" + MOLW.Coalkindname + "','" + MOLW.Carno + "','" + MOLW.Currentweight + "','" + MOLW.Onetweight + "','" + MOLW.Overweight + "',");
                        sbInsert.Append("'" + MOLW.Taxtype + "','" + MOLW.Randomcode + "','" + MOLW.Frontimage + "','" + MOLW.Backimage + "','" + MOLW.Upimage + "',");
                        sbInsert.Append("'" + MOLW.Roomimage + "','" + MOLW.Roomcode + "','" + MOLW.RoomName + "','" + MOLW.Operator + "','" + MOLW.Weighttime + "',");
                        sbInsert.Append("'" + MOLW.Outtype + "','" + MOLW.Bangtype + "',null,null,");
                        sbInsert.Append("null,null,'" + MOLW.IsNormal + "','" + MOLW.SendUnits + "','" + MOLW.ToUnits + "'");
                        MC.AddNewSqlText(MC.AllStation + MC.Prefix + "TT_OutWeight" + MC.Prefix + MC.AddFlg + MC.Prefix + DateTime.Now.ToString("yyyy-MM-dd hh:mm;ss") + MC.Prefix + sbInsert.ToString());

                        //发送图片
                        string strIsSendPicToRoom = StaticParameter.IsSendPicToRoom;
                        int iSend = MC.ServerStation;
                        //是否发送磅房
                        if (strIsSendPicToRoom == "1")
                            iSend = MC.CheckStation;
                        string strPic = "";
                        if (MOLW.FrontImageContent != null)
                        {
                            strPic = iSend + MC.Prefix + "Sys_FileSave" + MC.Prefix + MC.AddFlg + MC.Prefix + DateTime.Now.ToString("yyyy-MM-dd hh:mm;ss") + MC.Prefix
                                + MOLW.Frontimage + ",jpg," + Convert.ToBase64String(MOLW.FrontImageContent, 0, MOLW.FrontImageContent.Length);
                            MC.AddNewSqlText(strPic);
                        }
                        if (MOLW.BackImageContent != null)
                        {
                            strPic = iSend + MC.Prefix + "Sys_FileSave" + MC.Prefix + MC.AddFlg + MC.Prefix + DateTime.Now.ToString("yyyy-MM-dd hh:mm;ss") + MC.Prefix
                                + MOLW.Backimage + ",jpg," + Convert.ToBase64String(MOLW.BackImageContent, 0, MOLW.BackImageContent.Length);
                            MC.AddNewSqlText(strPic);
                        }
                        if (MOLW.UpImageContent != null)
                        {
                            strPic = iSend + MC.Prefix + "Sys_FileSave" + MC.Prefix + MC.AddFlg + MC.Prefix + DateTime.Now.ToString("yyyy-MM-dd hh:mm;ss") + MC.Prefix
                                + MOLW.Upimage + ",jpg," + Convert.ToBase64String(MOLW.UpImageContent, 0, MOLW.UpImageContent.Length);
                            MC.AddNewSqlText(strPic);
                        }
                        if (MOLW.RoomImageContent != null)
                        {
                            strPic = iSend + MC.Prefix + "Sys_FileSave" + MC.Prefix + MC.AddFlg + MC.Prefix + DateTime.Now.ToString("yyyy-MM-dd hh:mm;ss") + MC.Prefix
                                + MOLW.Roomimage + ",jpg," + Convert.ToBase64String(MOLW.RoomImageContent, 0, MOLW.RoomImageContent.Length);
                            MC.AddNewSqlText(strPic);
                        }
                        //CoalTraffic.MessagingService.LocalWeightServiceClient Loalclient = new CoalTraffic.MessagingService.LocalWeightServiceClient();
                        //Loalclient.AddOutWeight(MOLW);
                    }
                    catch
                    { }
                    #endregion

                    alSound.Alarm("过境煤过磅成功");

                    this.ClearTextBoxText(this);
                    this.ClearLabelText();
                }
                else
                {
                    alSound.Alarm("该站的数据库异常");
                    InsertState = 0;

                    InsertBadReCordInfo("异常", MOLW.Carno, strRoomName + "的数据库异常");
                }
            }
            else
            {
                alSound.Alarm(strError);
            }
        }