Example #1
0
        private void LoadData()
        {
            DataTableReader dr = null;
            TCommonType     ctype;

            cbbInType1.Items.Clear();
            cbbInType2.Items.Clear();
            try
            {
                if (!db.IsOpen)
                {
                    db.Open(SystemInfo.ConnStr);
                }
                if (SystemInfo.AdvTimeGroup)
                {
                    dr = db.GetDataReader(Pub.GetSQL(DBCode.DB_003003, new string[] { "103" }));
                }
                else
                {
                    dr = db.GetDataReader(Pub.GetSQL(DBCode.DB_003003, new string[] { "102" }));
                }
                while (dr.Read())
                {
                    ctype = new TCommonType(dr["TimeInTypeSysID"].ToString(), dr["TimeInTypeID"].ToString(),
                                            dr["TimeInTypeName"].ToString(), true);
                    cbbInType1.Items.Add(ctype);
                    cbbInType2.Items.Add(ctype);
                }
                if (SysID == "")
                {
                    dr = db.GetDataReader(Pub.GetSQL(DBCode.DB_003003, new string[] { "101" }));
                    if (dr.Read())
                    {
                        int no = 0;
                        int.TryParse(dr[0].ToString(), out no);
                        if (no > SystemInfo.MaxTimeNo)
                        {
                            no = SystemInfo.MaxTimeNo;
                        }
                        txtID.Text = no.ToString();
                    }
                    cbbInType1.SelectedIndex = 0;
                    cbbInType2.SelectedIndex = 0;
                    if (SystemInfo.AdvTimeGroup)
                    {
                        cbbInType1.SelectedIndex = 1;
                        cbbInType2.SelectedIndex = 1;
                    }
                }
                else
                {
                    dr = db.GetDataReader(Pub.GetSQL(DBCode.DB_003003, new string[] { "6", SysID }));
                    if (dr.Read())
                    {
                        txtID.Text   = dr["MacTimeNo"].ToString();
                        txtName.Text = dr["MacTimeName"].ToString();
                        MaskedTextBox txt;
                        for (int i = 1; i <= 3; i++)
                        {
                            txt      = (MaskedTextBox)groupBox1.Controls["txtBeginTime" + i.ToString()];
                            txt.Text = dr["MacTimeBeginTime" + i.ToString()].ToString();
                            txt      = (MaskedTextBox)groupBox1.Controls["txtEndTime" + i.ToString()];
                            txt.Text = dr["MacTimeEndTime" + i.ToString()].ToString();
                        }
                        for (int i = 4; i <= 6; i++)
                        {
                            txt      = (MaskedTextBox)groupBox2.Controls["txtBeginTime" + i.ToString()];
                            txt.Text = dr["MacTimeBeginTime" + i.ToString()].ToString();
                            txt      = (MaskedTextBox)groupBox2.Controls["txtEndTime" + i.ToString()];
                            txt.Text = dr["MacTimeEndTime" + i.ToString()].ToString();
                        }
                        SetInTypeIndex(cbbInType1, dr["MacTimeInType1"].ToString());
                        SetInTypeIndex(cbbInType2, dr["MacTimeInType2"].ToString());
                        string binStr = Pub.DecToBin(dr["MacTimeWeekIndex"].ToString(), 7);
                        if (binStr.Length == 7)
                        {
                            checkBox1.Checked = binStr.Substring(6, 1) == "1";
                            checkBox2.Checked = binStr.Substring(0, 1) == "1";
                            checkBox3.Checked = binStr.Substring(1, 1) == "1";
                            checkBox4.Checked = binStr.Substring(2, 1) == "1";
                            checkBox5.Checked = binStr.Substring(3, 1) == "1";
                            checkBox6.Checked = binStr.Substring(4, 1) == "1";
                            checkBox7.Checked = binStr.Substring(5, 1) == "1";
                        }
                        if (dr["MacTimeLimit"].ToString() == "1")
                        {
                            rbLimitOne.Checked = true;
                        }
                    }
                }
            }
            catch (Exception E)
            {
                Pub.ShowErrorMsg(E);
            }
            finally
            {
                if (dr != null)
                {
                    dr.Close();
                }
                dr = null;
            }
        }