private void btnSelect_Click(object sender, EventArgs e) { this.dataGridProtect.CurrentCell = null; this.dataGridSet.CurrentCell = null; this.dataGridShow.CurrentCell = null; frmList fl = new frmList(); if (fl.ShowDialog() == DialogResult.Yes) { if (!fl.isError) { cModeSet ModeSet; if (DataFileToClass(fl.ReturnId, out ModeSet, true)) { if (DataClassToFrm(this, ModeSet)) { frmMideaSn.mSnSet = (cSnSet)cXml.readXml(string.Format("{0}{1}.xml", frmMideaSn.SnIdDirectory, ModeSet.mId), typeof(cSnSet), frmMideaSn.mSnSet); return; } } MessageBox.Show("数据加载错误,将自动生成默认数据", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); if (File.Exists(fl.ReturnId)) { File.Delete(fl.ReturnId); } cModeSet modeSet = new cModeSet(); DataClassToFile(modeSet); DataClassToFrm(this, modeSet); } } fl.Dispose(); }
private string DataClassToStr(cModeSet modeSet) { string SendStr = "B~~0~"; SendStr = SendStr + modeSet.ToNetStr(); return(SendStr); }
//private string DataClassToStr(cSnSet snSet) //{ // string SendStr = "C~"; // SendStr += cSnSet.DataClassToStr(snSet); // return SendStr; //} private string DataClassToStr(cModeSet modeSet) { string SendStr = "B~~0~"; string str; frmSet.DataClassToFile(modeSet, out str); SendStr = SendStr + str; return(SendStr); }
private void btnSend_Click(object sender, EventArgs e) { cModeSet modeSet = new cModeSet(); modeSet.Load(cbbId.Text); frmSend f = new frmSend(modeSet); f.ShowDialog(); }
/// <summary> /// 将界面上的值写入到设定类 /// </summary> /// <param name="ModeSet">界面上的值写入到类,返回设置</param> /// <returns>bool,返回是否转换成功</returns> public bool DataFrmToClass(out cModeSet ModeSet) { bool isOk = false; cModeSet tmpModeSet = new cModeSet(); try { tmpModeSet.ID = cbbId.Text; tmpModeSet.Mode = txtMode.Text; tmpModeSet.Info = txtInfo.Text; tmpModeSet.JiQi = cbbMachine.SelectedIndex; tmpModeSet.LowSpeed = rbtDiFeng.Checked; tmpModeSet.BiaoZhunJi[0] = chkDoor1.Checked; tmpModeSet.BiaoZhunJi[1] = chkDoor2.Checked; tmpModeSet.BiaoZhunJi[2] = chkDoor3.Checked; for (int i = 0; i < tmpModeSet.KaiGuan.Length; i++) { tmpModeSet.KaiGuan[i] = chkSwitch[i].Checked; } tmpModeSet.Protect[0] = All.Class.Num.ToFloat(txtHiCur.Text); tmpModeSet.Protect[1] = All.Class.Num.ToFloat(txtHiPress.Text); for (int i = 0; i < tmpModeSet.XinHao.Length; i++) { tmpModeSet.XinHao[i] = chkXinHao[i].Checked; } tmpModeSet.Vol110V = rbt110V.Checked; for (int i = 0; i < tmpModeSet.DataShow.Length; i++) { tmpModeSet.DataShow[i] = chkShow[i].Checked; } for (int i = 0; i < 10; i++) { tmpModeSet.Step[i].Text = TmpStepStr[i].Text; tmpModeSet.Step[i].TestTime = All.Class.Num.ToInt(TmpStepStr[i].TestTime); tmpModeSet.Step[i].NengJi = All.Class.Num.ToInt(TmpStepStr[i].NengJi); tmpModeSet.Step[i].PinLv = All.Class.Num.ToInt(TmpStepStr[i].PinLv); tmpModeSet.Step[i].SnCode = TmpStepStr[i].SnCode; tmpModeSet.Step[i].StartCheck = All.Class.Num.ToBool(TmpStepStr[i].StartCheck); tmpModeSet.Step[i].EndCheck = All.Class.Num.ToBool(TmpStepStr[i].EndCheck); tmpModeSet.Step[i].StartInfo = TmpStepStr[i].StartInfo; tmpModeSet.Step[i].EndInfo = TmpStepStr[i].EndInfo; for (int j = 0; j < cMain.DataShow; j++) { tmpModeSet.Step[i].LowData[j] = All.Class.Num.ToFloat(TmpStepStr[i].LowData[j]); tmpModeSet.Step[i].HighData[j] = All.Class.Num.ToFloat(TmpStepStr[i].HighData[j]); } } isOk = true; } catch (Exception e) { All.Class.Error.Add(e); isOk = false; } ModeSet = tmpModeSet; return(isOk); }
private void btnSave_Click(object sender, EventArgs e) { cModeSet tmpMode = new cModeSet(); if (DataFrmToClass(out tmpMode)) { if (tmpMode.Save()) { MessageBox.Show("当前机型设置数据已成功保存.", "保存成功", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } } MessageBox.Show("数据保存错误,请检测数据是否正确后重新保存", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); }
private void ClassToFrm(cModeSet modeSet) { try { txtID.Text = modeSet.mId; txtMode.Text = modeSet.mMode; txtDescribe.Text = modeSet.mDescript; cbbVol.SelectedIndex = modeSet.mElect; cbbBzz.SelectedIndex = modeSet.mBiaoZhunJi; cbb24V.SelectedIndex = modeSet.m24V; cbbJiQi.SelectedIndex = modeSet.mJiQi; //保护 for (int i = 0; i < cMain.DataProtect; i++) { if (Grid1.Rows[i % (cMain.DataProtect / 2)].Cells[(int)Math.Floor((float)i * 2 / cMain.DataProtect) * 2].Value.ToString().Length > 0) { Grid1.Rows[i % (cMain.DataProtect / 2)].Cells[(int)Math.Floor((float)i * 2 / cMain.DataProtect) * 2 + 1].Value = modeSet.mProtect[i]; } } //步骤 for (int i = 0; i < Grid2.Rows.Count && i < modeSet.mStepId.Length; i++) { Grid2.Rows[i].Cells["RunMode"].Value = modeSet.mStepId[i]; Grid2.Rows[i].Cells["Times"].Value = modeSet.mSetTime[i]; Grid2.Rows[i].Cells["Code"].Value = modeSet.mSendStr[i]; for (int j = 0; j < cMain.DataKaiGuang; j++) { Grid2.Rows[i].Cells[string.Format("KaiGuan{0}", j + 1)].Value = modeSet.mKaiGuan[i, j]; } for (int j = 0; j < cMain.DataShow; j++) { Grid2.Rows[i].Cells[string.Format("Data{0}", j * 2 + 1)].Value = modeSet.mLowData[i, j]; Grid2.Rows[i].Cells[string.Format("Data{0}", j * 2 + 2)].Value = modeSet.mHighData[i, j]; } } //显示 for (int i = 0; i < cMain.DataShow; i++) { Grid3.Rows[0].Cells[i].Value = modeSet.mShow[i]; } } catch (Exception e) { cMain.WriteErrorToLog(e.ToString()); } }
private void btnSelect_Click(object sender, EventArgs e) { frmList fl = new frmList(); if (fl.ShowDialog() == DialogResult.Yes) { if (!fl.isError) { cModeSet ModeSet = new cModeSet(); if (ModeSet.Load(fl.ReturnId.Trim())) { DataClassToFrm(ModeSet); } } } fl.Dispose(); }
private cModeSet FrmToClass() { cModeSet result = new cModeSet(); result.mId = txtID.Text; result.mMode = txtMode.Text; result.mDescript = txtDescribe.Text; result.mElect = cbbVol.SelectedIndex; result.mBiaoZhunJi = cbbBzz.SelectedIndex; result.m24V = cbb24V.SelectedIndex; result.mJiQi = cbbJiQi.SelectedIndex; for (int i = 0; i < cMain.DataProtect / 2; i++) { result.mProtect[i] = Num.SingleParse(Grid1.Rows[i].Cells[1].Value); result.mProtect[cMain.DataProtect / 2 + i] = Num.SingleParse(Grid1.Rows[i].Cells[3].Value); } for (int i = 0; i < result.mStepId.Length && i < Grid2.Rows.Count; i++) { result.mStepId[i] = Grid2.Rows[i].Cells["RunMode"].Value.ToString(); result.mSetTime[i] = Num.IntParse(Grid2.Rows[i].Cells["Times"].Value); result.mSendStr[i] = Grid2.Rows[i].Cells["Code"].Value.ToString(); for (int j = 0; j < cMain.DataKaiGuang; j++) { result.mKaiGuan[i, j] = Num.BoolParse(Grid2.Rows[i].Cells[string.Format("KaiGuan{0}", j + 1)].Value); } for (int j = 0; j < cMain.DataShow; j++) { result.mLowData[i, j] = Num.SingleParse(Grid2.Rows[i].Cells[string.Format("Data{0}", j * 2 + 1)].Value); result.mHighData[i, j] = Num.SingleParse(Grid2.Rows[i].Cells[string.Format("Data{0}", j * 2 + 2)].Value); } } for (int i = 0; i < cMain.DataShow; i++) { result.mShow[i] = Num.BoolParse(Grid3.Rows[0].Cells[i].Value); } return(result); }
public static bool DataClassToFrm(frmSet mfrmSet, cModeSet mModeSet) { bool isOk = false; int i, j; //try //{ mfrmSet.cbbId.Text = mModeSet.mId; mfrmSet.txtMode.Text = mModeSet.mMode; mfrmSet.cbbElect.SelectedIndex = mModeSet.mElect; mfrmSet.cbbBZJ.SelectedIndex = mModeSet.mBiaoZhunJi; mfrmSet.chkBZJ1.Checked = mModeSet.mBiaoZhunJi1; mfrmSet.chkBZJ2.Checked = mModeSet.mBiaoZhunJi2; mfrmSet.chkBZJ3.Checked = mModeSet.mBiaoZhunJi3; mfrmSet.chkBZJ4.Checked = mModeSet.mBiaoZhunJi4; mfrmSet.chkBZJ5.Checked = mModeSet.mBiaoZhunJi5; mfrmSet.chkBZJ6.Checked = mModeSet.mBiaoZhunJi6; mfrmSet.cbb24V.SelectedIndex = mModeSet.m24V; mfrmSet.cbbMachine.SelectedIndex = mModeSet.mJiQi; for (i = 0; i < cMain.DataProtect; i++) { DataGridViewRow dr; if (i < 10) { if (mfrmSet.dataGridProtect.Rows[i].Cells[0].Value == null || mfrmSet.dataGridProtect.Rows[i].Cells[0].Value.ToString() == "") { continue; } dr = mfrmSet.dataGridProtect.Rows[i]; dr.Cells[1].Value = mModeSet.mProtect[i].ToString(); } else { if (mfrmSet.dataGridProtect.Rows[i - 10].Cells[2].Value == null || mfrmSet.dataGridProtect.Rows[i - 10].Cells[2].Value.ToString() == "") { continue; } dr = mfrmSet.dataGridProtect.Rows[i - 10]; dr.Cells[3].Value = mModeSet.mProtect[i].ToString(); } } for (i = 0; i < cModeSet.StepCount; i++) { DataGridViewRow dr = mfrmSet.dataGridSet.Rows[i]; dr.Cells[0].Value = mModeSet.mStepId[i]; dr.Cells[1].Value = mModeSet.mSetTime[i]; dr.Cells[2].Value = mModeSet.mSendStr[i]; for (j = 0; j < cMain.DataKaiGuang; j++) { dr.Cells[j + 3].Value = mModeSet.mKaiGuan[i, j]; } for (j = 0; j < cMain.DataShow * 2; j++) { if (j % 2 == 0) { dr.Cells[j + 3 + cMain.DataKaiGuang].Value = mModeSet.mLowData[i, j / 2]; } else { dr.Cells[j + 3 + cMain.DataKaiGuang].Value = mModeSet.mHighData[i, (j - 1) / 2]; } } } DataGridViewRow drShow = mfrmSet.dataGridShow.Rows[0]; for (i = 0; i < cMain.DataShow; i++) { drShow.Cells[i].Value = mModeSet.mShow[i]; } isOk = true; //} //catch (Exception exc) //{ // cMain.WriteErrorToLog("FrmSet DataClssToFrm is Error " + exc.ToString()); // isOk = false; //} return(isOk); }
public static bool DataFileToClass(string FileStr, out cModeSet ModeSet, bool isPath) { cModeSet mModeset = new cModeSet(); string readStr; if (isPath) { readStr = cMain.ReadFile(FileStr); } else { readStr = FileStr; } try { string[] tempStr; tempStr = readStr.Split('~'); int i, j, index = 0; mModeset.mId = tempStr[index++]; mModeset.mMode = tempStr[index++]; mModeset.mElect = Num.IntParse(tempStr[index++]); mModeset.mBiaoZhunJi = Num.IntParse(tempStr[index++]); mModeset.mBiaoZhunJi1 = Num.BoolParse(tempStr[index++]); mModeset.mBiaoZhunJi2 = Num.BoolParse(tempStr[index++]); mModeset.mBiaoZhunJi3 = Num.BoolParse(tempStr[index++]); mModeset.mBiaoZhunJi4 = Num.BoolParse(tempStr[index++]); mModeset.mBiaoZhunJi5 = Num.BoolParse(tempStr[index++]); mModeset.mBiaoZhunJi6 = Num.BoolParse(tempStr[index++]); mModeset.m24V = Num.IntParse(tempStr[index++]); mModeset.mJiQi = Num.IntParse(tempStr[index++]); for (i = 0; i < cMain.DataProtect; i++) { mModeset.mProtect[i] = Num.SingleParse(tempStr[index++]); } for (i = 0; i < cModeSet.StepCount; i++) { mModeset.mStepId[i] = tempStr[index++]; } for (i = 0; i < cModeSet.StepCount; i++) { mModeset.mSetTime[i] = Num.IntParse(tempStr[index++]); } for (i = 0; i < cModeSet.StepCount; i++) { mModeset.mSendStr[i] = tempStr[index++]; } for (i = 0; i < cMain.DataKaiGuang; i++) { for (j = 0; j < cModeSet.StepCount; j++) { if (tempStr[index++] == "√") { mModeset.mKaiGuan[j, i] = true; } else { mModeset.mKaiGuan[j, i] = false; } } } for (i = 0; i < cMain.DataShow * 2; i++) { for (j = 0; j < cModeSet.StepCount; j++) { if (i % 2 == 0) { mModeset.mLowData[j, i / 2] = Num.SingleParse(tempStr[index++]); } else { mModeset.mHighData[j, i / 2] = Num.SingleParse(tempStr[index++]); } } } for (i = 0; i < cMain.DataShow; i++) { mModeset.mShow[i] = Num.BoolParse(tempStr[index++]); } } catch { } ModeSet = mModeset; return(true); }
/// <summary> /// 将设置类转换成文本并保存起来 /// </summary> /// <param name="ModeSet">设置</param> /// <returns>是否保存成功</returns> public static bool DataClassToFile(cModeSet ModeSet)//将界面上的数据保存 { string temp; return(DataClassToFile(ModeSet, out temp)); }
public static bool DataClassToFile(cModeSet ModeSet, out string Str) { string temp = ""; string writeStr = ""; bool isOk = false; int i, j; string tempTime = "", tempSn = ""; try { writeStr = writeStr + ModeSet.mId + "~"; writeStr = writeStr + ModeSet.mMode + "~"; writeStr = writeStr + ModeSet.mElect.ToString() + "~"; writeStr = writeStr + ModeSet.mBiaoZhunJi.ToString() + "~"; writeStr = writeStr + ModeSet.mBiaoZhunJi1.ToString() + "~"; writeStr = writeStr + ModeSet.mBiaoZhunJi2.ToString() + "~"; writeStr = writeStr + ModeSet.mBiaoZhunJi3.ToString() + "~"; writeStr = writeStr + ModeSet.mBiaoZhunJi4.ToString() + "~"; writeStr = writeStr + ModeSet.mBiaoZhunJi5.ToString() + "~"; writeStr = writeStr + ModeSet.mBiaoZhunJi6.ToString() + "~"; writeStr = writeStr + ModeSet.m24V.ToString() + "~"; writeStr = writeStr + ModeSet.mJiQi.ToString() + "~"; for (i = 0; i < cMain.DataProtect; i++) { writeStr = writeStr + ModeSet.mProtect[i].ToString() + "~"; } for (i = 0; i < cModeSet.StepCount; i++) { writeStr = writeStr + ModeSet.mStepId[i] + "~"; tempTime = tempTime + ModeSet.mSetTime[i].ToString() + "~"; tempSn = tempSn + ModeSet.mSendStr[i] + "~"; } writeStr = writeStr + tempTime + tempSn; for (i = 0; i < cMain.DataKaiGuang; i++) { for (j = 0; j < cModeSet.StepCount; j++) { if (ModeSet.mKaiGuan[j, i]) { writeStr = writeStr + "√" + "~"; } else { writeStr = writeStr + "×" + "~"; } } } for (i = 0; i < cMain.DataShow * 2; i++) { for (j = 0; j < cModeSet.StepCount; j++) { if (i % 2 == 0) { writeStr = writeStr + ModeSet.mLowData[j, i / 2].ToString() + "~"; } else { writeStr = writeStr + ModeSet.mHighData[j, (i - 1) / 2].ToString() + "~"; } } } for (i = 0; i < cMain.DataShow; i++) { writeStr = writeStr + ModeSet.mShow[i].ToString() + "~"; } temp = writeStr; cMain.WriteFile(cMain.AppPath + "\\ID\\" + ModeSet.mId + ".txt", writeStr, false); isOk = true; } catch (Exception exc) { MessageBox.Show("FrmSet DataFrmToFile is Error " + exc.ToString()); temp = ""; isOk = false; } Str = temp; return(isOk); }
/// <summary> /// 将界面上的值写入到设定类 /// </summary> /// <param name="ModeSet">界面上的值写入到类,返回设置</param> /// <returns>bool,返回是否转换成功</returns> public static bool DataFrmToClass(frmSet mfrmSet, out cModeSet ModeSet) { cModeSet mModeSet = new cModeSet(); bool isOk = false; int i, j; //DataTable dt = new DataTable(); //dt = (DataTable)mfrmSet.dataGridProtect.DataSource; DataGridViewRow dr; try { mfrmSet.dataGridProtect.EndEdit(); mfrmSet.dataGridSet.EndEdit(); mModeSet.mId = mfrmSet.cbbId.Text; mModeSet.mMode = mfrmSet.txtMode.Text; mModeSet.mElect = mfrmSet.cbbElect.SelectedIndex; mModeSet.mBiaoZhunJi = mfrmSet.cbbBZJ.SelectedIndex; mModeSet.mBiaoZhunJi1 = mfrmSet.chkBZJ1.Checked; mModeSet.mBiaoZhunJi2 = mfrmSet.chkBZJ2.Checked; mModeSet.mBiaoZhunJi3 = mfrmSet.chkBZJ3.Checked; mModeSet.mBiaoZhunJi4 = mfrmSet.chkBZJ4.Checked; mModeSet.mBiaoZhunJi5 = mfrmSet.chkBZJ5.Checked; mModeSet.mBiaoZhunJi6 = mfrmSet.chkBZJ6.Checked; mModeSet.m24V = mfrmSet.cbb24V.SelectedIndex; mModeSet.mJiQi = mfrmSet.cbbMachine.SelectedIndex; for (i = 0; i < cMain.DataProtect; i++) { if (i < 10) { dr = mfrmSet.dataGridProtect.Rows[i]; mModeSet.mProtect[i] = Num.SingleParse(dr.Cells[1].Value); } else { dr = mfrmSet.dataGridProtect.Rows[i - 10]; mModeSet.mProtect[i] = Num.SingleParse(dr.Cells[3].Value); } } for (i = 0; i < cModeSet.StepCount; i++) { dr = mfrmSet.dataGridSet.Rows[i]; mModeSet.mStepId[i] = dr.Cells[0].Value.ToString(); mModeSet.mSetTime[i] = Num.IntParse(dr.Cells[1].Value); mModeSet.mSendStr[i] = dr.Cells[2].Value.ToString();; for (j = 0; j < cMain.DataKaiGuang; j++) { mModeSet.mKaiGuan[i, j] = (bool)dr.Cells[j + 3].Value; } for (j = 0; j < cMain.DataShow * 2; j++) { if (j % 2 == 0) { mModeSet.mLowData[i, j / 2] = Num.SingleParse(dr.Cells[j + 3 + cMain.DataKaiGuang].Value); } else { mModeSet.mHighData[i, (j - 1) / 2] = Num.SingleParse(dr.Cells[j + 3 + cMain.DataKaiGuang].Value); } } } dr = mfrmSet.dataGridShow.Rows[0]; for (i = 0; i < cMain.DataShow; i++) { mModeSet.mShow[i] = (bool)dr.Cells[i].Value; } isOk = true; } catch (Exception exc) { cMain.WriteErrorToLog("FrmSet DataFrmToClass is Error " + exc.ToString()); isOk = false; } ModeSet = mModeSet; return(isOk); }
public frmSend(cModeSet mModeSet) { modeSet = mModeSet; InitializeComponent(); }
private bool DataClassToFrm(cModeSet mModeSet) { changeValue = false; bool isOk = false; cbbId.Text = mModeSet.ID; cbbMachine.SelectedIndex = mModeSet.JiQi; txtMode.Text = mModeSet.Mode; txtInfo.Text = mModeSet.Info; chkDoor1.Checked = mModeSet.BiaoZhunJi[0]; chkDoor2.Checked = mModeSet.BiaoZhunJi[1]; chkDoor3.Checked = mModeSet.BiaoZhunJi[2]; rbtDiFeng.Checked = mModeSet.LowSpeed; rbtGaoFeng.Checked = !mModeSet.LowSpeed; for (int i = 0; i < mModeSet.KaiGuan.Length; i++) { chkSwitch[i].Checked = mModeSet.KaiGuan[i]; } txtHiCur.Text = mModeSet.Protect[0].ToString("F2"); txtHiPress.Text = mModeSet.Protect[1].ToString("F3"); for (int i = 0; i < mModeSet.XinHao.Length; i++) { chkXinHao[i].Checked = mModeSet.XinHao[i]; } rbt110V.Checked = mModeSet.Vol110V; rbt220V.Checked = !mModeSet.Vol110V; for (int i = 0; i < mModeSet.DataShow.Length; i++) { chkShow[i].Checked = mModeSet.DataShow[i]; txtLow[i].Enabled = mModeSet.DataShow[i]; txtHigh[i].Enabled = mModeSet.DataShow[i]; } for (int i = 0; i < mModeSet.Step.Length; i++) { if (mModeSet.Step[i].Text != "") { tabControl1.TabPages[i + 1].Text = string.Format("{0}:{1}", i + 1, mModeSet.Step[i].Text); } else { tabControl1.TabPages[i + 1].Text = string.Format("{0}:空", i + 1); } } for (int i = 0; i < 10; i++) { TmpStepStr[i].Text = mModeSet.Step[i].Text; TmpStepStr[i].TestTime = mModeSet.Step[i].TestTime.ToString(); TmpStepStr[i].NengJi = mModeSet.Step[i].NengJi.ToString(); TmpStepStr[i].PinLv = mModeSet.Step[i].PinLv.ToString(); TmpStepStr[i].SnCode = mModeSet.Step[i].SnCode; TmpStepStr[i].StartCheck = mModeSet.Step[i].StartCheck.ToString(); TmpStepStr[i].EndCheck = mModeSet.Step[i].EndCheck.ToString(); TmpStepStr[i].StartInfo = mModeSet.Step[i].StartInfo; TmpStepStr[i].EndInfo = mModeSet.Step[i].EndInfo; for (int j = 0; j < cMain.DataShow; j++) { TmpStepStr[i].LowData[j] = mModeSet.Step[i].LowData[j].ToString(); TmpStepStr[i].HighData[j] = mModeSet.Step[i].HighData[j].ToString(); } } DataClassToStepFrm(); changeValue = true; return(isOk); }