Exemple #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);
            }
        }
Exemple #2
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);
            }
        }