Beispiel #1
0
        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);
        }
Beispiel #2
0
        /// <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);
        }