Esempio n. 1
0
        public static string connectionString()
        {
            //string connection = "";// System.Configuration.ConfigurationManager.AppSettings["ConnectionString"];
            //if (connection != "")
            //{
            //    return connection;
            //}
            //else
            //{
            //    RWini ini = new RWini();
            //    string strRIP = ini.IniReadValue("Connection", "LServer");
            //    return "User ID=sa;pwd=" + CommonMethod.DecryptDES(ini.IniReadValue("Connection", "LPsw"), "EncryDes").ToLower() + ";Data Source=" + ini.IniReadValue("Connection", "LServer") + ";Initial Catalog=" + ini.IniReadValue("Connection", "LDataBase") + ";";
            //}

            string connection = System.Configuration.ConfigurationManager.AppSettings["ConnectionString"];
            if (connection != "")
            {
                return connection;
            }
            else
            {
                RWini ini = new RWini();
                //string strRIP = ini.IniReadValue("Connection", "LServer");
                return "User ID=sa;pwd=" + CommonMethod.DecryptDES(ini.IniReadValue("Connection", "LPsw"), "EncryDes").ToLower() + ";Data Source=" + ini.IniReadValue("Connection", "LServer") + ";Initial Catalog=" + ini.IniReadValue("Connection", "LDataBase") + ";";
            }
        }
        public override void Install(IDictionary stateSaver)
        {
            try
            {
                base.Install(stateSaver);

                string dir = this.Context.Parameters["dir"];
                Directory.SetCurrentDirectory(dir);
                string formType = this.Context.Parameters["formType"]; //类型1为计量站,2为验票站
                string systemName = this.Context.Parameters["systemName"]; //系统名称
                string customerName = this.Context.Parameters["customerName"];//打印报表时前面的名称
                string taxObject = this.Context.Parameters["tax"];//规费计算
                if (taxObject != "2")
                {
                    taxObject = "1";
                }
                string ip = this.Context.Parameters["ip"];//消息队列服务器IP
                RWini rw = new RWini();

                rw.inipath = dir + "\\Settings.ini";
                bool r = rw.ExistINIFile();
                rw.IniWriteValue("SysInfo", "FormType",formType);
                rw.IniWriteValue("SysInfo", "SystemName",systemName);
                rw.IniWriteValue("SysInfo", "CustomerName",customerName);

                //System.Diagnostics.Debugger.Launch();

                XmlDocument doc = new XmlDocument();
                doc.Load(dir + "\\CoalTraffic.exe.config");
                foreach (System.Xml.XmlNode node in doc["configuration"]["appSettings"])
                {
                    if (node.Name == "add")
                    {
                        if (node.Attributes.GetNamedItem("key").Value == "TaxObject")
                        {
                            node.Attributes.GetNamedItem("value").Value = taxObject;
                        }
                    }
                }
                foreach (System.Xml.XmlNode node in doc["configuration"]["system.serviceModel"]["client"])
                {
                    if (node.Name == "endpoint")
                    {
                        node.Attributes.GetNamedItem("address").Value = "net.msmq://" + ip + "/private/CTOSMessagingQueue";
                    }
                }
                doc.Save(dir + "\\CoalTraffic.exe.config");
            }
            catch(Exception ex)
            {
                Log.WriteLog(ex);
            }
        }
        private void MarkedCardSearch_Load(object sender, EventArgs e)
        {
            #region 绑定相关控件
            strRoomCode = new RWini().IniReadValue("RoomSetting", "RoomCode");

            //CommonMethod.ComboxBind(this.cmbRoom, "TT_Room", "RoomName", "RoomCode", "IsForbid='0'", "RoomName", "请选择验票站", "-1");
            if (strRoomCode != "")
            {
                this.cmbRoom.SelectedValue = strRoomCode;
            }
            #region 是否锁定选择计量站
            if (ini.IniReadValue("SysInfo", "FormType") == "1")
            {
                if (StaticParameter.UserCode != "0")
                {
                    this.cmbRoom.Enabled = false;
                }
            }
            else if (ini.IniReadValue("SysInfo", "FormType") == "2") //如果是验票站就让用户可以选择
            {
                if (StaticParameter.UserCode != "0")
                {
                    this.cmbRoom.Enabled = true;
                    label1.Text = "计 量 站:";
                }
            }
            #endregion

            CommonMethod.ComboxBind(this.cmbRoom, "Sys_Colliery", "CollName", "CollCode", "IsForbid='0'", "CollName", "请选择煤矿", "0");
            CommonMethod.ComboxBind(this.cmbCoalKind, "TT_CoalKind", "CoalkindName", "CoalKindCode", "IsForbid='0'", "CoalkindName asc", "请选择煤种", "0");
            //CommonMethod.ComboxBind(cmbOperator, "VT_LoadWeightOfOperator", "Operator", "OperatorSam", "RoomCode='" + strRoomCode + "'", "Operator asc", "请选择司磅员", "-1");

            this.dtpBegin.Text = DateTime.Now.ToShortDateString();
            this.dtpEnd.Text = DateTime.Now.AddDays(1).ToShortDateString();

            this.dgvMarkedCardSearch.AutoGenerateColumns = false;
            #endregion

            #region 判断该站是不是煤矿端计量站
            StringBuilder sbselectsql = new StringBuilder();
            sbselectsql.Append("select count(*) from TT_Room");
            sbselectsql.Append(" where RoomType='2' and RoomCode ='" + strRoomCode + "'");

            object OCount = DbHelperSQL.GetSingle(sbselectsql.ToString());

            loadData();
        }
Esempio n. 4
0
 /// <summary>
 /// 获取数据库中煤矿的余额和煤矿信息
 /// </summary>
 /// <returns></returns>
 private List<string> GetColieryAccount()
 {
     string strSql = "SELECT c.CollName ,[Account] ,[LowAccount] FROM [CoalTraffic].[dbo].[TT_ColieryAccount] as ca join [Sys_Colliery] as c on ca.CollCode=c.CollCode ";
     SqlDataReader reader = DbHelperSQL.ExecuteReader(strSql);
     List<string> list = new List<string>();
     RWini rwini = new RWini();
     string account = rwini.IniReadValue("ColieryAccount", "Account");
     while (reader.Read())
     {
         string s = reader[0].ToString();
         decimal DAaccount = (decimal)reader[1];
         if (DAaccount < int.Parse(account))
         {
             list.Add(s+"企业存款为:"+DAaccount.ToString()+" ,请提醒该企业及时缴费!");
         }
     }
     return list;
 }
 /// <summary>
 /// �����ַ���
 /// </summary>
 /// <returns></returns>
 public static string connectionString()
 {
     string connection = System.Configuration.ConfigurationManager.AppSettings["ConnectionString"];
     if (connection != "")
     {
         return connection;
     }
     else
     {
         RWini ini = new RWini();
         string ii = ini.IniReadValue("Connection", "isConnection");
         if (ini.IniReadValue("Connection", "isConnection") == "1")//�������ݿ�����
         {
             return "User ID=sa;pwd=" + CommonMethod.DecryptDES(ini.IniReadValue("Connection", "LPsw"), "EncryDes").ToLower() + ";Data Source=" + ini.IniReadValue("Connection", "LServer") + ";Initial Catalog=" + ini.IniReadValue("Connection", "LDataBase") + ";";
         }
         else//Զ�̷��������ݿ�����
         {
             return "User ID=sa;pwd=" + CommonMethod.DecryptDES(ini.IniReadValue("Connection", "LPsw"), "EncryDes").ToLower() + ";Data Source=" + ini.IniReadValue("Connection", "SServer") + ";Initial Catalog=" + ini.IniReadValue("Connection", "LDataBase") + ";";
         }
     }
 }
        private void btnLogin_Click(object sender, EventArgs e)
        {
            RWini ini = new RWini();
            string ip = ini.IniReadValue("Connection", "SServer");
            string strIp;

            #region 网络判断处理
            if (GetCmdPingResult(ip) == "1")
            {
                strIp = ini.IniReadValue("Connection", "isConnection");
                if (strIp != "0")
                {
                    ini.IniWriteValue("Connection", "isConnection", CommonMethod.ToDBC("0"));
                }
            }
            else
            {
                strIp = ini.IniReadValue("Connection", "isConnection");
                if (strIp == "0")
                {
                    ini.IniWriteValue("Connection", "isConnection", CommonMethod.ToDBC("1"));
                    MessageBox.Show("由于网络原因本系统与中心机房断开连接,请联系中心机房管理员!");
                    Application.ExitThread();
                    Application.Exit();
                }
            }
            #endregion

            if (cbxUserName.SelectedValue != null && txbPassWord.Text.Trim() != "")
            {
                string strUserCode = cbxUserName.SelectedValue.ToString();
                string password = CommonMethod.MD5Crypt(txbPassWord.Text.Trim());

                if (operbll.IsLoginInfo(strUserCode, password) > 0)//验证帐号密码
                {

                    #region 插入登录日志到数据库
                    StaticParameter.UserCode = strUserCode;
                    StaticParameter.UserName = cbxUserName.Text;
                    string strLogType = "登录";
                    string strUserTable = "Sys_Operator";
                    string strUserIP = System.Net.Dns.Resolve(System.Net.Dns.GetHostName()).AddressList[0].ToString();
                    strUserCode = this.cbxUserName.SelectedValue.ToString();
                    string strUserDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                    string strRemark = "登录CS调运系统";
                    string strSysCode = "s2000";
                    string strRelationID = strUserCode;
                    StringBuilder sbsql = new StringBuilder();
                    sbsql.Append("insert into Sys_OperateLog (LogType,OperateTable,Operator,OperateDate,OperateIP,Remark,SysCode,RelationID)");
                    sbsql.Append(" values('" + strLogType + "','" + strUserTable + "','" + StaticParameter.UserName + "','" + strUserDate + "','" + strUserIP + "','" + strRemark + "','" + strSysCode + "','" + strRelationID + "')");
                    DbHelperSQL.ExecuteSql(sbsql.ToString());

                    #region 当联网的时:插入同步sql语句到服务器,sql语句本地执行
                    if (strIp == "0")//当联网的时候将给本地数据库也插入数据
                   {
                      string sqlInsert = "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",sbsql.ToString()),
                            new SqlParameter("@datetime",DateTime.Now.ToString()),
                            new SqlParameter("@IP",ini.IniReadValue("Connection","LServer"))
                        };
                       DbHelperSQL.ExecuteSql(sqlInsert,sqlpars); //插入同步sql语句
                       DbHelperSQL.ExecuteSql2(sbsql.ToString(), "1");//sql语句本地执行
                   }
                   #endregion
                    #endregion

                    #region 当断网时,添加断网过磅的登录日志sql语句
                    if (strIp == "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",sbsql.ToString()),
                         new SqlParameter("@datetime",DateTime.Now)
                         };
                        DbHelperSQL.ExecuteSql(sbsqlcontext.ToString(), parameters);
                    }
                    #endregion

                    if (_isFirst == "0")
                    {
                        this.Hide();

                        #region 登录成功之后选择系统
                        if (StaticParameter.UserCode != "0")
                        {
                            #region 非超级管理员登录

                            if (StaticParameter.FormType == "1")
                            {
                                new RMainForm(strUserCode).ShowDialog();
                            }
                            else
                            {
                                new CMainForm(strUserCode).ShowDialog();
                            }
                            #endregion
                        }
                        else
                        {
                            #region 超级管理员登录
                            if (StaticParameter.FormType == "2")
                            {
                                new CMainForm(strUserCode).ShowDialog();
                            }

                            if (StaticParameter.FormType == "1")
                            {
                                new RMainForm(strUserCode).ShowDialog();
                            }
                            #endregion
                        }
                        #endregion
                    }
                    else
                    {
                        this.DialogResult = DialogResult.OK;
                        this.Close();
                    }
                }
                else
                {
                    MessageBox.Show("登录验证失败,请检查用户名或密码是否正确!", "天大天科调运系统", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txbPassWord.Text = "";
                    return;
                }
            }
            else
            {
                MessageBox.Show("请检查用户名和密码后重新输入!", "天大天科调运系统", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }
        private void btnOK_Click(object sender, EventArgs e)
        {
            #region �ж��Ƿ��Ƕ�ι���
            DataTable dtEmpty = DbHelperSQL.ReturnTableQuery("SELECT TOP 1 WeightTime FROM [CoalTraffic].[dbo].[TT_LoadWeight]  where NavicertCode='" + strNavicertCode + "'  order by WeightTime desc");
             if (dtEmpty.Rows.Count > 0)
             {
                 string tm = ini.IniReadValue("RoomSetting", "Times");//����೤ʱ���ڿ��Թ���(����)
                 int time = Convert.ToInt32(tm);
                 if ((DateTime.Now - (Convert.ToDateTime(dtEmpty.Rows[0]["WeightTime"]))).TotalMinutes < time)
               {
                   alarmSound.Alarm("��Сʱ���ظ�������");
                   ClearAll();
                   return;
               }
             }
            #endregion

            CoalTraffic.Model.TT_LoadWeight model = new CoalTraffic.Model.TT_LoadWeight();

            if (strCurrentMenu != "Person")
            {
                model.LoadWeight = Convert.ToDecimal(lblDigital.Text);
                model.NetWeight = Convert.ToDecimal(lblDigital.Text) - Convert.ToDecimal(txtEmptyWeight.Text.Trim());
            }
            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()))
                    {
                        alarmSound.Alarm("��������س���������С�ڰ�������");
                        txtHandDigital.Text = "";
                        return;
                    }
                    else
                    {
                        model.LoadWeight = Convert.ToDecimal(CommonMethod.ToDBC(this.txtHandDigital.Text.Trim()));
                        model.NetWeight = Convert.ToDecimal(CommonMethod.ToDBC(this.txtHandDigital.Text.Trim())) - Convert.ToDecimal(txtEmptyWeight.Text.Trim());
                    }
                }
                else
                {
                    alarmSound.Alarm("��������س�������ʽ����");
                    txtHandDigital.Text = "";
                    return;
                }
                #endregion
            }
            if (model.NetWeight > 0.00m)
            {

                #region ��ȡ����ҵ��ص���Ϣ
                SqlParameter[] parameter =
                {
                    new SqlParameter("@CollCode", SqlDbType.VarChar,10),
                    new SqlParameter("@CoalKindCode", SqlDbType.VarChar,4)
                };

                parameter[0].Value = strCollCode;
                parameter[1].Value = strCoalKindCode;
                DataSet dstColieryAccount = DbHelperSQL.RunProcedure("PT_ColieryAccountJudge", parameter, "ColieryAccount");
                #endregion

                string strLeastValue = dstColieryAccount.Tables["ColieryAccount"].Rows[0]["ReturnValue"].ToString();

                if (strLeastValue == "0") //0���������ɹ���
                {
                    #region ��Ƶץͼ
                    if (StaticParameter.IsVideo == "1")
                    {
                        if (byteFrontImage == null && byteBackImage == null && byteUpImage == null && byteRoomImage == null)
                        {
                            byteFrontImage = this.videoFrontImage.CapturePic();
                            byteBackImage = this.videoBackImage.CapturePic();
                            byteUpImage = this.videoUpImage.CapturePic();
                            byteRoomImage = this.videoRoomImage.CapturePic();
                        }
                    }
                    #endregion

                    #region ʵ�����س�
                    string strWeightCode = strRoomCode + DateTime.Now.ToString("yyyyMMddHHmmss");
                    model.WeightCode = strWeightCode;
                    model.TrafficCode = cementName;//strWeightCode;
                    model.NavicertCode = strNavicertCode;
                    model.MarkedCardCode = strMardedCardCode;
                    model.RemoteCardCode = strRemoteCode;

                    model.CollCode = strCollCode;
                    model.CollName = this.ComCollName.Text.Trim();
                    model.CoalKindCode = this.strCoalKindCode;
                    //���� 2010-05-19 ѡ���Ʒ�ij�������
                    model.CoalKindName = this.ComKindName.Text.Trim();
                    //model.CoalKindName = this.txtKindName.Text.Trim();
                    model.CarOwnerName = strCarOwnerName;

                    model.CarNo = txtCarNo.Text;
                    model.CarType = txtCarType.Text;
                    model.EmptyWeight = Convert.ToDecimal(txtEmptyWeight.Text);

                    model.OverWeight = 0;
                    model.RoomCode = strRoomCode;
                    model.RoomName = strRoomName;
                    model.BangType = strBangType;
                    model.Operator = StaticParameter.UserName;

                    model.WeightTime = DateTime.Now;
                    model.RandomCode = CommonMethod.getRandom(4);
                    model.CustomerName = "ˮ��ȥ��";
                    model.IsFirstSite = "1";
                    model.TaxType = "�س�������˰";

                    model.FrontImage = strFrontImage;
                    model.BackImage = strBackImage;
                    model.UpImage = strUpImage;
                    model.RoomImage = strRoomImage;
                    model.FrontImageContent = byteFrontImage;

                    model.BackImageContent = byteBackImage;
                    model.UpImageContent = byteUpImage;
                    model.RoomImageContent = byteRoomImage;
                    //model.TaxObject = ConfigurationManager.AppSettings["TaxObject"].ToString();
                    RWini rwini = new RWini();
                    model.TaxObject = ini.IniReadValue("GFSet", "TaxObject");
                    model.EmptyCode = strEmptyCode;
                    #endregion

                    if (bll.Add(model) != "")
                    {
                        if (bll.Add(model) != "-1")
                        {
                            #region ��ӳɹ���������ͬ��
                             try
                                {
                                    //����ͼƬ
                                    //System.Net.WebClient webclient = new System.Net.WebClient();
                                    //if (byteFrontImage != null)
                                    //{
                                    //    webclient.UploadData(ini.IniReadValue("PicterRoute", "PRoute") + model.WeightCode + "&filename=1", byteFrontImage);
                                    //}
                                    //if (byteBackImage != null)
                                    //{
                                    //    webclient.UploadData(ini.IniReadValue("PicterRoute", "PRoute") + model.WeightCode + "&filename=2", byteBackImage);
                                    //}
                                    //if (byteUpImage != null)
                                    //{
                                    //    webclient.UploadData(ini.IniReadValue("PicterRoute", "PRoute") + model.WeightCode + "&filename=3", byteUpImage);
                                    //}
                                    //if (byteRoomImage != null)
                                    //{
                                    //    webclient.UploadData(ini.IniReadValue("PicterRoute", "PRoute") + model.WeightCode + "&filename=4", byteRoomImage);
                                    //}
                                }
                                catch
                                {

                                }

                            #endregion

                            string strErro = "";
                            if (StaticParameter.IsHaveMarkedCard == "1")
                            {
                                strErro = "�����ձ�ʶ��";
                            }
                            if (StaticParameter.FormType == "2")  //��Ʊվ�޴�ӡ�� �����ӡ
                            {
                                alarmSound.Alarm("�����ɹ�,����ձ�ʶ��");
                                CommonMethod.MessageBox("�����ɹ�,����ձ�ʶ��!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                            }
                            else
                            {
                                alarmSound.Alarm("�����ɹ�,���ȷ����ӡ�س�������" + strErro + "");
                                CommonMethod.MessageBox("�����ɹ�,���ȷ����ӡ�س�������" + strErro + "!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);

                                //�������ó�ر�־λ
                                this.isks = true;

                                Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
                                string strFileName = "";

                                strFileName = StaticParameter.ReportFile;

                                Type type = assembly.GetType("CoalTraffic.Report." + strFileName + "LoadWeightPrint");
                                object obj = Activator.CreateInstance(type, strWeightCode, true); Form formToShow = (Form)obj; formToShow.ShowDialog();
                            }
                        }
                        else
                        {
                            alarmSound.Alarm("�˻�����Ѳ��㱾���Ŀۿ��֪ͨ" + ComCollName.Text.Trim() + "��������");
                            CommonMethod.MessageBox("�˻�����Ѳ��㱾���Ŀۿ��֪ͨ" + ComCollName.Text.Trim() + "��������", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);

                        }
                    }
                    else
                    {
                        this.alarmSound.Alarm("��վ�����ݿ��쳣");
                        InsertState = 0;
                        InsertBadReCordInfo("�쳣", txtCarNo.Text.Trim(), "�����ݿ��쳣");
                    }
                }
                else if (strLeastValue == "1")
                {
                    alarmSound.Alarm("��ҵ����������,���ܼ�������");
                    CommonMethod.MessageBox("��ҵ����������,���ܼ�������!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);

                }
                else if (strLeastValue == "2")
                {
                    alarmSound.Alarm("����ҵ�������ò�Ʒ,���ܼ�������");
                    InsertState = 0;
                    InsertBadReCordInfo("�쳣", txtCarNo.Text.Trim(), strCollName + "������" + strCoalKindName);
                    CommonMethod.MessageBox("����ҵ�������ò�Ʒ,���ܼ�������!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);

                }
                else if (strLeastValue == "-1")
                {
                    alarmSound.Alarm("����ҵ������,���ܼ�������");
                    InsertState = 0;
                    InsertBadReCordInfo("�쳣", txtCarNo.Text.Trim(), "���Ϊ��" + strCollCode + "����ҵ������");
                }

                btnOK.Enabled = false;
                ClearAll();
                if (StaticParameter.CardType == "IC")
                    icCard.FactoryCodeInitValue = "";
            }
            else
            {
                alarmSound.Alarm("ˮ�ྻ���쳣");
                InsertState = 0;
                InsertBadReCordInfo("�쳣", txtCarNo.Text.Trim(), "���ƺ�Ϊ��" + txtCarNo.Text.Trim() + "������ˮ�ྻ���쳣");
            }
        }
        /// <summary>
        /// 转化磅秤的显示值 例:大唐波特率4800数据转换格式:"01632031E+"->"16.32" ;耀华波特率9600数据转换格式:"00006001D+"->"0.06";柯力波特9600数据转换格式:"060.000="->"0.06";
        /// </summary>
        /// <param name="strPoundValue"></param>
        /// <returns></returns>
        public static string ChangePoundValue(string strPoundValue)
        {
            RWini ini = new RWini();
            string strWeightValue = string.Empty;

            string strPoundType = ini.IniReadValue("BcComSetting", "BcType");
            string strPoundRate = ini.IniReadValue("BcComSetting", "BoudRate");

            if ((strPoundType == "柯力" && strPoundRate == "9600"))
            {
                string strFrontPart = string.Empty;
                string strBehindPart = string.Empty;
                if (strPoundValue.Length >= 9 && (strPoundValue.EndsWith("=") || strPoundValue.StartsWith("=")))
                {

                }
            }

            if ((strPoundType == "大唐" && strPoundRate == "4800") || (strPoundType == "耀华") && strPoundRate == "9600")
            {
                string strFrontPart = string.Empty;
                string strBehindPart = string.Empty;

                if (strPoundValue.Length >=9 && (strPoundValue.EndsWith("=") || strPoundValue.StartsWith("=")))
                {
                    strPoundValue = RemoceSpecialChar(strPoundValue); //去除特殊字符 01632031->16.32

                    strFrontPart = strPoundValue.Substring(0, 3).TrimStart('0');

                    if (strFrontPart == "")
                    {
                        strFrontPart = "0";
                    }

                    strBehindPart = strPoundValue.Substring(3, 2);

                    strWeightValue = strFrontPart + "." + strBehindPart;
                }
            }

            return strWeightValue;
        }
 /// <summary>
 /// 获取过磅编号(格式1-4位磅称,5-12位年月日,13-16位过磅编号 如0001 20080808 0001)
 /// </summary>
 /// <param name="TableName">表名</param>
 /// <param name="KeyName">主键名</param>
 /// <returns></returns>
 public static string getMaxBangID(string TableName, string KeyName)
 {
     try
     {
         string RoomCode = new RWini().IniReadValue("RoomSetting", "RoomCode");
         string sql = "Select CONVERT(varchar(8), GETDATE(), 112)+ right('0000'+cast(isnull(max(cast(substring(" + KeyName + ",14,4) as int)),0)+1 as varchar(4)),4)"
                     + " From " + TableName
                     + " Where substring(" + KeyName + ",5,8)=CONVERT(varchar(8), GETDATE(), 112) and substring(" + KeyName + ",1,4)='" + RoomCode.PadLeft(4, '0') + "'";
         return RoomCode.PadLeft(4, '0') + DbHelperSQL.GetSingle(sql).ToString();
     }
     catch
     {
         return "";
     }
 }
        static void Main()
        {
            int iProcessNum = 0;

            foreach (Process singleProc in Process.GetProcesses())
            {
                if (singleProc.ProcessName == Process.GetCurrentProcess().ProcessName)
                {
                    iProcessNum += 1;
                }
            }
            if (iProcessNum > 1)
            {

                MessageBox.Show("该程序已经在运行中!", "天大天科调运系统", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {

                //设置应用程序未处理异常方式:ThreadException处理
                Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
                //处理未捕获的UI线程异常
                Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
                //处理未捕获的非ui线程异常
                AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

                RWini ini = new RWini();
                string strIsSet = ini.IniReadValue("Connection", "isSet");
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                if (strIsSet == "1")
                {
                    if (new UserLogin().ShowDialog() == DialogResult.OK)
                    {
                        string strUserCode = StaticParameter.UserCode;

                        #region 登录成功之后选择系统
                        if (strUserCode != "0")
                        {
                            #region 非超级管理员登录
                            if (StaticParameter.FormType == "1")
                            {
                                new RMainForm(strUserCode).ShowDialog();
                            }
                            else
                            {
                                new CMainForm(strUserCode).ShowDialog();
                            }
                            #endregion
                        }
                        else
                        {
                            #region 超级管理员登录
                            if (StaticParameter.FormType == "2")
                            {
                                new CMainForm(strUserCode).ShowDialog();
                            }

                            if (StaticParameter.FormType == "1")
                            {
                                new RMainForm(strUserCode).ShowDialog();
                            }
                            #endregion
                        }
                        #endregion
                    }
                }
                else if (strIsSet == "0")
                {
                    if (new Settings.DataBaseInitial().ShowDialog() == DialogResult.OK)
                    {
                        Application.Run(new UserLogin("0"));
                    }
                }
            }
        }
        private void MarkedCardSearch_Load(object sender, EventArgs e)
        {
            string strRoomCode = new RWini().IniReadValue("RoomSetting", "RoomCode");
            this.grdNavicert.AutoGenerateColumns = false;

            CommonMethod.ComboxBind(this.cmbCollCode, "Sys_Colliery", "CollName", "CollCode", "IsForBid ='0'", "CollName asc", "请选择企业", "0");

            CommonMethod.ComboxBind(this.cmbCoalKindCode,"TT_CoalKind","CoalKindName", "CoalKindCode","IsForBid ='0'","CoalKindName asc","请选择产品","0");

            loadData();
        }
 private void NavicertSearch_Load(object sender, EventArgs e)
 {
     string strRoomCode =  new RWini().IniReadValue("RoomSetting", "RoomCode");
     this.grdNavicert.AutoGenerateColumns = false;
     CommonMethod.ComboxBind(this.cbxRoomCode, "TT_Room", "RoomName", "RoomCode", "IsForbid='0'", "RoomName", "请选择验票站", "0");
     this.cbxRoomCode.SelectedValue = strRoomCode;
     this.cbxRoomCode.Enabled = false;
     CommonMethod.ComboxBind(this.cbxSendPerson, "Sys_Operator", "UserName", "UserCode", "IsForbid='0' and OrgCode='" + strRoomCode + "'", "UserName asc", "请选择发卡人", "-1");
     loadData();
 }
        //读取参数中的值
        private void port_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            string tenstring = string.Empty;
            System.Threading.Thread.Sleep(200);
            int bytes = comport.BytesToRead;//读出的字节长度
            byte[] buffer = new byte[bytes];//定义一个长度为10的字节数组
            comport.Read(buffer, 0, bytes);
            if (bytes > 0)
            {
                switch (bytes)
                {
                    case 10:
                        {
                            int iten = 0;
                            int gten = 0;
                            for (int i = 0; i < bytes - 1; i++)
                            {
                                if (i == 5 || i == 6 || i == 7)
                                {
                                    switch (buffer[i].ToString().ToUpper())
                                    {
                                        case "A":
                                            iten = 10;
                                            break;
                                        case "B":
                                            iten = 11;
                                            break;
                                        case "C":
                                            iten = 12;
                                            break;
                                        case "D":
                                            iten = 13;
                                            break;
                                        case "E":
                                            iten = 14;
                                            break;
                                        case "F":
                                            iten = 15;
                                            break;
                                        default:
                                            iten = Convert.ToInt32(buffer[i]);
                                            break;
                                    }
                                    switch (i)
                                    {
                                        case 4:
                                            {
                                                gten = gten + iten * 256 * 256 * 256;
                                                break;
                                            }
                                        case 5:
                                            {
                                                gten = gten + iten * 256 * 256;
                                                break;
                                            }
                                        case 6:
                                            {
                                                gten = gten + iten * 256;
                                                break;
                                            }
                                        case 7:
                                            {
                                                gten = gten + iten;
                                                break;
                                            }

                                    }

                                }//if

                            }//for;
                            tenstring = gten.ToString("0000000000");
                            break;
                        }//case 10
                    case 9:
                        {
                            ulong iten = 0;
                            ulong gten = 0;
                            for (int i = 0; i < bytes - 1; i++)
                            {
                                if (i == 3 || i == 4 || i == 5 || i == 6)
                                {
                                    switch (buffer[i].ToString().ToUpper())
                                    {
                                        case "A":
                                            iten = 10;
                                            break;
                                        case "B":
                                            iten = 11;
                                            break;
                                        case "C":
                                            iten = 12;
                                            break;
                                        case "D":
                                            iten = 13;
                                            break;
                                        case "E":
                                            iten = 14;
                                            break;
                                        case "F":
                                            iten = 15;
                                            break;
                                        default:
                                            iten = Convert.ToUInt64(buffer[i]);
                                            break;
                                    }//swith
                                    switch (i)
                                    {
                                        case 3:
                                            {
                                                gten = gten + iten * 256 * 256 * 256;
                                                break;
                                            }
                                        case 4:
                                            {
                                                gten = gten + iten * 256 * 256;
                                                break;
                                            }
                                        case 5:
                                            {
                                                gten = gten + iten * 256;
                                                break;
                                            }
                                        case 6:
                                            {
                                                gten = gten + iten;
                                                break;
                                            }

                                    }//swith;
                                }//if

                            }//for
                            tenstring = gten.ToString();
                            break;
                        }//case 9
                    default:
                        {
                            alarmSound.Alarm("读取到非正常使用的卡片");
                            return;
                        }
                }//swith case;
                //转换成相应的数据库信息
                string sSQL = "select CardNo from TT_InitialCard where CardID='" + tenstring + "' and CardType='1'";
                object OResult = DbHelperSQL.GetSingle(sSQL);
                if (OResult == null)
                {
                    alarmSound.Alarm("此卡没有相应的初始化信息");
                }
                else
                {
                    //从0开始计数,所以要加1位进行运算。
                    if (iCardCount + 1 <= iLimitCardCount)
                    {
                        #region 从服务器获取卡的类型--初始化表中
                        sSQL = "select CardType from TT_InitialCard where CardID='" + tenstring + "'";
                        object oCardType = DbHelperSQL.GetSingle(sSQL);
                        string CardType = oCardType.ToString();
                        #endregion

                        #region 从服务器查下发卡时间和当前时间的差值
                        string strTime = "SELECT DATEDIFF(DAY, (select [SendCardDate] from [CoalTraffic].[dbo].[TT_MarkedCard] where [MarkedCardNo]='" + tenstring + "'), GETDATE())";//查询发卡时间和现在时间只差是多少天
                        object objTime = DbHelperSQL.GetSingle(strTime);
                        int CardTime =Convert.ToInt32( objTime) ;//将时间转换为整数型
                        #endregion
                        if (CardType == "1")
                        {
                            RWini ini = new RWini();
                            int days = int.Parse(ini.IniReadValue("ActiveMarkedCard", "days"));
                            if (CardTime < days)
                            {
                                alarmSound.Alarm("此 卡 的 激 活 时 间 还 没 有 到,还 差 "+(days-CardTime).ToString()+" 天 才 可 以 激 活");
                                return;
                            }
                            //外部编号
                            string resultSql = OResult.ToString().Trim();
                            if (!SCardCode.Contains(resultSql))
                            {
                                sSQL = "select MarkedCardState from TT_MarkedCard where MarkedCardNo='" + tenstring + "'";
                                object OMarkedState = DbHelperSQL.GetSingle(sSQL);
                                if (OMarkedState != null)
                                {
                                    string state = OMarkedState.ToString();

                                    state = "2";//可以刷所有的卡
                                    if (state == "2")
                                    {
                                        //在此种状态下,才开始进行数据处理;
                                        SCardCode = SCardCode + resultSql + "|";
                                        SCardNo = SCardNo + tenstring + "|";
                                        iCardCount += 1;
                                        Log(ByteArrayToHexString(buffer), resultSql, tenstring);
                                    }
                                    else if (state == "")
                                        alarmSound.Alarm("此标识卡还未使用不能验证");
                                    else if (state == "1")
                                        alarmSound.Alarm("该标识卡是未使用状态不能验证");
                                    else if (state == "3")
                                        alarmSound.Alarm("该标识卡已挂失不能验证");
                                    else if (state == "4")
                                        alarmSound.Alarm("该标识卡已吊销不能验证");
                                }
                                else
                                {
                                    alarmSound.Alarm("此标示卡还未处理");
                                }

                            }
                            else
                            {
                                alarmSound.Alarm("此标示卡已经刷过");
                            }

                        }
                        else
                        {
                            alarmSound.Alarm("您刷的不是标示卡");
                        }
                    }
                    else
                    {
                        alarmSound.Alarm("您刷卡数量已到达要购买数量");
                    }
                }
            }//if bytes
        }
        private void btnLogin_Click(object sender, EventArgs e)
        {
            RWini ini = new RWini();
            string ip = ini.IniReadValue("Connection", "SServer");
            string strIp;
            if (GetCmdPingResult(ip) == "1")
            {
                strIp = ini.IniReadValue("Connection", "isConnection");
                if (strIp != "0")
                {
                    ini.IniWriteValue("Connection", "isConnection", CommonMethod.ToDBC("0"));
                }
            }
            else
            {
                strIp = ini.IniReadValue("Connection", "isConnection");
                if (strIp == "0")
                {
                    //ini.IniWriteValue("Connection", "isConnection", CommonMethod.ToDBC("1"));
                    //MessageBox.Show("系统与服务器断开连接,请重新登陆系统!");
                    MessageBox.Show("系统与服务器断开连接,请联系中心机房!");
                    Application.ExitThread();
                    Application.Exit();
                }
            }
            MC = new MSMQClient();
            if (cbxUserName.SelectedValue != null && txbPassWord.Text.Trim() != "")
            {
                string strUserCode = cbxUserName.SelectedValue.ToString();
                string password = CommonMethod.MD5Crypt(txbPassWord.Text.Trim());

                if (operbll.IsLoginInfo(strUserCode, password) > 0)
                {

                    StaticParameter.UserCode = strUserCode;
                    StaticParameter.UserName = cbxUserName.Text;
                    string strLogType = "登录";
                    string strUserTable = "Sys_Operator";
                    string strUserIP = System.Net.Dns.Resolve(System.Net.Dns.GetHostName()).AddressList[0].ToString();
                    strUserCode = this.cbxUserName.SelectedValue.ToString();
                    string strUserDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                    string strRemark = "登录CS调运系统";
                    string strSysCode = "s2000";
                    string strRelationID = strUserCode;
                    StringBuilder sbsql = new StringBuilder();
                    sbsql.Append("insert into Sys_OperateLog (LogType,OperateTable,Operator,OperateDate,OperateIP,Remark,SysCode,RelationID)");
                    sbsql.Append(" values('" + strLogType + "','" + strUserTable + "','" + StaticParameter.UserName + "','" + strUserDate + "','" + strUserIP + "','" + strRemark + "','" + strSysCode + "','" + strRelationID + "')");
                    DbHelperSQL.ExecuteSql(sbsql.ToString());
                    //登陆日志上传到服务器
                    if (strIp == "0")
                    {
                        //MsmqManageServer mqServer = new MsmqManageServer();
                        MSMQserver mqServer = new MSMQserver();
                        mqServer.AddMsmq(MC.ServerStation + MC.Prefix + "Sys_OperateLog" + MC.Prefix + MC.AddFlg + MC.Prefix + DateTime.Now.ToString("yyyy-MM-dd hh:mm;ss") + MC.Prefix + sbsql.ToString());
                    }
                    else
                    {
                        MC.AddNewSqlText(MC.ServerStation + MC.Prefix + "Sys_OperateLog" + MC.Prefix + MC.AddFlg + MC.Prefix + DateTime.Now.ToString("yyyy-MM-dd hh:mm;ss") + MC.Prefix + sbsql.ToString());
                    }
                    if (_isFirst == "0")
                    {
                        this.Hide();

                        #region 登录成功之后选择系统
                        if (StaticParameter.UserCode != "0")
                        {
                            #region 非超级管理员登录

                            if (StaticParameter.FormType == "1")
                            {
                                new RMainForm(strUserCode).ShowDialog();
                            }
                            else
                            {
                                new CMainForm(strUserCode).ShowDialog();
                            }
                            #endregion
                        }
                        else
                        {
                            #region 超级管理员登录
                            if (StaticParameter.FormType == "2")
                            {
                                new CMainForm(strUserCode).ShowDialog();
                            }

                            if (StaticParameter.FormType == "1")
                            {
                                new RMainForm(strUserCode).ShowDialog();
                            }
                            #endregion
                        }
                        #endregion
                    }
                    else
                    {
                        this.DialogResult = DialogResult.OK;
                        this.Close();
                    }
                }
                else
                {
                    MessageBox.Show("登录验证失败,请检查用户名和密码后重新输入!", "天大天科调运系统", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txbPassWord.Text = "";
                }
            }
            else
            {
                MessageBox.Show("请检查用户名和密码后重新输入!", "天大天科调运系统", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void FM_UserLogin_Load(object sender, EventArgs e)
        {
            string strIp;
            RWini ini = new RWini();
            string ip = ini.IniReadValue("Connection", "SServer");
            if (GetCmdPingResult(ip) == "1")
            {
                strIp = ini.IniReadValue("Connection", "isConnection");
                if (strIp == "1")
                {
                    ini.IniWriteValue("Connection", "isConnection", CommonMethod.ToDBC("0"));
                }
            }
            else
            {
                #region 是否开启断网过磅
                string isONNet = ini.IniReadValue("Connection", "isOnNetWorkDisconnection");
                if (isONNet != "0")
                {
                    MessageBox.Show("本系统未开启断网过磅功能,请联系中心机房管理员", "天大天科", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    Application.ExitThread();
                    Application.Exit();
                }
                #endregion

                strIp = ini.IniReadValue("Connection", "isConnection");
                if (strIp == "0")
                {
                    ini.IniWriteValue("Connection", "isConnection", CommonMethod.ToDBC("1"));
                    MessageBox.Show("由于网络原因本系统与服务器断开连接", "天大天科", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Application.ExitThread();
                    Application.Exit();
                }
            }
            //IC和ID卡相关信息。
            #region IC卡和ID卡相关信息
            StaticParameter.BaudRate = ini.IniReadValue("IcCard", "BoudRate");
            StaticParameter.DateBits = ini.IniReadValue("IcCard", "DataBits");
            StaticParameter.StopBits = ini.IniReadValue("IcCard", "StopBits");
            StaticParameter.Parity = ini.IniReadValue("IcCard", "Parity");
            StaticParameter.PortName = ini.IniReadValue("IcCard", "PortName");
            #endregion
            //磅房类型
            #region 磅房类型
            string strFormType = ini.IniReadValue("SysInfo", "FormType");
            if (strFormType == "1")
            {
                StaticParameter.FormType = strFormType;
            }
            else
            {
                StaticParameter.FormType = "2";
            }
            #endregion

            //磅房相关信息。
            #region 磅房相关信息
            StaticParameter.BangBaudRate = ini.IniReadValue("BcComSetting", "BoudRate");
            StaticParameter.BangDateBits = ini.IniReadValue("BcComSetting", "DataBits");
            StaticParameter.BangStopBits = ini.IniReadValue("BcComSetting", "StopBits");
            StaticParameter.BangParity = ini.IniReadValue("BcComSetting", "Parity");
            StaticParameter.BangPortName = ini.IniReadValue("BcComSetting", "PortName");
            #endregion

            //卡片类型
            #region 卡片类型
            if (ini.IniReadValue("RoomSetting", "CardType") == "ID")
            {
                StaticParameter.CardType = "ID";
            }
            else
            {
                StaticParameter.CardType = "IC";
            }
            #endregion

            #region 卡片长度
            int INavicertCardLength, IMarkedCardLength;
            if (int.TryParse(ini.IniReadValue("CardLength", "NavicertLength"), out INavicertCardLength))
            {
                StaticParameter.NavicertLength = INavicertCardLength;
            }
            else
            {
                StaticParameter.NavicertLength = 10;
            }
            if (int.TryParse(ini.IniReadValue("CardLength", "MarkedCardLength"), out IMarkedCardLength))
            {
                StaticParameter.MarkedCardLength = IMarkedCardLength;
            }
            else
            {
                StaticParameter.MarkedCardLength = 10;
            }
            #endregion

            //是否有视频
            #region 是否有视频
            if (ini.IniReadValue("VideoSetting", "IsVideo") == "1")
            {
                StaticParameter.IsVideo = "1";
            }
            else
            {
                StaticParameter.IsVideo = "0";
            }
            #endregion

            //是否有车牌识别器
            #region 是否有车牌识别器
            if (ini.IniReadValue("CarNoSetting", "IsCarNo") == "1")
            {
                StaticParameter.IsCarNo = "1";
            }
            else
            {
                StaticParameter.IsCarNo = "0";
            }
            #endregion

            //是否有标识卡
            #region 是否有标识卡
            if (ini.IniReadValue("RoomSetting", "IsHaveMarkedCard") == "1")
            {
                StaticParameter.IsHaveMarkedCard = "1";
            }
            else
            {
                StaticParameter.IsHaveMarkedCard = "0";
            }
            #endregion

            //是否有电子标签
            #region 是否有电子标签
            if (ini.IniReadValue("RoomSetting", "RemoteReader") == "1")
            {
                StaticParameter.IsRemoteReader = "1";
            }
            else
            {
                StaticParameter.IsRemoteReader = "0";
            }
            #endregion

            //超重吨位阈值
            #region 超重阀值
            decimal dWeightThreshold;
            if (decimal.TryParse(ini.IniReadValue("RoomSetting", "WeightThreshold"), out dWeightThreshold))
            {
                StaticParameter.WeightThreshold = dWeightThreshold;
            }
            else
            {
                StaticParameter.WeightThreshold = 0.00m;
            }
            #endregion

            //是否需要多次空车过磅
            #region 是否需要多次空车过磅
            if (ini.IniReadValue("RoomSetting", "IsEmpty") == "1")
            {
                StaticParameter.IsEmpty = "1";
            }
            else
            {
                StaticParameter.IsEmpty = "0";
            }
            #endregion

            //图片是否只上传到服务器
            #region 图片是否只上传服务器
            if (ini.IniReadValue("SysInfo", "IsSendPicToRoom") == "0")
            {
                StaticParameter.IsSendPicToRoom = "0";
            }
            else
            {
                StaticParameter.IsSendPicToRoom = "1";
            }

            #endregion

            #region 视频放大倍数
            int iAmplify;
            if (int.TryParse(CommonMethod.ToDBC(ini.IniReadValue("VideoSetting", "Amplify")), out iAmplify))
            {
                if (iAmplify > 5)
                {
                    StaticParameter.Amplify = "5";
                }
                else
                {
                    StaticParameter.Amplify = ini.IniReadValue("VideoSetting", "Amplify");
                }
            }
            else
            {
                StaticParameter.Amplify = "3";
            }
            #endregion

            #region 报表文件夹
            if (ini.IniReadValue("SysInfo", "ReportFile") != "")
            {
                StaticParameter.ReportFile = ini.IniReadValue("SysInfo", "ReportFile") + ".";
            }
            #endregion

            #region 皮肤
            string strSkin = ini.IniReadValue("SysInfo", "Skin");
            string strPath = Directory.GetCurrentDirectory();
            StaticParameter.Skin = strPath + "\\Skin\\" + strSkin + "\\";
            #endregion

            #region 加载窗体背景
            string strbg = string.Empty;
            string strLoadBg = string.Empty;
            if (strFormType == "1")
            {
                strbg = "rlg.jpg";
                strLoadBg = "rbg.jpg";
            }
            else
            {
                strbg = "clg.jpg";
                strLoadBg = "cbg.jpg";
            }

            this.BackgroundImage = Image.FromFile(StaticParameter.Skin + strbg);
            this.BackgroundImageLayout = ImageLayout.Stretch;

            panLoad.BackgroundImage = Image.FromFile(StaticParameter.Skin + strLoadBg);
            panLoad.BackgroundImageLayout = ImageLayout.Stretch;
            #endregion

            BgWorker.RunWorkerAsync();
        }
 /// <summary>
 /// 创建消息队列
 /// </summary>
 void CreateQueue()
 {
     _dtblRoom = DbHelperSQL.ReturnTableQuery("Select RoomIP From TT_Room Where RoomCode ='0'");
     strRoomIP = _dtblRoom.Rows[0]["RoomIP"].ToString();
     strRoomName = new RWini().IniReadValue("RoomSetting", "RoomName");
     _strQueueName = "SqlServer";
     _MqSqlClient = new MessageQueue(_ServiceMachinePrefix + strRoomIP + "\\private$\\" + _strQueueName);
 }
        //读取参数中的值
        private void port_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            string tenstring = string.Empty;
            System.Threading.Thread.Sleep(200);
            int bytes = comport.BytesToRead;
            byte[] buffer = new byte[bytes];
            comport.Read(buffer, 0, bytes);
            if (bytes > 0)
            {
                switch (bytes)
                {
                    case 10:
                        {
                            int iten = 0;
                            int gten = 0;
                            for (int i = 0; i < bytes - 1; i++)
                            {
                                if (i == 5 || i == 6 || i == 7)
                                {
                                    switch (buffer[i].ToString().ToUpper())
                                    {
                                        case "A":
                                            iten = 10;
                                            break;
                                        case "B":
                                            iten = 11;
                                            break;
                                        case "C":
                                            iten = 12;
                                            break;
                                        case "D":
                                            iten = 13;
                                            break;
                                        case "E":
                                            iten = 14;
                                            break;
                                        case "F":
                                            iten = 15;
                                            break;
                                        default:
                                            iten = Convert.ToInt32(buffer[i]);
                                            break;
                                    }
                                    switch (i)
                                    {
                                        case 4:
                                            {
                                                gten = gten + iten * 256 * 256 * 256;
                                                break;
                                            }
                                        case 5:
                                            {
                                                gten = gten + iten * 256 * 256;
                                                break;
                                            }
                                        case 6:
                                            {
                                                gten = gten + iten * 256;
                                                break;
                                            }
                                        case 7:
                                            {
                                                gten = gten + iten;
                                                break;
                                            }

                                    }

                                }//if

                            }//for;
                            tenstring = gten.ToString("0000000000");
                            break;
                        }//case 10
                    case 9:
                        {
                            ulong iten = 0;
                            ulong gten = 0;
                            for (int i = 0; i < bytes - 1; i++)
                            {
                                if (i == 3 || i == 4 || i == 5 || i == 6)
                                {
                                    switch (buffer[i].ToString().ToUpper())
                                    {
                                        case "A":
                                            iten = 10;
                                            break;
                                        case "B":
                                            iten = 11;
                                            break;
                                        case "C":
                                            iten = 12;
                                            break;
                                        case "D":
                                            iten = 13;
                                            break;
                                        case "E":
                                            iten = 14;
                                            break;
                                        case "F":
                                            iten = 15;
                                            break;
                                        default:
                                            iten = Convert.ToUInt64(buffer[i]);
                                            break;
                                    }//swith
                                    switch (i)
                                    {
                                        case 3:
                                            {
                                                gten = gten + iten * 256 * 256 * 256;
                                                break;
                                            }
                                        case 4:
                                            {
                                                gten = gten + iten * 256 * 256;
                                                break;
                                            }
                                        case 5:
                                            {
                                                gten = gten + iten * 256;
                                                break;
                                            }
                                        case 6:
                                            {
                                                gten = gten + iten;
                                                break;
                                            }

                                    }//swith;
                                }//if

                            }//for
                            tenstring = gten.ToString();
                            break;
                        }//case 9
                    default:
                        {
                            alarmSound.Alarm("读取到非正常使用的卡片");
                            return;
                        }
                }//swith case;
                //转换成相应的数据库信息
                string sSQL = "select CardNo from TT_InitialCard where  CardID='" + tenstring + "' and CardType='1'";
                object OResult = DbHelperSQL.GetSingle(sSQL);
                if (OResult == null)
                {
                    alarmSound.Alarm("此卡没有相应的初始化信息");
                }
                else
                {
                    //从0开始计数,所以要加1位进行运算。
                    if (iCardCount + 1 <= iLimitCardCount)
                    {
                        sSQL = "select CardType from TT_InitialCard where CardID='" + tenstring + "'";
                        object oCardType = DbHelperSQL.GetSingle(sSQL);
                        string CardType = oCardType.ToString();

                        if (CardType == "1")
                        {
                            string sql = "select * from [CoalTraffic].[dbo].[TT_MarkedCard] where [MarkedCardNo]='" + tenstring + "'";
                            object o = DbHelperSQL.GetSingle(sql);
                            if(o != null)
                            {
                            string strTime = "SELECT DATEDIFF(DAY, (select [SendCardDate] from [CoalTraffic].[dbo].[TT_MarkedCard] where [MarkedCardNo]='" + tenstring + "'), GETDATE())";//查询发卡时间和现在时间只差是多少天
                            object objTime = DbHelperSQL.GetSingle(strTime);
                            int CardTime = (int)objTime;//将时间转换为整数型
                            RWini ini = new RWini();
                            int days = int.Parse(ini.IniReadValue("ActiveMarkedCard", "days"));
                            if (CardTime < days)
                            {
                                alarmSound.Alarm("此 卡 的 使 用 时 间 还 没 有 到,还 差 " + (days - CardTime).ToString() + " 天 才 可 以 使 用");
                                return;
                            }
                            }
                            //外部编号
                            string resultSql = OResult.ToString().Trim();
                            //sSQL="select MarkedCardNo from TT_MarkedCard where MarkedCardCode='"+resultSql+"' "
                            if (!strFactoryCode.Contains(tenstring))
                            {
                                sSQL = "select MarkedCardState from TT_MarkedCard where MarkedCardNo='" + tenstring + "'";
                                object OMarkedState = DbHelperSQL.GetSingle(sSQL);
                                if (OMarkedState != null)
                                {
                                    //判断是否此种标示卡是否拉这种煤
                                    sSQL = "select MarkedCardState from TT_MarkedCard where MarkedCardNo='" + tenstring + "' " +
                                          " and CoalKindCode='" + CollCode + "'";
                                    object oExits = DbHelperSQL.GetSingle(sSQL);
                                    if (oExits != null)
                                    {
                                        string state = OMarkedState.ToString();
                                        if (state == "2")
                                        {
                                            //在此种状态下,才开始进行数据处理;
                                            strFactoryCode += tenstring + "|";
                                            strExistFactoryCode += tenstring + "|";
                                            strExistMarkedCode += resultSql + "|";
                                            iCardCount += 1;
                                            Log(ByteArrayToHexString(buffer), resultSql, tenstring);
                                        }
                                        else if (state == "1")
                                            alarmSound.Alarm("该标识卡是未使用状态不能再次发放");
                                        else if (state == "3")
                                            alarmSound.Alarm("该标识卡已挂失");
                                        else if (state == "4")
                                            alarmSound.Alarm("该标识卡已吊销");
                                    }
                                    else
                                    {
                                        alarmSound.Alarm("您刷得不是" + CollName + "的标识卡");
                                    }
                                }
                                else
                                {
                                    //对未添加的标示卡进行处理--加入信息
                                    strFactoryCode += tenstring + "|";
                                    strNewFactoryCode += tenstring + "|";
                                    strNewMarkedCode += resultSql + "|";
                                    iCardCount += 1;
                                    Log(ByteArrayToHexString(buffer), resultSql, tenstring);
                                }
                            }
                            else
                            {
                                alarmSound.Alarm("此标示卡已经刷过");
                            }
                        }

                        else
                        {
                            alarmSound.Alarm("您刷的不是标示卡");
                        }
                    }
                    else
                    {
                        alarmSound.Alarm("您刷卡数量已到达要购买数量");
                    }
                }
            }//if bytes
        }
Esempio n. 18
0
 /// <summary>
 /// 余额提醒时钟
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void tmAccount_Tick(object sender, EventArgs e)
 {
     #region 余额提醒
     RWini rwini = new RWini();
     string isNO = rwini.IniReadValue("ColieryAccount", "isNO");
     string interval = rwini.IniReadValue("ColieryAccount", "Interval");
     if (isNO == "true")
     {
         StringBuilder sb = new StringBuilder();
         List<string> list = GetColieryAccount();//获取数据库中煤矿的余额
         if (list.Count<=0)
         {
             tmAccount.Interval = 1000 * int.Parse(interval);//设置
             return;
         }
         for (int i = 0; i < list.Count; i++)
         {
             sb.Append(list[i]);
         }
         alarmSound.Alarm(sb.ToString());
         tmAccount.Interval = 1000 * int.Parse(interval);//设置
         MessageBox.Show(sb.ToString(), "天大天科", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
     }
     #endregion
 }
Esempio n. 19
0
        static void Main()
        {
            //int iProcessNum = 0;

            //foreach (Process singleProc in Process.GetProcesses())
            //{
            //    if (singleProc.ProcessName == Process.GetCurrentProcess().ProcessName)
            //    {
            //        iProcessNum += 1;
            //    }
            //}
            //if (iProcessNum > 1)
            //{
            //    MessageBox.Show("该程序已经在运行中!", "天大天科调运系统", MessageBoxButtons.OK, MessageBoxIcon.Information);
            //}
            //else
            //{
            //    RWini ini = new RWini();
            //    string strIsSet = ini.IniReadValue("Connection", "isSet");
            //    Application.EnableVisualStyles();
            //    Application.SetCompatibleTextRenderingDefault(false);

            //    if (strIsSet == "1")
            //    {
            //        if (new UserLogin().ShowDialog() == DialogResult.OK)
            //        {
            //            string strUserCode = StaticParameter.UserCode;
            //            Application.Run(new MainForm(strUserCode));
            //        }
            //    }
            //    else if (strIsSet == "0")
            //    {
            //        if (new Settings.DataBaseInitial().ShowDialog() == DialogResult.OK)
            //        {
            //            Application.Run(new UserLogin("0"));
            //        }
            //    }

            //}

            RWini ini = new RWini();
            string strIsSet = ini.IniReadValue("Connection", "isSet");
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            if (strIsSet == "1")
            {
                if (new UserLogin().ShowDialog() == DialogResult.OK)
                {
                    string strUserCode = StaticParameter.UserCode;
                    Application.Run(new MainForm());
                }
            }
            else if (strIsSet == "0")
            {
                if (new Settings.DataBaseInitial().ShowDialog() == DialogResult.OK)
                {
                    Application.Run(new UserLogin("0"));
                }
            }
        }
 /// <summary>
 /// 获取过磅编号(格式1-4位磅称,5-18位年月日时分秒 如000120080808080808)
 /// </summary>
 /// <param name="TableName">表名</param>
 /// <param name="KeyName">主键名</param>
 /// <returns></returns>
 public static string getMaxBangID()
 {
     try
     {
         DateTime dtTime = Convert.ToDateTime(DbHelperSQL.GetSingle("select getdate()"));
         string RoomCode = new RWini().IniReadValue("RoomSetting", "RoomCode");
         return RoomCode.PadLeft(4, '0') + dtTime.ToString("yyyyMMddHHmmss");
     }
     catch
     {
         return "";
     }
 }
        private void NavicertSearch_Load(object sender, EventArgs e)
        {
            string strRoomCode = new RWini().IniReadValue("RoomSetting", "RoomCode");
            this.grdNavicert.AutoGenerateColumns = false;
            CommonMethod.ComboxBind(this.cbxRoomCode, "TT_Room", "RoomName", "RoomCode", "RoomType ='1' and IsForBid ='0' and Remark !='0'", "RoomName", "请选择计量站", "-1");
            //this.cbxRoomCode.Enabled = false;
            CommonMethod.ComboxBind(this.cbxSendPerson, "VT_NavicertPerson", "SendPerson", "SPerson", "1=1 and RoomCode = '" + cbxRoomCode.SelectedValue.ToString() + "'", "SendPerson asc", "请选择发卡人", "-1");

            this.cbxStartTime.Text = DateTime.Now.AddMonths(-1).ToShortDateString();
            this.cbxEndTime.Text = DateTime.Now.ToShortDateString();

            loadData();
        }
 /// <summary>
 /// 提示信息显示
 /// </summary>
 /// <param name="Text">提示信息</param>
 /// <param name="buttons">按钮显示</param>
 /// <param name="icon">图标显示</param>
 public static DialogResult MessageBox(string Text, MessageBoxButtons buttons, MessageBoxIcon icon)
 {
     string Caption = new RWini().IniReadValue("SysInfo", "MessageCaption");
     return System.Windows.Forms.MessageBox.Show(Text, Caption, buttons, icon);
 }
        /// <summary>
        /// ping 网络
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void PingIP(object sender, EventArgs e)
        {
            RWini ini = new RWini();
            string ip = ini.IniReadValue("Connection", "SServer");
            if (GetCmdPingResult(ip) == "1")
            {

                timer.Interval = 60000;
                string strIp = ini.IniReadValue("Connection", "isConnection");
                if (strIp != "0")
                {
                    ini.IniWriteValue("Connection", "isConnection", CommonMethod.ToDBC("0"));
                    //从新添加
                    MessageBox.Show("本系统与服务器已连接,点击确定后,请从新登录!");
                    Application.ExitThread();
                    Application.Exit();
                }
            }
            else
            {
                timer.Interval = 20000;
                string strIp = ini.IniReadValue("Connection", "isConnection");
                if (strIp == "0")
                {
                    ini.IniWriteValue("Connection", "isConnection", CommonMethod.ToDBC("1"));
                    MessageBox.Show("本系统与服务器断开连接,不能过磅,请联系中心机房!");
                    Application.ExitThread();
                    Application.Exit();

                }
            }
        }
        /// <summary>
        /// 刷卡事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void txtMarkedCode_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == System.Windows.Forms.Keys.Enter)
            {
                if ((Convert.ToInt32(txtAdded.Text)) < (Convert.ToInt32(txtActiveCount.Text)))
                {
                    if (txtMarkedCode.Text.Trim().Length == 10)
                    {
                        if (!arraylist.Contains(txtMarkedCode.Text.Trim()))
                        {

                            string sql = "select count(CardID) from dbo.TT_InitialCard where CardID='" + txtMarkedCode.Text.Trim() + "'" + "  and CardType='1'";
                            int result = (int)DbHelperSQL.GetSingle(sql);
                            if (result > 0)
                            {
                                 string cardNum = "select COUNT(MarkedCardCode) from dbo.TT_MarkedCard where MarkedCardCode='" + txtMarkedCode.Text.Trim() + "' ";
                                int resultNum =Convert.ToInt32(DbHelperSQL.GetSingle(cardNum));
                                if (resultNum == 0)
                                {
                                    MessageBox.Show("此卡未发放,请联系管理员查询", "天大天科");
                                    txtMarkedCode.Text = "";
                                    return;
                                }
                                #region 激活时间判断
                                string strTime = "SELECT DATEDIFF(DAY, (select [SendCardDate] from [CoalTraffic].[dbo].[TT_MarkedCard] where [MarkedCardNo]='" + txtMarkedCode.Text.Trim() + "'), GETDATE())";//查询发卡时间和现在时间只差是多少天
                                object objTime = DbHelperSQL.GetSingle(strTime);
                                int CardTime = (int)objTime;//将时间转换为整数型
                                RWini ini = new RWini();
                                int days = int.Parse(ini.IniReadValue("ActiveMarkedCard", "days"));
                                if (CardTime < days)
                                {
                                    txtMarkedCode.Text = "";
                                    alarmSound.Alarm("此 卡 的 使 用 时 间 还 没 有 到,还 差 " + (days - CardTime).ToString() + " 天 才 可 以 使 用");
                                    MessageBox.Show("此 卡 的 使 用 时 间 还 没 有 到,还 差 " + (days - CardTime).ToString() + " 天 才 可 以 使 用");
                                    return;
                                }
                                #endregion

                                //如果标识卡的状态为0,那么就表示该卡未经过验证。需要验证后才可以激活。1:已经激活,单位使用;2:已经使用;0:已经使用,并且经过验证
                                string sql2 = "select MarkedCardState from dbo.TT_MarkedCard where MarkedCardCode='" + txtMarkedCode.Text.Trim() + "'";
                                int result2 =Convert.ToInt32(DbHelperSQL.GetSingle(sql2));
                                if (result2 == 2)
                                {
                                    MessageBox.Show("此卡未验证,请联系管理员查询", "天大天科");
                                    txtMarkedCode.Text = "";
                                    return;
                                }
                                else if (result2 == 1)
                                {
                                    MessageBox.Show("此卡未使用,请联系管理员查询", "天大天科");
                                    txtMarkedCode.Text = "";
                                    return;
                                }
                                else if (result2 == 0)
                                {
                                    arraylist.Add(txtMarkedCode.Text.Trim());
                                    txtMarkedCode.Text = "";
                                    skNumber += 1;
                                    txtAdded.Text = skNumber.ToString();
                                }
                                else
                                {
                                    MessageBox.Show("此卡为非法卡,请联系管理员查询", "天大天科");
                                    txtMarkedCode.Text = "";
                                    return;
                                }

                            }
                            else
                            {
                                MessageBox.Show("此卡没有初始化,请联系管理员。", "天大天科");
                                //this.Close();
                                txtMarkedCode.Text = "";
                                return;
                            }

                        }
                        else
                        {
                            MessageBox.Show("此卡已刷过了!", "天大天科");
                            txtMarkedCode.Text = "";
                            //return;
                        }

                    }
                }
                else
                {
                    txtMarkedCode.ReadOnly = true;
                    //alarmSound.Alarm("您已经刷卡超过您的购买数量");
                    MessageBox.Show("您已经刷卡超过您的购买数量  请点击发卡按钮");
                    txtMarkedCode.Text = "";
                    //return;
                }
            }
        }
Esempio n. 25
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            lblUserName.Text = ini.IniReadValue("LoginInfo", "UserName");
            lblDepartName.Text = ini.IniReadValue("LoginInfo", "DepartName");

            strRights = CommonMethod.GetOperatorPosition(StaticParameter.UserCode);
            initToolStrip();
            initMenu();

            #region 余额提醒
            RWini rwini = new RWini();
            string isNO = rwini.IniReadValue("ColieryAccount", "isNO");
            if (isNO=="true")
            {
                List<string> list = GetColieryAccount();//获取数据库中煤矿的余额
                for (int i = 0; i < list.Count; i++)
                {
                    MessageBox.Show(list[i], "天大天科", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
            }
            #endregion
        }
        private void LoadWeightSearch_Load(object sender, EventArgs e)
        {
            #region 绑定相关控件
            strRoomCode = new RWini().IniReadValue("RoomSetting", "RoomCode");

            CommonMethod.ComboxBind(this.cmbRoom, "TT_Room", "RoomName", "RoomCode", "RoomType>0 and IsForbid='0' and Remark !='0'", "RoomName", "请选择计量站", "-1");
            this.cmbRoom.SelectedValue = strRoomCode;
            if (StaticParameter.UserCode == "0"||this.strDepart=="监控中心")
            {
                this.cmbRoom.Enabled = true;
            }
            CommonMethod.ComboxBind(this.cmbCoalName, "Sys_Colliery", "CollName", "CollCode", "IsForbid='0'", "CollName", "请选择企业", "0");
            CommonMethod.ComboxBind(this.cmbCoalKind, "TT_CoalKind", "CoalkindName", "CoalKindCode", "IsForbid='0'", "CoalkindName asc", "请选择产品", "0");
            CommonMethod.ComboxBind(cmbOperator, "VT_LoadWeightOfOperator", "Operator", "OperatorSam", "RoomCode='" + strRoomCode + "'", "Operator asc", "请选择司磅员", "-1");

            this.dtpBegin.Text = DateTime.Now.ToShortDateString();
            this.dtpEnd.Text = DateTime.Now.ToShortDateString();

            this.dgvWeightBang.AutoGenerateColumns = false;
            #endregion

            #region 绑定过磅类型
            DataTable dt = new DataTable();
            dt.Columns.Add("BangTypeName");
            dt.Columns.Add("BangTypeCode");

            DataRow dr4 = dt.NewRow();
            dr4["BangTypeName"] = "请选择类型";
            dr4["BangTypeCode"] = "-1";
            dt.Rows.Add(dr4);

            #region 判断该站是不是企业端计量站
            StringBuilder sbselectsql = new StringBuilder();
            sbselectsql.Append("select count(*) from TT_Room");
            sbselectsql.Append(" where RoomType='2' and RoomCode ='" + strRoomCode + "'");

            object OCount = DbHelperSQL.GetSingle(sbselectsql.ToString());

            if (int.Parse(OCount.ToString()) != 0)
            {
                DataRow dr2 = dt.NewRow();
                dr2["BangTypeName"] = "重车验票";
                dr2["BangTypeCode"] = "3";
                dt.Rows.Add(dr2);

                if (StaticParameter.RightList.Contains("s2303") || StaticParameter.RightList.Contains("s2304") || StaticParameter.RightList.Contains("s2309"))
                {
                    DataRow dr3 = dt.NewRow();
                    dr3["BangTypeName"] = "散煤验票";
                    dr3["BangTypeCode"] = "4";
                    dt.Rows.Add(dr3);
                }
            }
            #endregion

            DataRow dr = dt.NewRow();
            dr["BangTypeName"] = "重车过磅";
            dr["BangTypeCode"] = "1";
            dt.Rows.Add(dr);

            if (StaticParameter.RightList.Contains("s2205") || StaticParameter.RightList.Contains("s2206") || StaticParameter.RightList.Contains("s2213"))
            {
                DataRow dr1 = dt.NewRow();
                dr1["BangTypeName"] = "散煤过磅";
                dr1["BangTypeCode"] = "2";
                dt.Rows.Add(dr1);
            }

            cmbBangType.DataSource = dt;
            cmbBangType.DisplayMember = "BangTypeName";
            cmbBangType.ValueMember = "BangTypeCode";
            #endregion

            loadData();
        }
        private void MarkedCardSearch_Load(object sender, EventArgs e)
        {
            #region 绑定相关控件
            strRoomCode = new RWini().IniReadValue("RoomSetting", "RoomCode");

            //CommonMethod.ComboxBind(this.cmbRoom, "TT_Room", "RoomName", "RoomCode", "IsForbid='0'", "RoomName", "请选择验票站", "-1");
            if (strRoomCode != "")
            {
                this.cmbRoom.SelectedValue = strRoomCode;
            }
            #region 是否锁定选择计量站
            if (ini.IniReadValue("SysInfo", "FormType") == "1")
            {
                if (StaticParameter.UserCode != "0")
                {
                    this.cmbRoom.Enabled = false;
                }
            }
            else if (ini.IniReadValue("SysInfo", "FormType") == "2") //如果是验票站就让用户可以选择
            {
                if (StaticParameter.UserCode != "0")
                {
                    this.cmbRoom.Enabled = true;
                    label1.Text = "计 量 站:";
                }
            }
            #endregion

            CommonMethod.ComboxBind(this.cmbRoom, "Sys_Colliery", "CollName", "CollCode", "IsForbid='0'", "CollName", "请选择煤矿", "0");
            CommonMethod.ComboxBind(this.cmbCoalKind, "TT_CoalKind", "CoalkindName", "CoalKindCode", "IsForbid='0'", "CoalkindName asc", "请选择煤种", "0");
            //CommonMethod.ComboxBind(cmbOperator, "VT_LoadWeightOfOperator", "Operator", "OperatorSam", "RoomCode='" + strRoomCode + "'", "Operator asc", "请选择司磅员", "-1");

            this.dtpBegin.Text = DateTime.Now.ToShortDateString();
            this.dtpEnd.Text = DateTime.Now.ToShortDateString();

            this.dgvMarkedCardSearch.AutoGenerateColumns = false;
            #endregion

            //#region 绑定过磅类型
            //DataTable dt = new DataTable();
            //dt.Columns.Add("BangTypeName");
            //dt.Columns.Add("BangTypeCode");

            //DataRow dr4 = dt.NewRow();
            //dr4["BangTypeName"] = "请选择类型";
            //dr4["BangTypeCode"] = "-1";
            //dt.Rows.Add(dr4);

            #region 判断该站是不是煤矿端计量站
            StringBuilder sbselectsql = new StringBuilder();
            sbselectsql.Append("select count(*) from TT_Room");
            sbselectsql.Append(" where RoomType='2' and RoomCode ='" + strRoomCode + "'");

            object OCount = DbHelperSQL.GetSingle(sbselectsql.ToString());

            //if (int.Parse(OCount.ToString()) != 0)
            //{
            //    DataRow dr2 = dt.NewRow();
            //    dr2["BangTypeName"] = "重车验票";
            //    dr2["BangTypeCode"] = "3";
            //    dt.Rows.Add(dr2);

            //    if (StaticParameter.RightList.Contains("s2303") || StaticParameter.RightList.Contains("s2304") || StaticParameter.RightList.Contains("s2309"))
            //    {
            //        DataRow dr3 = dt.NewRow();
            //        dr3["BangTypeName"] = "散煤验票";
            //        dr3["BangTypeCode"] = "4";
            //        dt.Rows.Add(dr3);
            //    }
            //}
            //#endregion

            //DataRow dr = dt.NewRow();
            //dr["BangTypeName"] = "重车过磅";
            //dr["BangTypeCode"] = "1";
            //dt.Rows.Add(dr);

            //if (StaticParameter.RightList.Contains("s2205") || StaticParameter.RightList.Contains("s2206") || StaticParameter.RightList.Contains("s2213"))
            //{
            //    DataRow dr1 = dt.NewRow();
            //    dr1["BangTypeName"] = "散煤过磅";
            //    dr1["BangTypeCode"] = "2";
            //    dt.Rows.Add(dr1);
            //}

            //cmbBangType.DataSource = dt;
            //cmbBangType.DisplayMember = "BangTypeName";
            //cmbBangType.ValueMember = "BangTypeCode";
            //#endregion

            loadData();
        }