Пример #1
0
        private void OnClickKeyGenerator(object sender, EventArgs e)
        {
            try
            {
                LMMainForm.PrepareDictionary(_dictCompanyNames, _listCompanyNames);

                PrepareDeviceCodes(_dictDeviceCodes, _dictCodes);

                KeyGenPrepareForm kgpf = new KeyGenPrepareForm(_dictCompanyNames, _dictDeviceCodes);
                if (kgpf.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    // Key generating:
                    int    iIDCompany   = kgpf.IDCompany;
                    string sCompanyName = kgpf.ResultCompany;

                    string strDeviceCode = kgpf.ResultDeviceCode;
                    int    iIDDevice     = RetrieveIdDevice(strDeviceCode);

                    short nFlagOfTest = kgpf.TestKeyFlag ? ((short)1) : ((short)0);
                    if (0 == nFlagOfTest)
                    {   // If it is NOT Test-key:
                        int iLimitOfKeys = LMMainForm.GetLimitOfKeys(iIDCompany);
                        int iExistKeys   = RetrieveExistKeysForCompany(iIDCompany);
                        if (iExistKeys >= iLimitOfKeys)
                        {
                            string strCompanyName = kgpf.ResultCompany;
                            string strOut         =
                                string.Format("Превышение лимита ключей для компании '{0}'! Действие отменено!", strCompanyName);
                            MessageBox.Show(strOut, "License Manager", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            return;
                        }
                    }

                    Key k = new Key(iIDDevice);
                    k.ID         = -1;               // ID generate automatically
                    k.FlagOfTest = nFlagOfTest;
                    k.IssueDate  = kgpf.DTIssueDate; // DateTime.Now;
                    k.StartDate  = kgpf.DTStartDate; // DateTime.Now;
                    // TimeSpan ts = new TimeSpan(365, 0, 0, 0);
                    // DateTime dtEnd = DateTime.Now + ts;
                    k.EndDate = kgpf.DTEndDate; // dtEnd;
                    k.KeyGenerate();

                    string s1 = "";
                    ReasonStore(sCompanyName, ref s1);

                    int iIDKey = InsertKeyRecord(k);
                    InsertKeyHistoryRecord(iIDKey, DateTime.Now, s1);

                    DataTable tTable = _dsKeys.Tables["tblKeys"];
                    tTable.Rows.Clear();

                    RefreshKeysGrid(false, _keyFilter);
                }
            }
            catch (Exception ex)
            {
                log.ErrorFormat("KeysForm.OnClickKeyGenerator - {0}", ex.Message);
            }
        }
Пример #2
0
        private void OnFilterLoad(object sender, EventArgs e)
        {
            try
            {
                radioButtonAnyKey.Checked  = true;
                radioButtonAllKeys.Checked = true;

                checkBoxCompany.Checked = false;
                checkBoxDevice.Checked  = false;
                checkBoxOwner.Checked   = false;
                checkBoxParent.Checked  = false;

                comboBoxCompany.Enabled = false;
                comboBoxDevice.Enabled  = false;
                comboBoxOwner.Enabled   = false;
                comboBoxParent.Enabled  = false;

                _dictCompanyNames = new Dictionary <int, string>();
                LMMainForm.PrepareDictionary(_dictCompanyNames, null);

                _dictDevicesCodes  = new Dictionary <int, string>();
                _listFNameOfOwners = new List <string>();
                PrepareDeviceAndOwners(_dictDevicesCodes, _listFNameOfOwners);

                _dictParents = new Dictionary <int, int>();
                PrepareParents(_dictParents);

                foreach (KeyValuePair <int, string> kvp in this._dictCompanyNames)
                {
                    string strCompanyName = kvp.Value;
                    comboBoxCompany.Items.Add((object)strCompanyName);
                }

                foreach (KeyValuePair <int, string> kvp in this._dictDevicesCodes)
                {
                    string strOutCode = string.Format("Устройство '{0}' (код устройства '{1}')", kvp.Key, kvp.Value);
                    comboBoxDevice.Items.Add((object)strOutCode);
                }

                foreach (string strFNameOfOwner in _listFNameOfOwners)
                {
                    comboBoxOwner.Items.Add((object)strFNameOfOwner);
                }

                foreach (KeyValuePair <int, int> kvp in this._dictParents)
                {
                    string strText = string.Format("Ключ '{0}' (вместо ключа '{1}')", kvp.Value, kvp.Key);
                    comboBoxParent.Items.Add((object)strText);
                }
            }
            catch (Exception ex)
            {
                log.ErrorFormat("KeyFilterForm.OnFilterLoad - {0}", ex.Message);
            }
        }
Пример #3
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
 }
Пример #4
0
 private List <int> _listHistKeys; // List of IDs
 public KeyHistoryForm(LMMainForm mainForm, List <int> listHistKeys)
 {
     try
     {
         _mainForm     = mainForm;
         _listHistKeys = listHistKeys;
         InitializeComponent();
     }
     catch (Exception ex)
     {
         log.ErrorFormat("KeyHistoryForm.KeyHistoryForm - {0}", ex.Message);
     }
 }
Пример #5
0
 public KeysForm(LMMainForm mainForm, KeyFilter keyFilter = null)
 {
     try
     {
         _keyFilter = keyFilter;
         _mainForm  = mainForm;
         InitializeComponent();
     }
     catch (Exception ex)
     {
         log.ErrorFormat("KeysForm.KeysForm - {0}", ex.Message);
     }
 }
Пример #6
0
 public CompanyForm(LMMainForm mainForm)
 {
     try
     {
         _mainForm = mainForm;
         InitializeComponent();
         this.sqlSelectCommand1.Connection = _mainForm.SqlConnection;
         this.sqlInsertCommand1.Connection = _mainForm.SqlConnection;
         this.sqlUpdateCommand1.Connection = _mainForm.SqlConnection;
         this.sqlDeleteCommand1.Connection = _mainForm.SqlConnection;
     }
     catch (Exception ex)
     {
         log.ErrorFormat("CompanyForm.CompanyForm - {0}", ex.Message);
     }
 }
Пример #7
0
        public AboutForm()
        {
            string strFileName = "LM.exe";

            InitializeComponent();

            FileVersionInfo fileVersionInfo   = FileVersionInfo.GetVersionInfo(strFileName);
            string          strVersion        = fileVersionInfo.FileVersion;
            DateTime        dtCompileDateTime = LMMainForm.RetrieveLinkerTimestamp(strFileName);

            labelVersion.Text = strVersion;
            labelTime.Text    = dtCompileDateTime.ToString();

            string strLink = "http://files.rsdn.ru/21902/alexgin_resume.pdf";
            int    iLen    = this.linkLabel1.Text.Length;

            this.linkLabel1.Links.Add(0, iLen, strLink);
        }
Пример #8
0
        private void OnClickEditDevices(object sender, EventArgs e)
        {
            try
            {
                if (dataGridView2.ReadOnly)
                {
                    LMMainForm.PrepareDictionary(_dictCompanyNames, _listCompanyNames);

                    dataGridView2.ReadOnly           = false;
                    dataGridView2.AllowUserToAddRows = true;
                    dataGridView2.RowHeadersVisible  = true;

                    toolStripBtnEdit.Enabled = false;
                    toolStripBtnSave.Enabled = true;
                }
            }
            catch (Exception ex)
            {
                log.ErrorFormat("DevicesForm.OnClickEditDevices - {0}", ex.Message);
            }
        }
Пример #9
0
        private void OnLoadDevices(object sender, EventArgs e)
        {
            try
            {
                _dictCompanyNames = new Dictionary <int, string>();
                _listCompanyNames = new List <string>();
                LMMainForm.PrepareDictionary(_dictCompanyNames, _listCompanyNames);

                DataTable tTable = new DataTable("tblDevices");

                DataColumn clID              = new DataColumn("ID", typeof(int));
                DataColumn clIDCOMPANY       = new DataColumn("IDCOMPANY", typeof(int));
                DataColumn clCompanyName     = new DataColumn("CompanyName", typeof(string)); // Column for replace
                DataColumn clCodeOfKey       = new DataColumn("CodeOfKey", typeof(string));
                DataColumn clFNameOfOwner    = new DataColumn("FNameOfOwner", typeof(string));
                DataColumn clPositionOfOwner = new DataColumn("PositionOfOwner", typeof(string));

                tTable.Columns.Add(clID);
                tTable.Columns.Add(clIDCOMPANY);
                tTable.Columns.Add(clCompanyName);
                tTable.Columns.Add(clCodeOfKey);
                tTable.Columns.Add(clFNameOfOwner);
                tTable.Columns.Add(clPositionOfOwner);

                _dsDevices = new DataSet("dsDevices");
                _dsDevices.Tables.Add(tTable);

                _bs = new BindingSource(_dsDevices, "tblDevices");

                dataGridView2.DataSource = _bs;
                sqlDataAdapter1.Fill(_dsDevices, "tblDevices");

                // see:
                // https://social.msdn.microsoft.com/Forums/windows/en-US/abb7be97-0a44-4e18-98bf-687a723645a9/combo-box-inside-datagridview-using-datatable?forum=winformsdatacontrols

                DataGridViewComboBoxColumn colCombo = new DataGridViewComboBoxColumn();
                {
                    colCombo.DataPropertyName = "CompanyName";
                    colCombo.HeaderText       = "ComboBoxColumn";
                    colCombo.DropDownWidth    = 250;
                    colCombo.Width            = 90;
                    colCombo.MaxDropDownItems = _listCompanyNames.Count;
                    colCombo.FlatStyle        = FlatStyle.Flat;
                    colCombo.DataSource       = _listCompanyNames;
                    // colCombo.ValueMember = "CompanyName";
                    // colCombo.DisplayMember = colCombo.ValueMember;
                    colCombo.ValueType = typeof(string);
                }
                dataGridView2.Columns.Remove("CompanyName");
                dataGridView2.Columns.Insert(2, colCombo);

                foreach (DataRow dr in tTable.Rows)
                {
                    string strIdCompany = dr["IDCOMPANY"].ToString();
                    int    iCompanyId   = Convert.ToInt32(strIdCompany);
                    dr["CompanyName"] = _dictCompanyNames[iCompanyId];
                }
                // Rename 'HeaderText' ONLY via dataGridView!!!
                // DO NOT using dataSet/dataTable for this action!!!
                int iIndex = 0;
                foreach (DataGridViewColumn column in dataGridView2.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  = 175;
                        column.HeaderText = "Название организации";
                        break;

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

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

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

                toolStripBtnSave.Enabled = false;
            }
            catch (Exception ex)
            {
                log.ErrorFormat("DevicesForm.OnLoadDevices - {0}", ex.Message);
            }
        }
Пример #10
0
        private void OnClickKeyGenerChild(object sender, EventArgs e)
        {
            try
            {
                int    iSelRow      = dataGridView3.CurrentCell.RowIndex;
                string strParentKey = dataGridView3.Rows[iSelRow].Cells[0].Value.ToString();
                int    iParentKey   = Convert.ToInt32(strParentKey);

                string strCompanyId = dataGridView3.Rows[iSelRow].Cells[1].Value.ToString();
                int    iCompanyId   = Convert.ToInt32(strCompanyId);

                string strCompanyName = dataGridView3.Rows[iSelRow].Cells[2].Value.ToString();
                string strDeviceCode  = dataGridView3.Rows[iSelRow].Cells[4].Value.ToString();

                LMMainForm.PrepareDictionary(_dictCompanyNames, _listCompanyNames);

                PrepareDeviceCodes(_dictDeviceCodes, _dictCodes);

                KeyGenPrepareForm kgpf = new KeyGenPrepareForm(_dictCompanyNames, _dictDeviceCodes, iParentKey);
                kgpf.IDCompany        = iCompanyId;
                kgpf.ResultCompany    = strCompanyName;
                kgpf.ResultDeviceCode = strDeviceCode;
                if (kgpf.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    // Key generating:
                    // int iIDCompany = kgpf.IDCompany;
                    int iIDDevice = RetrieveIdDevice(strDeviceCode);

                    short nFlagOfTest = kgpf.TestKeyFlag ? ((short)1) : ((short)0);

                    Key k = new Key(iIDDevice);
                    k.ID         = -1;               // ID generate automatically
                    k.FlagOfTest = nFlagOfTest;
                    k.IssueDate  = kgpf.DTIssueDate; // DateTime.Now;
                    k.StartDate  = kgpf.DTStartDate; // DateTime.Now;
                    // TimeSpan ts = new TimeSpan(365, 0, 0, 0);
                    // DateTime dtEnd = DateTime.Now + ts;
                    k.EndDate     = kgpf.DTEndDate; // dtEnd;
                    k.IDParentKey = iParentKey;
                    k.KeyGenerate();

                    string s1 = "";
                    if (!ReasonStore(strCompanyName, ref s1, iParentKey))
                    {
                        return;
                    }

                    int iIDKey = InsertKeyRecord(k);
                    InsertKeyHistoryRecord(iIDKey, DateTime.Now, s1);

                    DataTable tTable = _dsKeys.Tables["tblKeys"];
                    tTable.Rows.Clear();

                    RefreshKeysGrid(false, _keyFilter);
                }
            }
            catch (Exception ex)
            {
                log.ErrorFormat("KeysForm.OnClickKeyGenerChild - {0}", ex.Message);
            }
        }
Пример #11
0
        private void OnLoadKeys(object sender, EventArgs e)
        {
            try
            {
                _dictCompanyNames = new Dictionary <int, string>();
                _listCompanyNames = new List <string>();
                LMMainForm.PrepareDictionary(_dictCompanyNames, _listCompanyNames);

                _dictDeviceCodes = new Dictionary <int, List <string> >();
                _dictCodes       = new Dictionary <int, string>();
                PrepareDeviceCodes(_dictDeviceCodes, _dictCodes);

                DataTable tTable = new DataTable("tblKeys");

                DataColumn clID              = new DataColumn("ID", typeof(int));
                DataColumn clIDCOMPANY       = new DataColumn("IDCOMPANY", typeof(int));
                DataColumn clCompanyName     = new DataColumn("CompanyName", typeof(string));
                DataColumn clIDDEVICE        = new DataColumn("IDDEVICE", typeof(int));
                DataColumn clDeviceCode      = new DataColumn("DeviceCode", typeof(string));
                DataColumn clIDPARENTKEY     = new DataColumn("IDPARENTKEY", typeof(int));
                DataColumn clSecondKey       = new DataColumn("SecondKey", typeof(string));
                DataColumn clValueOfKey      = new DataColumn("ValueOfKey", typeof(string));
                DataColumn clStartDate       = new DataColumn("StartDate", typeof(System.DateTime));
                DataColumn clEndDate         = new DataColumn("EndDate", typeof(System.DateTime));
                DataColumn clValidCheckBox   = new DataColumn("ValidCheckBox", typeof(bool)); // Column for replace
                DataColumn clFlagOfTest      = new DataColumn("FlagOfTest", typeof(short));
                DataColumn clTestCheckBox    = new DataColumn("TestCheckBox", typeof(bool));  // Column for replace
                DataColumn clIssueDate       = new DataColumn("IssueDate", typeof(System.DateTime));
                DataColumn clFNameOfOwner    = new DataColumn("FNameOfOwner", typeof(string));
                DataColumn clPositionOfOwner = new DataColumn("PositionOfOwner", typeof(string));

                tTable.Columns.Add(clID);
                tTable.Columns.Add(clIDCOMPANY);
                tTable.Columns.Add(clCompanyName);
                tTable.Columns.Add(clIDDEVICE);
                tTable.Columns.Add(clDeviceCode);
                tTable.Columns.Add(clIDPARENTKEY);
                tTable.Columns.Add(clSecondKey);
                tTable.Columns.Add(clValueOfKey);
                tTable.Columns.Add(clStartDate);
                tTable.Columns.Add(clEndDate);
                tTable.Columns.Add(clValidCheckBox);
                tTable.Columns.Add(clFlagOfTest);
                tTable.Columns.Add(clTestCheckBox);
                tTable.Columns.Add(clIssueDate);
                tTable.Columns.Add(clFNameOfOwner);
                tTable.Columns.Add(clPositionOfOwner);

                _dsKeys = new DataSet("dsKeys");
                _dsKeys.Tables.Add(tTable);

                _bs = new BindingSource(_dsKeys, "tblKeys");

                dataGridView3.DataSource = _bs;
                RefreshKeysGrid(true, _keyFilter);
            }
            catch (Exception ex)
            {
                log.ErrorFormat("KeysForm.OnLoadKeys - {0}", ex.Message);
            }
        }