private void ret_btn3_Click(object sender, EventArgs e) { //点击返回保存用户设置 INIhelp.SetValue("当前用户", comboBox1.Text); INIhelp.SetValue("背光时间", textBox1.Text); INIhelp.SetValue("时钟设置", dateTimePicker2.Text); INIhelp.SetValue("修改密码", textBox2.Text); INIhelp.SetValue("蜂鸣器", comboBox2.Text); INIhelp.SetValue("修改加密锁", textBox3.Text); if (INIhelp.GetValue("当前用户") != "管理员权限") { MainSettingForm.flag = true; } else { MainSettingForm.flag = false; } this.Close(); this.DialogResult = DialogResult.OK; }
/// <summary> /// 保存设置(下发指令并且设置保存) /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button1_Click(object sender, EventArgs e) { //统统往下丢指令 //X轴上限 string str1 = textBox1.Text; if (str1 == "") { return; } int id1 = Convert.ToInt32(str1); byte[] iByte1 = toBytes.intToBytes(id1);//4位 //X轴下限 string str2 = textBox4.Text; if (str2 == "") { return; } int id2 = Convert.ToInt32(str2); byte[] iByte2 = toBytes.intToBytes(id2);//4位 //Y轴上限 string str5 = textBox8.Text; if (str5 == "") { return; } int id5 = Convert.ToInt32(str5); byte[] iByte5 = toBytes.intToBytes(id5);//4位 //Y轴下限 string str6 = textBox6.Text; if (str6 == "") { return; } int id6 = Convert.ToInt32(str6); byte[] iByte6 = toBytes.intToBytes(id6);//4位 //Z轴上限 string str3 = textBox2.Text; if (str3 == "") { return; } int id3 = Convert.ToInt32(str3); byte[] iByte3 = toBytes.intToBytes(id3);//4位 //Z轴下限 string str4 = textBox5.Text; if (str4 == "") { return; } int id4 = Convert.ToInt32(str4); byte[] iByte4 = toBytes.intToBytes(id4);//4位 //O轴上限 string str7 = textBox9.Text; if (str7 == "") { return; } int id7 = Convert.ToInt32(str7); byte[] iByte7 = toBytes.intToBytes(id7);//4位 //O轴下限 string str8 = textBox7.Text; if (str8 == "") { return; } int id8 = Convert.ToInt32(str8); byte[] iByte8 = toBytes.intToBytes(id8);//4位 ////将四轴的开关状态写进一个字节发送出去 //string[] status = new string[4]; //try //{ // if (comboBox2.Text.Equals("开")) // { // status[0] = "1"; // } // if (comboBox2.Text.Equals("关")) // { // status[0] = "0"; // } // if (comboBox1.Text.Equals("开")) // { // status[1] = "1"; // } // if (comboBox1.Text.Equals("关")) // { // status[1] = "0"; // } // if (comboBox3.Text.Equals("开")) // { // status[2] = "1"; // } // if (comboBox3.Text.Equals("关")) // { // status[2] = "0"; // } // if (comboBox4.Text.Equals("开")) // { // status[3] = "1"; // } // if (comboBox4.Text.Equals("关")) // { // status[3] = "0"; // } //} //catch //{ //} //string status2 = string.Join("",status); //int a = Convert.ToInt32(status2, 2); //byte[] b = toBytes.intToBytes(a); BF.sendbuf[0] = 0xFA; BF.sendbuf[1] = 0x21; BF.sendbuf[2] = 0x0B; BF.sendbuf[3] = iByte1[3]; BF.sendbuf[4] = iByte1[2]; BF.sendbuf[5] = iByte1[1]; BF.sendbuf[6] = iByte1[0]; BF.sendbuf[7] = iByte2[3]; BF.sendbuf[8] = iByte2[2]; BF.sendbuf[9] = iByte2[1]; BF.sendbuf[10] = iByte2[0]; BF.sendbuf[11] = iByte5[3]; BF.sendbuf[12] = iByte5[2]; BF.sendbuf[13] = iByte5[1]; BF.sendbuf[14] = iByte5[0]; BF.sendbuf[15] = iByte6[3]; BF.sendbuf[16] = iByte6[2]; BF.sendbuf[17] = iByte6[1]; BF.sendbuf[18] = iByte6[0]; BF.sendbuf[19] = iByte3[3]; BF.sendbuf[20] = iByte3[2]; BF.sendbuf[21] = iByte3[1]; BF.sendbuf[22] = iByte3[0]; BF.sendbuf[23] = iByte4[3]; BF.sendbuf[24] = iByte4[2]; BF.sendbuf[25] = iByte4[1]; BF.sendbuf[26] = iByte4[0]; BF.sendbuf[27] = iByte7[3]; BF.sendbuf[28] = iByte7[2]; BF.sendbuf[29] = iByte7[1]; BF.sendbuf[30] = iByte7[0]; BF.sendbuf[31] = iByte8[3]; BF.sendbuf[32] = iByte8[2]; BF.sendbuf[33] = iByte8[1]; BF.sendbuf[34] = iByte8[0]; BF.sendbuf[35] = 0xF5; SendMenuCommand(BF.sendbuf, 36); //更新到配置文件里 INIhelp.SetValue("X轴上限位", textBox1.Text); INIhelp.SetValue("X轴下限位", textBox4.Text); INIhelp.SetValue("Z轴上限位", textBox2.Text); INIhelp.SetValue("Z轴下限位", textBox5.Text); INIhelp.SetValue("Y轴上限位", textBox8.Text); INIhelp.SetValue("Y轴下限位", textBox6.Text); INIhelp.SetValue("O轴上限位", textBox9.Text); INIhelp.SetValue("O轴下限位", textBox7.Text); }
/// <summary> /// 保存指示灯状态,怎么遍历简化代码? /// </summary> private void saveStatus() { if (button3.BackColor == Color.Transparent) { INIhelp.SetValue(GlobalV.sts3, "0"); } if (button3.BackColor == Color.Red) { INIhelp.SetValue(GlobalV.sts3, "1"); } if (button4.BackColor == Color.Transparent) { INIhelp.SetValue(GlobalV.sts4, "0"); } if (button4.BackColor == Color.Red) { INIhelp.SetValue(GlobalV.sts4, "1"); } if (button5.BackColor == Color.Transparent) { INIhelp.SetValue(GlobalV.sts5, "0"); } if (button5.BackColor == Color.Red) { INIhelp.SetValue(GlobalV.sts5, "1"); } if (button6.BackColor == Color.Transparent) { INIhelp.SetValue(GlobalV.sts6, "0"); } if (button6.BackColor == Color.Red) { INIhelp.SetValue(GlobalV.sts6, "1"); } if (button7.BackColor == Color.Transparent) { INIhelp.SetValue(GlobalV.sts7, "0"); } if (button7.BackColor == Color.Red) { INIhelp.SetValue(GlobalV.sts7, "1"); } if (button8.BackColor == Color.Transparent) { INIhelp.SetValue(GlobalV.sts8, "0"); } if (button8.BackColor == Color.Red) { INIhelp.SetValue(GlobalV.sts8, "1"); } if (button9.BackColor == Color.Transparent) { INIhelp.SetValue(GlobalV.sts9, "0"); } if (button9.BackColor == Color.Red) { INIhelp.SetValue(GlobalV.sts9, "1"); } if (button10.BackColor == Color.Transparent) { INIhelp.SetValue(GlobalV.sts10, "0"); } if (button10.BackColor == Color.Red) { INIhelp.SetValue(GlobalV.sts10, "1"); } if (button11.BackColor == Color.Transparent) { INIhelp.SetValue(GlobalV.sts11, "0"); } if (button11.BackColor == Color.Red) { INIhelp.SetValue(GlobalV.sts11, "1"); } if (button12.BackColor == Color.Transparent) { INIhelp.SetValue(GlobalV.sts12, "0"); } if (button12.BackColor == Color.Red) { INIhelp.SetValue(GlobalV.sts12, "1"); } if (button13.BackColor == Color.Transparent) { INIhelp.SetValue(GlobalV.sts13, "0"); } if (button13.BackColor == Color.Red) { INIhelp.SetValue(GlobalV.sts13, "1"); } if (button14.BackColor == Color.Transparent) { INIhelp.SetValue(GlobalV.sts14, "0"); } if (button14.BackColor == Color.Red) { INIhelp.SetValue(GlobalV.sts14, "1"); } if (button15.BackColor == Color.Transparent) { INIhelp.SetValue(GlobalV.sts15, "0"); } if (button15.BackColor == Color.Red) { INIhelp.SetValue(GlobalV.sts15, "1"); } if (button16.BackColor == Color.Transparent) { INIhelp.SetValue(GlobalV.sts16, "0"); } if (button16.BackColor == Color.Red) { INIhelp.SetValue(GlobalV.sts16, "1"); } if (button17.BackColor == Color.Transparent) { INIhelp.SetValue(GlobalV.sts17, "0"); } if (button17.BackColor == Color.Red) { INIhelp.SetValue(GlobalV.sts17, "1"); } }