public void SetMaterialId(string id)
        {
            _materialRecordId = id;
            _currSqlSelect = new SqlSelect(TbMaterials.Name);
            _currSqlSelect.Equal(TbMaterials.MaterialId, id);
            _currSqlSelect.RetrieveData();

            ConstructFormWithValue();
        }
        private void btnStartSearchAdd_Click(object sender, EventArgs e)
        {
            SqlSelect sqlSelectQuery = new SqlSelect(TbMaterials.Name);

            ConstructSelectQuery(ref sqlSelectQuery);
            sqlSelectQuery.OrderByField = TbMaterials.MaterialId;
            sqlSelectQuery.RetrieveData();

            ResultsToDgvShow(sqlSelectQuery.DataTable);
        }
        public static string GetAuthorOfComputer()
        {
            string author = "";

            List<string> macAddresses = GetMacAddressOfCurrentComputer();
            foreach (string macAddress in macAddresses)
            {
                SqlSelect sqlSelect = new SqlSelect(TbPeopleHardwareAddress.Name);
                sqlSelect.Like(TbPeopleHardwareAddress.MacAddress, macAddress);
                sqlSelect.RetrieveData();

                if (sqlSelect.CountOfRows == 1)
                {
                    author = sqlSelect.GetValueOfField(TbPeopleHardwareAddress.SurnameAndName).ToString();
                    break;
                }
            }

            return author != "" ? author : macAddresses[0];
        }
        public void LoadEpitTableToDataGrid(String table, DataGridView dgv)
        {
            SqlSelect sqlSelect = new SqlSelect(table);
            sqlSelect.OrderByField = TbEpitStructure.Number;
            sqlSelect.SortIsAscending = false;
            sqlSelect.RetrieveData();

            dgv.Rows.Clear();
            dgv.RowCount = sqlSelect.CountOfRows + 1;

            for (int i = 0; i < sqlSelect.CountOfRows; i++)
            {
                int number = (int)sqlSelect.GetValueOfField(TbEpitStructure.Number, i);
                dgv.Rows[i].Cells[0].Value = number != 0 ? number + " слой" : "Подложка";
                dgv.Rows[i].Cells[1].Value = sqlSelect.GetValueOfField(TbEpitStructure.TypeOfLayer, i);
                dgv.Rows[i].Cells[2].Value = sqlSelect.GetValueOfField(TbEpitStructure.Material, i);
                dgv.Rows[i].Cells[3].Value = sqlSelect.GetValueOfField(TbEpitStructure.Thickness, i) + "?";
                dgv.Rows[i].Cells[4].Value =
                    ((double)sqlSelect.GetValueOfField(TbEpitStructure.Concentration, i)).ToString("0.0##E+00") + "?";
            }
        }
        private Dictionary<string, string> GetEpitTablesInfo()
        {
            Dictionary<string, string> res = new Dictionary<string, string>();

            SqlSelect sqlSelect = new SqlSelect(TbEpitHost.Name);
            sqlSelect.RetrieveData();
            DataTable dt = sqlSelect.DataTable;

            foreach (DataRow row in dt.Rows)
                res.Add(row[TbEpitHost.NameOfEpitStructureTable].ToString(), row[TbEpitHost.UserName].ToString());

            return res;
        }
        private void ConstructSelectQuery(ref SqlSelect sqlSelectQuery)
        {
            if (tbGlobalSearch.Text != "")
            {
                string str = tbGlobalSearch.Text;
                sqlSelectQuery.TypeOfLogicIsAnd = false;
                sqlSelectQuery.Like(TbMaterials.MaterialId, str);
                sqlSelectQuery.Like(TbMaterials.AuthorOfRecord, str);
                sqlSelectQuery.Like(TbMaterials.Comment, str);
                sqlSelectQuery.Like(TbMaterials.ConcentrationInWafer, str);
                sqlSelectQuery.Like(TbMaterials.Corresponds, str);
                sqlSelectQuery.Like(TbMaterials.CreationDate, str);
                sqlSelectQuery.Like(TbMaterials.Ingot, str);
                sqlSelectQuery.Like(TbMaterials.LaunchedStatus, str);
                sqlSelectQuery.Like(TbMaterials.MaterialOfWafer, str);
                sqlSelectQuery.Like(TbMaterials.RecordIdOfAttachmentFile, str);
                sqlSelectQuery.Like(TbMaterials.RecordIdOfEpitStructureFile, str);
                sqlSelectQuery.Like(TbMaterials.Technology, str);
                sqlSelectQuery.Like(TbMaterials.TechProc, str);
                sqlSelectQuery.Like(TbMaterials.StructureManufacturer, str);
                sqlSelectQuery.Like(TbMaterials.ThicknessOfWafer, str);
                sqlSelectQuery.Like(TbMaterials.TypeOfWafer, str);
                sqlSelectQuery.Like(TbMaterials.VerificationStatus, str);
                sqlSelectQuery.Like(TbMaterials.WaferDiameter, str);
                sqlSelectQuery.Like(TbMaterials.WaferManufacturer, str);
                sqlSelectQuery.Like(TbMaterials.WaferResistance, str);

                return;
            }

            if (tbNumberOfParty.Text != "")
                sqlSelectQuery.Equal(TbMaterials.NumberOfParcel, tbNumberOfParty.Text);

            if (!rbDontWantWNFilter.Checked)
            {
                if (tbNumberOfWafers.Enabled)
                {
                    int x = Int32.Parse(tbNumberOfWafers.Text);
                    sqlSelectQuery.Equal(TbMaterials.NumberOfWafer, x);
                }
                if (tbNumberOfWafersStart.Enabled)
                {
                    int x1 = Int32.Parse(tbNumberOfWafersStart.Text);
                    sqlSelectQuery.MoreOrEqual(TbMaterials.NumberOfWafer, x1);
                }
                if (tbNumberOfWafersFinish.Enabled)
                {
                    int x2 = Int32.Parse(tbNumberOfWafersFinish.Text);
                    sqlSelectQuery.LessOrEqual(TbMaterials.NumberOfWafer, x2);
                }
            }

            if (!rbDontWantDateFilter.Checked)
            {
                if (dtpCreationTime.Enabled)
                    sqlSelectQuery.Equal(TbMaterials.CreationDate, dtpCreationTime.Value.Date);
                if (dtpCreationStart.Enabled)
                    sqlSelectQuery.MoreOrEqual(TbMaterials.CreationDate, dtpCreationStart.Value.Date);
                if (dtpCreationFinish.Enabled)
                    sqlSelectQuery.LessOrEqual(TbMaterials.CreationDate, dtpCreationFinish.Value.Date);
            }
            if (cbAuthorOfRecord.Text != "")
                sqlSelectQuery.Equal(TbMaterials.AuthorOfRecord, cbAuthorOfRecord.Text);
            if (cbDefinitionOfWafer.Text != "")
                sqlSelectQuery.Equal(TbMaterials.WaferManufacturer, cbDefinitionOfWafer.Text);
            if (cbTypeOfWafer.Text != "")
                sqlSelectQuery.Equal(TbMaterials.TypeOfWafer, cbTypeOfWafer.Text);
            if (cbMaterialOfWafer.Text != "")
                sqlSelectQuery.Equal(TbMaterials.MaterialOfWafer, cbMaterialOfWafer.Text);
            if (!rbDontWantConcFilter.Checked)
            {
                if (tbConcOfWafer.Enabled)
                    sqlSelectQuery.Equal(TbMaterials.ConcentrationInWafer, Double.Parse(tbConcOfWafer.Text));
                if (tbConcOfWaferStart.Enabled)
                    sqlSelectQuery.MoreOrEqual(TbMaterials.ConcentrationInWafer, Double.Parse(tbConcOfWaferStart.Text));
                if (tbConcOfWaferFinish.Enabled)
                    sqlSelectQuery.LessOrEqual(TbMaterials.ConcentrationInWafer, Double.Parse(tbConcOfWaferFinish.Text));
            }
            if (!rbDontWantWTFilter.Checked)
            {
                if (tbThicknessOfWafer.Enabled)
                {
                    double thickness = Double.Parse(tbThicknessOfWafer.Text);
                    if (cbWaferThicknessDim.Text == "нм")
                        thickness /= 1000;
                    sqlSelectQuery.Equal(TbMaterials.ThicknessOfWafer, thickness);
                }
                if (tbThicknessOfWaferStart.Enabled)
                {
                    double thickness = Double.Parse(tbThicknessOfWaferStart.Text);
                    if (cbWaferThicknessDimStart.Text == "нм")
                        thickness /= 1000;
                    sqlSelectQuery.MoreOrEqual(TbMaterials.ThicknessOfWafer, thickness);
                }
                if (tbThicknessOfWaferFinish.Enabled)
                {
                    double thickness = Double.Parse(tbThicknessOfWaferFinish.Text);
                    if (cbWaferThicknessDimFinish.Text == "нм")
                        thickness /= 1000;
                    sqlSelectQuery.LessOrEqual(TbMaterials.ThicknessOfWafer, thickness);
                }
            }
            if (!rbStatusAll.Checked)
            {
                if (rbStatusLaunched.Checked)
                    sqlSelectQuery.Equal(TbMaterials.LaunchedStatus, "YES");
                if (rbStatusNoLaunched.Checked)
                    sqlSelectQuery.Equal(TbMaterials.LaunchedStatus, "NO");
            }

            if (cbTechnology.Text != "")
            {
                sqlSelectQuery.Equal(TbMaterials.Technology, cbTechnology.Text);
            }
            if (cbTechProc.Text != "")
            {
                sqlSelectQuery.Equal(TbMaterials.TechProc, cbTechProc.Text);
            }
            if (cbManufacturer.Text != "")
            {
                sqlSelectQuery.Equal(TbMaterials.StructureManufacturer, cbManufacturer.Text);
            }
            if (tbIngot.Text != "")
            {
                sqlSelectQuery.Equal(TbMaterials.Ingot, tbIngot.Text);
            }
            if (tbCorresponds.Text != "")
            {
                sqlSelectQuery.Equal(TbMaterials.Corresponds, tbCorresponds.Text);
            }
        }
        private void cbPartyNumber_TextChanged(object sender, EventArgs e)
        {
            SqlSelect sqlSelect = new SqlSelect(TbMaterials.Name);
            sqlSelect.Equal(TbMaterials.NumberOfParcel, cbPartyNumber.Text);
            sqlSelect.RetrieveData();
            DataTable dt = sqlSelect.DataTable;

            cbWaferNumber.Text = "";
            cbWaferNumber.Items.Clear();

            var query =
                from DataRow row in dt.Rows
                select row[TbMaterials.NumberOfWafer].ToString();
            cbWaferNumber.Items.AddRange( query.ToArray() );
        }
        private void InitDgvEpitStructure()
        {
            dgvEpitStructure.ColumnCount = _nameOfColumns.Length;
            for (int i = 0; i < _nameOfColumns.Length; i++)
                dgvEpitStructure.Columns[i].Name = _nameOfColumns[i];
            dgvEpitStructure.ReadOnly = true;
            dgvEpitStructure.Font = new Font("Microsoft Sans Serif", 8);
            dgvEpitStructure.ColumnHeadersDefaultCellStyle.Font = new Font("Microsoft Sans Serif", 8);
            dgvEpitStructure.BackgroundColor = SystemColors.Control;
            dgvEpitStructure.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
            dgvEpitStructure.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            dgvEpitStructure.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;

            string nameOfTableWithEpitStructure = (string) _currSqlSelect.GetValueOfField(TbMaterials.NameOfTableWithEpitStructure);
            SqlSelect sqlSelect = new SqlSelect(nameOfTableWithEpitStructure)
            {
                OrderByField = TbEpitStructure.Number,
                SortIsAscending = false
            };
            sqlSelect.RetrieveData();

            dgvEpitStructure.RowCount = sqlSelect.CountOfRows + 1;
            for (int i = 0; i < sqlSelect.CountOfRows; i++)
            {
                for (int col = 0; col < _nameOfColumns.Length; col++)
                {
                    string res = sqlSelect.GetValueOfField(_indexOfColumns[col], i).ToString();
                    if (col == 4)
                        res = ((double) sqlSelect.GetValueOfField(_indexOfColumns[col], i)).ToString("0.0##E+00");
                    if (col == 0 && res == "0")
                        res = "Подложка";

                    dgvEpitStructure.Rows[i].Cells[col].Value = res;
                }
            }

            dgvEpitStructure.AutoResizeColumns();
        }
        private void ConstructFormWithValue()
        {
            tbPartyNumber.Text = _currSqlSelect.GetValueOfField(TbMaterials.NumberOfParcel).ToString();
            tbWaferNumber.Text = _currSqlSelect.GetValueOfField(TbMaterials.NumberOfWafer).ToString();
            rtbComment.Text = _currSqlSelect.GetValueOfField(TbMaterials.Comment).ToString();
            cbAuthor.Text = _currSqlSelect.GetValueOfField(TbMaterials.AuthorOfRecord).ToString();
            cbTechnology.Text = _currSqlSelect.GetValueOfField(TbMaterials.Technology).ToString();
            tbIngot.Text = _currSqlSelect.GetValueOfField(TbMaterials.Ingot).ToString();
            tbCorrespond.Text =  _currSqlSelect.GetValueOfField(TbMaterials.Corresponds).ToString();
            cbWaferManufacturer.Text = _currSqlSelect.GetValueOfField(TbMaterials.WaferManufacturer).ToString();
            cbMaterialOfWafer.Text = _currSqlSelect.GetValueOfField(TbMaterials.MaterialOfWafer).ToString();
            cbTypeOfWafer.Text = _currSqlSelect.GetValueOfField(TbMaterials.TypeOfWafer).ToString();
            tbConcOfWafer.Text = _currSqlSelect.GetValueOfField(TbMaterials.ConcentrationInWafer).ToString();
            tbThickOfWafer.Text =  _currSqlSelect.GetValueOfField(TbMaterials.ThicknessOfWafer).ToString();
            dtpRecordMaterial.Value = (DateTime) _currSqlSelect.GetValueOfField(TbMaterials.CreationDate);
            cbManufacturer.Text =  _currSqlSelect.GetValueOfField(TbMaterials.StructureManufacturer).ToString();

            string strResistance =  _currSqlSelect.GetValueOfField(TbMaterials.WaferResistance).ToString();
            if (strResistance != "")
            {
                double resistance = Double.Parse(strResistance);
                cbWaferResistance.Text = resistance.ToString("0.0##E+00");
            }

            cbWaferDiameter.Text =  _currSqlSelect.GetValueOfField(TbMaterials.WaferDiameter).ToString();
            cbTechProc.Text =  _currSqlSelect.GetValueOfField(TbMaterials.TechProc).ToString();

            // получение стека эпитаксиальных структур
            string nameOfTableWithEpitStructure =  _currSqlSelect.GetValueOfField(TbMaterials.NameOfTableWithEpitStructure).ToString();
            SqlSelect sqlSelect = new SqlSelect(TbEpitHost.Name);
            sqlSelect.Equal(TbEpitHost.NameOfEpitStructureTable, nameOfTableWithEpitStructure);
            sqlSelect.RetrieveData();
            tbTypeOfEpitStruct.Text = sqlSelect.GetValueOfField(TbEpitHost.UserName).ToString();

            InitDgvEpitStructure();

            // обновляем контролы без изменения БД
            bool copy = _editMode;
            _editMode = false;
            string userValidation = _currSqlSelect.GetValueOfField(TbMaterials.VerificationStatus).ToString();
            cbUserValidation.CheckState = userValidation == "YES" ? CheckState.Checked : CheckState.Unchecked;
            string isLaunched = _currSqlSelect.GetValueOfField(TbMaterials.LaunchedStatus).ToString();
            cbIsLaunched.CheckState = isLaunched == "YES" ? CheckState.Checked : CheckState.Unchecked;
            _editMode = copy;

            string recordIdOfEpitStructureFile =  _currSqlSelect.GetValueOfField(TbMaterials.RecordIdOfEpitStructureFile).ToString();
            if (recordIdOfEpitStructureFile != "")
            {
                SqlSelect select1 = new SqlSelect(TbFilesPool.Name);
                select1.Equal(TbFilesPool.FileID, recordIdOfEpitStructureFile);
                select1.RetrieveData();
                lblOpenScanOfPassFile.Text = select1.GetValueOfField(TbFilesPool.NameOfFile).ToString();
                _pathToScanPassFile = ClientLibrary.DownloadFileFromServer(recordIdOfEpitStructureFile);
                if (_pathToScanPassFile != null)
                    pbEpitStructImage.Load(_pathToScanPassFile);
            }

            string recordIdOfAttachmentFile = _currSqlSelect.GetValueOfField(TbMaterials.RecordIdOfAttachmentFile).ToString();
            if (recordIdOfAttachmentFile != "")
            {
                SqlSelect select2 = new SqlSelect(TbFilesPool.Name);
                select2.Equal(TbFilesPool.FileID, recordIdOfAttachmentFile);
                select2.RetrieveData();
                lblOpenAttFile.Text = select2.GetValueOfField(TbFilesPool.NameOfFile).ToString();
                _pathToAttFile = ClientLibrary.DownloadFileFromServer(recordIdOfAttachmentFile);
            }

            MakeControlsReadOnly();
        }