예제 #1
0
        /*
         * private void Out_house_Click(object sender, EventArgs e)
         * {
         *
         *  if (Out_count.Text.Trim() == String.Empty || Out_data.Text.Trim() == String.Empty ||
         *       Out_name.Text.Trim() == String.Empty ||
         *      Out_number.Text.Trim() == String.Empty || Out_person.Text.Trim() == String.Empty)
         *  {
         *      Out_show.Text = "信息填写不完整,请填写完后重新出库!";
         *  }
         *  else if (IsOpened == false)
         *  {
         *      Out_show.Text = "请先打开串口!";
         *  }
         *  else
         *  {
         *
         *      OleDbConnection conn = new OleDbConnection();
         *      conn.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\mydata.mdb;Persist Security Info=True";
         *      conn.Open();
         *      Int32 b = Convert.ToInt32(Out_count.Text.Trim());
         *      String count = String.Format("SELECT * FROM tab_house_in WHERE InCount={0}", b);
         *      OleDbCommand cmd = new OleDbCommand(count, conn);
         *      OleDbDataReader dr = cmd.ExecuteReader();
         *      if (dr.Read())
         *      {
         *          if (((String)dr["InName"]).Trim() == Out_name.Text.Trim())
         *          {
         *              if ((int)dr["InNumber"] < Int32.Parse(Out_number.Text.Trim()))
         *              {
         *                  Out_show.Text = "很抱歉,库存不足!";
         *              }
         *              else
         *              {
         *                  Int32 d = Convert.ToInt32(Out_number.Text.Trim());
         *                  Int32 f = Convert.ToInt32(Out_number.Text.Trim());
         *                  String num = String.Format("UPDATE tab_house_in SET InNumber=InNumber-{0} WHERE InCount={1}", d, f);
         *                  OleDbCommand cmd_num = new OleDbCommand(num, conn);
         *                  cmd_num.ExecuteReader();
         *                  Int32 coun = Convert.ToInt32(Out_count.Text.Trim());
         *                  Int32 house = (int)dr["InHouseName"];
         *                  Int32 number = Convert.ToInt32(Out_number.Text.Trim());
         *                  String insert = String.Format("insert into [tab_house_out] (OutCount,OutName,OutHouseName,OutGiver,OutNumber,OutData,OutPerson) values('{0}','{1}','{2}','{3}','{4}','{5}','{6}')",
         *                    coun, (String)dr["InName"], house, (String)dr["InGiver"], number, Out_data.Text.Trim(), Out_person.Text.Trim());
         *                  OleDbCommand insert_out = new OleDbCommand(insert, conn);
         *                  insert_out.ExecuteReader();
         *                  Out_show.Text = "出库成功!";
         *              }
         *
         *          }
         *          else
         *          {
         *              Out_show.Text = "此编号信息不符,请仔细检查!";
         *          }
         *
         *      }
         *      else
         *      {
         *          Out_show.Text = "仓库中不存在此物品,请注意核查!";
         *      }
         *      conn.Close();
         *      conn = null;
         *      cmd = null;
         *      dr = null;
         *  }
         *
         * }
         */
        private void mainform_Load(object sender, EventArgs e)
        {
            // TODO: 这行代码将数据加载到表“mydataDataSet.tab_house_in”中。您可以根据需要移动或删除它。
            l_user.Text = "admin";
            int num = -1;

            for (int i = 2; i < 15; i++)
            {
                Int32 value = reader.OpenSerialPort("COM" + i, 115200);
                if (value == 0)
                {
                    num = i;
                    break;
                }
                else
                {
                    num = 5;
                }
            }
            if (num == 0)
            {
                port_show.Text = "未读取到串口,请检查设备后重新登录";
            }
            else
            {
                cmb_port.SelectedIndex = num - 1;
                cmb_baud.SelectedIndex = 4;
                port_show.Text         = "已自动匹配好串口和波特率!";
                IsOpened          = true;
                DT1               = System.DateTime.Now;
                dt                = System.DateTime.Today.ToString("yyyy/MM/dd");
                l_start_time.Text = dt;
            }
            // this.tab_house_inTableAdapter.Fill(this.mydataDataSet.tab_house_in);
            //   dataGridView2.DataSource = null;
        }
예제 #2
0
        private void my_button_Click(object sender, EventArgs e)
        {
            Button button = (Button)sender;
            String s      = null;

            main_text.Text = "";

            switch (button.Name)
            {
            case "logout_button":
                this.Dispose();
                Login.login.Show();
                break;

            case "exit_button":
                SendMessage(this.Handle, WM_CLOSE, 0, 0);
                break;

            case "main_open_com":
                if (IsConnected == true)
                {
                    main_remain.Text = "串口已经打开,不能重复打开串口!";
                    return;
                }
                if (main_com_box.SelectedIndex < 0)
                {
                    main_remain.Text = "请选择一个串口";
                    main_com_box.Focus();
                    return;
                }
                if (main_rate_box.SelectedIndex < 0)
                {
                    main_remain.Text = "请选择波特率";
                    main_rate_box.Focus();
                    return;
                }

                int open_value = reader.OpenSerialPort(main_com_box.SelectedItem.ToString(), Int32.Parse(main_rate_box.SelectedItem.ToString()));
                if (open_value == 0)
                {
                    main_remain.Text            = String.Format("串口{0}打开成功!", main_com_box.Text.Trim());
                    main_open_com.Enabled       = false;
                    main_close_com.Enabled      = true;
                    main_in_button.Enabled      = true;
                    main_out_button.Enabled     = true;
                    main_repair_button.Enabled  = true;
                    main_destroy_button.Enabled = true;
                    monitor_start.Enabled       = true;
                    monitor_stop.Enabled        = true;

                    IsConnected = true;
                }
                else
                {
                    main_remain.Text = String.Format("串口{0}打开失败!", main_com_box.Text.Trim());
                    IsConnected      = false;
                }
                break;

            case "main_close_com":
                if (IsConnected == false)
                {
                    main_remain.Text = "串口已经关闭!";
                    return;
                }
                else
                {
                    int close_value = 0;
                    if (close_value == 0)
                    {
                        IsConnected             = false;
                        main_remain.Text        = String.Format("串口{0}成功关闭!", main_com_box.Text.Trim());
                        main_open_com.Enabled   = true;
                        main_close_com.Enabled  = false;
                        main_in_button.Enabled  = false;
                        main_out_button.Enabled = false;
                        monitor_start.Enabled   = false;
                        monitor_stop.Enabled    = false;
                    }
                    else
                    {
                        main_remain.Text = String.Format("串口{0}关闭失败!", main_com_box.Text.Trim());
                    }
                }
                break;

            case "main_refresh":
                readFromDb(-1);
                list.Clear();
                break;

            case "main_save":
                foreach (string id in list)
                {
                    if (n == 0)
                    {
                        s = String.Format("delete from " + table[n] + " where " + key[n] + " = '{0}'", id);
                    }

                    if (n != 0)
                    {
                        //SELECT * from [Out] where FORMAT(Time,'yyyy.MM.dd HH:mm:ss')= '2018.12.16 10:43:55' ;
                        s = String.Format("delete from " + table[n] + " where FORMAT(" + key[n] + ",'yyyy.MM.dd HH:mm:ss') = '{0}'", id);
                    }
                    //"delete from [Gun] where TagId = "+TagId;
                    command = new OleDbCommand(s, connection);
                    int num = command.ExecuteNonQuery();
                    command          = null;
                    main_remain.Text = String.Format("您已成功删除 {0} 条记录", num);
                }
                break;

            case "main_del":
                if (this.dataGrid.SelectedRows.Count > 0)
                {
                    for (int i = 0; i < dataGrid.Rows.Count; i++)
                    {
                        if (true == dataGrid.Rows[i].Selected)
                        {
                            list.Add(dataGrid.Rows[i].Cells[0].Value.ToString());
                            dataGrid.Rows.RemoveAt(i);
                        }
                    }
                }
                break;

            case "main_cancel":
                main_refresh.PerformClick();
                list.Clear();
                break;
            }
        }