private void btnSave_Click(object sender, EventArgs e)
        {
            if (m_selRow == -1)
            {
                MessageBox.Show("Выберите чугун из имеющихся миксеров");
                return;
            }
            WordPool<double> wpIron = new WordPool<double>(0.0);
            WordPool<double> wpProps = new WordPool<double>(0.0);
            int cntMix = 0;
            for (var i = 2; i < dgw.Rows[m_selRow].Cells.Count; i++)
            {
                string key = dgw.Columns[i].HeaderText;
                wpIron.SetWord(key, (double)dgw.Rows[m_selRow].Cells[i].Value);
            }
            for (int i = Program.face.ch_Iron.m_propsStart; i < Program.face.ch_Iron.gridChem.RowCount; i++)
            {
                wpProps.SetWord((string)Program.face.ch_Iron.gridChem.Rows[i].Cells[0].Value, (double)Program.face.ch_Iron.gridChem.Rows[i].Cells[1].Value);
            }
            Program.face.ch_Iron.m_inFP.Clear();
            Program.face.ch_Iron.gridChem.Rows.Clear();
            Program.face.ch_Iron.gridChem.RowCount = wpIron.Count;
            for (var rowCnt = 0;
                rowCnt < Program.face.ch_Iron.gridChem.RowCount;
                rowCnt++)
            {
                Program.face.ch_Iron.gridChem.Rows[rowCnt].Cells[0].Value
                    = wpIron.ElementAt(rowCnt).Key;
                Program.face.ch_Iron.gridChem.Rows[rowCnt].Cells[1].Value
                    = wpIron.ElementAt(rowCnt).Value;
                Program.face.ch_Iron.m_inFP.SetWord(wpIron.ElementAt(rowCnt).Key,
                    wpIron.ElementAt(rowCnt).Value);

            }
            Program.face.ch_Iron.m_propsStart =
                Program.face.ch_Iron.gridChem.RowCount;
            if (wpProps.Count > 0)
            {
                Program.face.ch_Iron.gridChem.Rows.Add(wpProps.Count);
                for (var rowCnt = Program.face.ch_Iron.m_propsStart; rowCnt < Program.face.ch_Iron.gridChem.RowCount; rowCnt++)
                {
                    Program.face.ch_Iron.gridChem.Rows[rowCnt].Cells[0].Value
                        = wpProps.ElementAt(rowCnt - Program.face.ch_Iron.m_propsStart).Key;
                    Program.face.ch_Iron.gridChem.Rows[rowCnt].Cells[1].Value
                        = wpProps.ElementAt(rowCnt - Program.face.ch_Iron.m_propsStart).Value;
                    Program.face.ch_Iron.m_inFP.SetWord(wpProps.ElementAt(rowCnt - Program.face.ch_Iron.m_propsStart).Key,
                        wpProps.ElementAt(rowCnt - Program.face.ch_Iron.m_propsStart).Value);

                }
            }
            Program.face.ch_Iron.m_readOnLoad = false;
            Close();
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            //MessageBox.Show(string.Format("Sum {0}", countScrapShares()));
            #if DB_IS_ORACLE
            Program.OraCmd.CommandText = "SELECT "
            + "ELEMENT.NAME, ELEMENT.\"VALUE\" "
            + "FROM ELEMENT, SCRAP "
            + "WHERE ELEMENT.SID = SCRAP.ID AND (SCRAP.CODE = :C)";
            Program.OraCmd.Parameters.Clear();
            Program.OraCmd.Parameters.Add(new OracleParameter("C", OracleDbType.Int16, System.Data.ParameterDirection.Input));
            #else
            ScrapDataSetTableAdapters.ScrapMixerTableAdapter ada = new ScrapMixerTableAdapter();
            ScrapDataSet.ScrapMixerDataTable tbl = new ScrapDataSet.ScrapMixerDataTable();
            #endif
            WordPool<double> wpProps = new WordPool<double>(0.0);
            WordPool<double> wpTotal = new WordPool<double>(0.0);
            for (int i = 0; i < gridScrap.RowCount; i++)
            {
                if (gridScrap.Rows[i].Cells[1].Value == null) break;
                short code = Convert.ToInt16(gridScrap.Rows[i].Cells[1].Value);
                short shares = Convert.ToInt16(gridScrap.Rows[i].Cells[0].Value);
            #if DB_IS_ORACLE
                Program.OraCmd.Parameters["C"].Value = code;
                if (Program.OraCmd.Connection.State != System.Data.ConnectionState.Closed)
                {
                    Program.OraCmd.Connection.Close();
                }
                Program.OraCmd.Connection.Open();
                Program.OraReader = Program.OraCmd.ExecuteReader();
                if (Program.OraReader.HasRows)
                {
                    while (Program.OraReader.Read())
                    {
                        string key = Convert.ToString(Program.OraReader[0]);
                        double val = Convert.ToDouble(Program.OraReader[1]);
                        wpTotal.SetWord(key, wpTotal.GetWord(key) + shares * val);
                    }
                }
            #else
                try
                {
                    ada.Connection.ConnectionString = "Data Source=Chemistry.sdf";
                    ada.FillByCode(tbl, code);
                }
                catch (Exception) { }
                ;
                for (int j = 0; j < tbl.Count; j++)
                {
                    string key = tbl[j].Name;
                    wpTotal.SetWord(key, wpTotal.GetWord(key) + shares * tbl[j].Value);
                }
            #endif
            }
            double scaleFactor = 1.0 / countScrapShares();
            for (int k = 0; k < wpTotal.Count; k++)
            {
                wpTotal.SetWord(wpTotal.ElementAt(k).Key, scaleFactor * wpTotal.ElementAt(k).Value);
            }
            for (int i = Program.face.ch_Scrap.m_propsStart; i < Program.face.ch_Scrap.gridChem.RowCount; i++)
            {
                wpProps.SetWord((string)Program.face.ch_Scrap.gridChem.Rows[i].Cells[0].Value, (double)Program.face.ch_Scrap.gridChem.Rows[i].Cells[1].Value);
            }
            Program.face.ch_Scrap.m_inFP.Clear();
            Program.face.ch_Scrap.gridChem.Rows.Clear();
            Program.face.ch_Scrap.gridChem.RowCount = wpTotal.Count;
            for (var rowCnt = 0;
                rowCnt < Program.face.ch_Scrap.gridChem.RowCount;
                rowCnt++)
            {
                Program.face.ch_Scrap.gridChem.Rows[rowCnt].Cells[0].Value
                    = wpTotal.ElementAt(rowCnt).Key;
                Program.face.ch_Scrap.gridChem.Rows[rowCnt].Cells[1].Value
                    = wpTotal.ElementAt(rowCnt).Value;
                Program.face.ch_Scrap.m_inFP.SetWord(wpTotal.ElementAt(rowCnt).Key,
                    wpTotal.ElementAt(rowCnt).Value);
            }
            Program.face.ch_Scrap.m_propsStart =
                Program.face.ch_Scrap.gridChem.RowCount;
            if (wpProps.Count > 0)
            {
                Program.face.ch_Scrap.gridChem.Rows.Add(wpProps.Count);
                for (var rowCnt = Program.face.ch_Scrap.m_propsStart; rowCnt < Program.face.ch_Scrap.gridChem.RowCount; rowCnt++)
                {
                    Program.face.ch_Scrap.gridChem.Rows[rowCnt].Cells[0].Value
                        = wpProps.ElementAt(rowCnt - Program.face.ch_Scrap.m_propsStart).Key;
                    Program.face.ch_Scrap.gridChem.Rows[rowCnt].Cells[1].Value
                        = wpProps.ElementAt(rowCnt - Program.face.ch_Scrap.m_propsStart).Value;
                    Program.face.ch_Scrap.m_inFP.SetWord(wpProps.ElementAt(rowCnt - Program.face.ch_Scrap.m_propsStart).Key,
                        wpProps.ElementAt(rowCnt - Program.face.ch_Scrap.m_propsStart).Value);

                }
            }
            Program.face.ch_Scrap.m_readOnLoad = false;
            Close();
        }