Esempio n. 1
0
        private void OnClickSearch(object sender, EventArgs e)
        {
            KeyFilter     kf   = new KeyFilter();
            KeyFilterForm kffm = new KeyFilterForm(this, kf);

            if (kffm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                ShowKeysByFilter(kf);
            }
        }
Esempio n. 2
0
 private Dictionary <int, int> _dictParents; // IDPARENT as a Key, ID (current) - as a Value
 public KeyFilterForm(LMMainForm mainForm, KeyFilter keyFilter)
 {
     _mainForm  = mainForm;
     _keyFilter = keyFilter;
     InitializeComponent();
     // Set key-filter into unactive state:
     _keyFilter.IDCompany    = -1;
     _keyFilter.IDDevice     = -1;
     _keyFilter.IDKey        = -1;
     _keyFilter.IDParentKey  = -1;
     _keyFilter.FNameOfOwner = ""; // Empty string
 }
Esempio n. 3
0
 public KeysForm(LMMainForm mainForm, KeyFilter keyFilter = null)
 {
     try
     {
         _keyFilter = keyFilter;
         _mainForm  = mainForm;
         InitializeComponent();
     }
     catch (Exception ex)
     {
         log.ErrorFormat("KeysForm.KeysForm - {0}", ex.Message);
     }
 }
Esempio n. 4
0
        public void ShowKeysByFilter(KeyFilter kf)
        {
            if (_keys != null)
            {
                _keys.Close();
            }

            _keys = null;

            _keys           = new KeysForm(this, kf);
            _keys.MdiParent = this;

            _keys.Show();
        }
Esempio n. 5
0
        public void ShowKeysForCompany(int iIDCompany)
        {
            if (_keys != null)
            {
                _keys.Close();
            }

            _keys = null;

            KeyFilter kfr = new KeyFilter(-1, iIDCompany, -1, -1, -1, -1); //1);

            kfr.FNameOfOwner = "";                                         // Empty string
            _keys            = new KeysForm(this, kfr);
            _keys.MdiParent  = this;

            _keys.Show();
        }
Esempio n. 6
0
        private void RefreshKeysGrid(bool bFirstPass, KeyFilter kfr)
        {
            try
            {
                DataTable tTable = _dsKeys.Tables["tblKeys"];
                // sqlDataAdapter1.Fill(_dsKeys, "tblKeys");
                FillKeysTable(tTable, kfr);

                if (bFirstPass)
                {
                    DataGridViewCheckBoxColumn columnCb1 = new DataGridViewCheckBoxColumn();
                    {
                        columnCb1.DataPropertyName = "ValidCheckBox";
                        columnCb1.HeaderText       = "CheckBoxColumn1";
                        columnCb1.FlatStyle        = FlatStyle.Standard;
                        // columnCb2.Width = 100;
                        columnCb1.ThreeState   = true;
                        columnCb1.CellTemplate = new DataGridViewCheckBoxCell();
                        columnCb1.CellTemplate.Style.BackColor = Color.Beige;
                    }
                    dataGridView3.Columns.Remove("ValidCheckBox");
                    dataGridView3.Columns.Insert(10, columnCb1);

                    DataGridViewCheckBoxColumn columnCb2 = new DataGridViewCheckBoxColumn();
                    {
                        columnCb2.DataPropertyName = "TestCheckBox";
                        columnCb2.HeaderText       = "CheckBoxColumn2";
                        columnCb2.FlatStyle        = FlatStyle.Standard;
                        // columnCb2.Width = 100;
                        columnCb2.ThreeState   = true;
                        columnCb2.CellTemplate = new DataGridViewCheckBoxCell();
                        columnCb2.CellTemplate.Style.BackColor = Color.Beige;
                    }
                    dataGridView3.Columns.Remove("TestCheckBox");
                    dataGridView3.Columns.Insert(12, columnCb2);
                }

                // Rename 'HeaderText' ONLY via dataGridView!!!
                // DO NOT using dataSet/dataTable for this action!!!
                int iIndex = 0;
                foreach (DataGridViewColumn column in dataGridView3.Columns)
                {
                    switch (iIndex)
                    {
                    case 0: column.Width  = 45;
                        column.HeaderText = "N п/п";
                        break;

                    case 1: column.Visible = false;     // Hide "IDCOMPANY" column
                        break;

                    case 2: column.Width  = 115;
                        column.HeaderText = "Название организации";
                        break;

                    case 3: column.Visible = false;     // Hide "IDDEVICE" column
                        break;

                    case 4: column.Width  = 65;
                        column.HeaderText = "Код устройства";
                        break;

                    case 5: column.Visible = false;     // Hide "IDPARENTKEY" column
                        break;

                    case 6: column.Width  = 70;
                        column.HeaderText = "Предшеств.";
                        break;

                    case 7: column.Width  = 90;
                        column.HeaderText = "Значение ключа";
                        break;

                    case 8: column.Width  = 75;
                        column.HeaderText = "Начальная дата";
                        break;

                    case 9: column.Width  = 75;
                        column.HeaderText = "Конечная дата";
                        break;

                    case 10: column.Width = 75;
                        column.HeaderText = "Действует";
                        break;

                    case 11: column.Visible = false;     // Hide "FlagOfTest" column
                        break;

                    case 12: column.Width = 75;
                        column.HeaderText = "Тестовый";
                        break;

                    case 13: column.Width = 75;
                        column.HeaderText = "Дата выпуска";
                        break;

                    case 14: column.Width = 95;
                        column.HeaderText = "Фамилия владельца";
                        break;

                    case 15: column.Width = 95;
                        column.HeaderText = "Должность владельца";
                        break;
                    }
                    iIndex++;
                }
                dataGridView3.ReadOnly           = true;
                dataGridView3.AllowUserToAddRows = false;
                dataGridView3.RowHeadersVisible  = false;

                // toolStripBtnSave.Enabled = false;
            }
            catch (Exception ex)
            {
                log.ErrorFormat("KeysForm.RefreshKeysGrid - {0}", ex.Message);
            }
        }
Esempio n. 7
0
        private void FillKeysTable(DataTable tTable, KeyFilter kfr = null)
        {
            try
            {   /*
                 * string strSQL = "SELECT Keys.ID, Devices.IDCOMPANY, Company.CompanyName, IDDEVICE, Devices.CodeOfKey as DeviceCode, IDPARENTKEY, ValueOfKey, " +
                 *  "StartDate, EndDate, FlagOfTest, IssueDate, Devices.FNameOfOwner, Devices.PositionOfOwner " +
                 *  "FROM Keys " +
                 *  "INNER JOIN Devices ON Keys.IDDEVICE = Devices.ID " +
                 *  "INNER JOIN Company ON Devices.IDCOMPANY = Company.ID";
                 *
                 * SqlCommand cmd = new SqlCommand(strSQL, _mainForm.SqlConnection2); */// It's also OK (if kfr==null)
                SqlCommand cmd = null;
                if (kfr != null)
                {
                    cmd             = new SqlCommand("SP_SHOWKEYS2", _mainForm.SqlConnection2);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Clear();
                    cmd.Parameters.Add("@ID", SqlDbType.Int).Value                    = kfr.IDKey;
                    cmd.Parameters.Add("@IDCOMPANY", SqlDbType.Int).Value             = kfr.IDCompany;
                    cmd.Parameters.Add("@IDDEVICE", SqlDbType.Int).Value              = kfr.IDDevice;
                    cmd.Parameters.Add("@IDPARENTKEY", SqlDbType.Int).Value           = kfr.IDParentKey;
                    cmd.Parameters.Add("@VALIDKEY", SqlDbType.Int).Value              = kfr.ValidKeyMode;
                    cmd.Parameters.Add("@FNameOfOwner", SqlDbType.VarChar, 128).Value = kfr.FNameOfOwner;
                }
                else // if (kfr == null) - filter is not present:
                {
                    cmd             = new SqlCommand("SP_SHOWKEYS1", _mainForm.SqlConnection2);
                    cmd.CommandType = CommandType.StoredProcedure;
                }
                SqlDataReader reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    int    iKeysId        = reader.GetInt32(0);
                    int    iIDCompany     = reader.GetInt32(1);
                    string strCompanyName = reader.GetString(2);
                    int    iIDDevice      = reader.GetInt32(3);
                    string strDeviceCode  = reader.GetString(4);
                    int    iIDParentKey   = 0;
                    if (!reader.IsDBNull(5))
                    {
                        iIDParentKey = reader.GetInt32(5);
                    }
                    string   strValueOfKey = reader.GetString(6);
                    DateTime dtStartDate   = reader.GetDateTime(7);
                    DateTime dtEndDate     = reader.GetDateTime(8);
                    short    nFlagOfTest   = reader.GetInt16(9);
                    bool     bFlagOfTest   = (bool)(1 == nFlagOfTest);
                    DateTime dtIssueDate   = DateTime.MinValue;
                    if (!reader.IsDBNull(10))
                    {
                        dtIssueDate = reader.GetDateTime(10);
                    }
                    string   strFNameOfOwner    = reader.GetString(11);
                    string   strPositionOfOwner = reader.GetString(12);
                    DateTime dtNow     = DateTime.Now;
                    bool     bValidKey = (bool)((dtStartDate <= dtNow) && (dtNow <= dtEndDate));

                    DataRow dr = tTable.NewRow();
                    dr.BeginEdit();
                    dr["ID"]          = iKeysId;
                    dr["IDCOMPANY"]   = iIDCompany;
                    dr["CompanyName"] = strCompanyName;
                    dr["IDDEVICE"]    = iIDDevice;
                    dr["DeviceCode"]  = strDeviceCode;
                    dr["IDPARENTKEY"] = iIDParentKey;
                    if (0 == iIDParentKey)
                    {
                        dr["SecondKey"] = "-";
                    }
                    else
                    {
                        dr["SecondKey"] = iIDParentKey.ToString();
                    }
                    dr["ValueOfKey"]      = strValueOfKey;
                    dr["StartDate"]       = dtStartDate;
                    dr["EndDate"]         = dtEndDate;
                    dr["ValidCheckBox"]   = bValidKey;
                    dr["FlagOfTest"]      = nFlagOfTest;
                    dr["TestCheckBox"]    = bFlagOfTest;
                    dr["IssueDate"]       = dtIssueDate;
                    dr["FNameOfOwner"]    = strFNameOfOwner;
                    dr["PositionOfOwner"] = strPositionOfOwner;
                    dr.EndEdit();
                    tTable.Rows.Add(dr);
                }
                reader.Close();
            }
            catch (Exception ex)
            {
                log.ErrorFormat("KeysForm.RefreshKeysGrid - {0}", ex.Message);
            }
        }