protected virtual void OnChanged(DataProviderEventArgs args) { if (args.ProcessLossChanged) { myProcessLossList = null; myProcessLossHash = null; } if (args.RawChanged) { myRawHash = null; myRawList = null; } if (args.TotalLossChanged) { myTotalLossList = null; myTotalLossHash = null; } if (Changed != null) { Changed(this, args); } }
/// <summary> /// получение таблицы потерь /// </summary> /// <returns>Массив записей потерь</returns> protected override SortableBindingList <DataTotalLoss> LoadTotalLossList() { DataTable totalLossTable = null; String sql = "SELECT * FROM totalLoss ORDER BY number ASC"; try { if (this.conn.State == ConnectionState.Closed) { this.conn.Open(); } this.adapter.SelectCommand = new OdbcCommand(sql, this.conn); DataSet ds = new DataSet("Loss"); ds.Locale = CultureInfo.InvariantCulture; this.adapter.Fill(ds); totalLossTable = ds.Tables[0]; } catch (OdbcException pe) { MessageBox.Show(pe.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, 0); return(null); } SortableBindingList <DataTotalLoss> ret = new SortableBindingList <DataTotalLoss>(); for (int i = 0; i < totalLossTable.Rows.Count; i++) { DataTotalLoss curData = new DataTotalLoss(null); curData.Id = Convert.ToInt32(totalLossTable.Rows[i]["id"], CultureInfo.InvariantCulture); curData.Name = totalLossTable.Rows[i]["name"].ToString(); curData.Quantity = Convert.ToDecimal(totalLossTable.Rows[i]["number"], CultureInfo.InvariantCulture); curData.Comment = totalLossTable.Rows[i]["comment"].ToString(); curData.IsChanged = false; ret.Add(curData); } return(ret); }
// обновление списка и структуры после изменения БД void dp_Changed(object sender, DataProviderEventArgs args) { //int prevIDnum = currentRecord.id; //panelTotalLossData1._data = null; //panelRawData1._data = null; int curItem = listBox1.SelectedIndices[0]; switch (myRecType) { case DataBaseType.TotalLossType: if (!args.TotalLossChanged) { return; // если обновление не тех данных, то просто выходим } SortableBindingList <DataTotalLoss> newLoss = Config.DP.TotalLossList; for (int i = 0; i < newLoss.Count; i++) { if (newLoss[i].Equals(listBox1.Items[curItem])) { curItem = i; break; } } listBox1.Items.Clear(); listBox1.Items.AddRange(newLoss.ToArray()); break; case DataBaseType.RawType: if (!args.RawChanged) { return; } SortableBindingList <DataRawStruct> newRaw = Config.DP.RawList; for (int i = 0; i < newRaw.Count; i++) { if (((DataRawStruct)newRaw[i]).Equals(listBox1.Items[curItem])) { curItem = i; break; } } listBox1.Items.Clear(); listBox1.Items.AddRange(Config.DP.RawList.ToArray()); break; case DataBaseType.ProcessLossType: if (!args.ProcessLossChanged) { return; } newRaw = Config.DP.ProcessLossList; for (int i = 0; i < newRaw.Count; i++) { if (newRaw[i].Equals(listBox1.Items[curItem])) { curItem = i; break; } } listBox1.Items.Clear(); listBox1.Items.AddRange(Config.DP.ProcessLossList.ToArray()); break; default: throw new NotImplementedException("Not implemented"); } if (listBox1.Items.Count > curItem) { listBox1.SelectedIndex = curItem; } else { listBox1.SelectedIndex = listBox1.Items.Count - 1; } this.IsDataChanged = false; //throw new Exception("The method or operation is not implemented."); }
protected override SortableBindingList <DataRawStruct> LoadDataRawList(string tableName) { DataTable comp_table = null; String sql = "SELECT * FROM " + tableName + " ORDER BY name ASC"; try { if (this.conn.State == ConnectionState.Closed) { this.conn.Open(); } this.adapter.SelectCommand = new OdbcCommand(sql, this.conn); DataSet ds = new DataSet("tables"); ds.Locale = CultureInfo.InvariantCulture; this.adapter.Fill(ds); comp_table = ds.Tables[0]; } catch (OdbcException pe) { MessageBox.Show(pe.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, 0); return(null); } SortableBindingList <DataRawStruct> ret = new SortableBindingList <DataRawStruct>(); for (int i = 0; i < comp_table.Rows.Count; i++) { DataRawStruct curRec = new DataRawStruct(null); curRec.Brutto = Convert.ToDecimal(comp_table.Rows[i]["brutto"] is DBNull ? 0 : comp_table.Rows[i]["brutto"], CultureInfo.InvariantCulture); curRec.Caloric = Convert.ToDecimal(comp_table.Rows[i]["caloric"] is DBNull ? 0 : comp_table.Rows[i]["caloric"], CultureInfo.InvariantCulture); curRec.starch = Convert.ToDecimal(comp_table.Rows[i]["starch"] is DBNull ? 0 : comp_table.Rows[i]["starch"], CultureInfo.InvariantCulture); curRec.saccharides = Convert.ToDecimal(comp_table.Rows[i]["saccharides"] is DBNull ? 0 : comp_table.Rows[i]["saccharides"], CultureInfo.InvariantCulture); curRec.cellulose = Convert.ToDecimal(comp_table.Rows[i]["cellulose"] is DBNull ? 0 : comp_table.Rows[i]["cellulose"], CultureInfo.InvariantCulture); curRec.cholesterol = Convert.ToDecimal(comp_table.Rows[i]["cholesterol"] is DBNull ? 0 : comp_table.Rows[i]["cholesterol"], CultureInfo.InvariantCulture); curRec.Comment = comp_table.Rows[i]["comment"].ToString(); curRec.fat = Convert.ToDecimal(comp_table.Rows[i]["fat"] is DBNull ? 0 : comp_table.Rows[i]["fat"], CultureInfo.InvariantCulture); curRec.acid = Convert.ToDecimal(comp_table.Rows[i]["acid"] is DBNull ? 0 : comp_table.Rows[i]["acid"], CultureInfo.InvariantCulture); curRec.ash = Convert.ToDecimal(comp_table.Rows[i]["ash"] is DBNull ? 0 : comp_table.Rows[i]["ash"], CultureInfo.InvariantCulture); curRec.Id = Convert.ToInt32(comp_table.Rows[i]["id"], CultureInfo.InvariantCulture); curRec.MineralCA = Convert.ToDecimal(comp_table.Rows[i]["mineralCa"] is DBNull ? 0 : comp_table.Rows[i]["mineralCa"], CultureInfo.InvariantCulture); curRec.MineralFE = Convert.ToDecimal(comp_table.Rows[i]["mineralFe"] is DBNull ? 0 : comp_table.Rows[i]["mineralFe"], CultureInfo.InvariantCulture); curRec.MineralK = Convert.ToDecimal(comp_table.Rows[i]["mineralK"] is DBNull ? 0 : comp_table.Rows[i]["mineralK"], CultureInfo.InvariantCulture); curRec.MineralMG = Convert.ToDecimal(comp_table.Rows[i]["mineralMg"] is DBNull ? 0 : comp_table.Rows[i]["mineralMg"], CultureInfo.InvariantCulture); curRec.MineralNA = Convert.ToDecimal(comp_table.Rows[i]["mineralNa"] is DBNull ? 0 : comp_table.Rows[i]["mineralNa"], CultureInfo.InvariantCulture); curRec.MineralP = Convert.ToDecimal(comp_table.Rows[i]["mineralP"] is DBNull ? 0 : comp_table.Rows[i]["mineralP"], CultureInfo.InvariantCulture); curRec.Name = comp_table.Rows[i]["name"].ToString(); curRec.NormativDoc = comp_table.Rows[i]["normativDoc"].ToString(); curRec.protein = Convert.ToDecimal(comp_table.Rows[i]["protein"] is DBNull ? 0 : comp_table.Rows[i]["protein"], CultureInfo.InvariantCulture); curRec.vitaminA = Convert.ToDecimal(comp_table.Rows[i]["vitaminA"] is DBNull ? 0 : comp_table.Rows[i]["vitaminA"], CultureInfo.InvariantCulture); curRec.VitaminB = Convert.ToDecimal(comp_table.Rows[i]["vitaminB"] is DBNull ? 0 : comp_table.Rows[i]["vitaminB"], CultureInfo.InvariantCulture); curRec.VitaminB1 = Convert.ToDecimal(comp_table.Rows[i]["vitaminB1"] is DBNull ? 0 : comp_table.Rows[i]["vitaminB1"], CultureInfo.InvariantCulture); curRec.VitaminB2 = Convert.ToDecimal(comp_table.Rows[i]["vitaminB2"] is DBNull ? 0 : comp_table.Rows[i]["vitaminB2"], CultureInfo.InvariantCulture); curRec.VitaminC = Convert.ToDecimal(comp_table.Rows[i]["vitaminC"] is DBNull ? 0 : comp_table.Rows[i]["vitaminC"], CultureInfo.InvariantCulture); curRec.VitaminPP = Convert.ToDecimal(comp_table.Rows[i]["vitaminPP"] is DBNull ? 0 : comp_table.Rows[i]["vitaminPP"], CultureInfo.InvariantCulture); curRec.Water = Convert.ToDecimal(comp_table.Rows[i]["water"] is DBNull ? 0 : comp_table.Rows[i]["water"], CultureInfo.InvariantCulture); if (comp_table.Columns.Contains("inSostav")) { curRec.InSostav = Convert.ToBoolean(comp_table.Rows[i]["inSostav"] is DBNull ? true : comp_table.Rows[i]["inSostav"], CultureInfo.InvariantCulture); } if (comp_table.Columns.Contains("inRecept")) { curRec.InRecept = Convert.ToBoolean(comp_table.Rows[i]["inRecept"] is DBNull ? true : comp_table.Rows[i]["inRecept"], CultureInfo.InvariantCulture); } curRec.IsChanged = false; ret.Add(curRec); } return(ret); }
internal void LoadData(DataRecept data) { this.tbName.TextChanged -= new System.EventHandler(this.tbTextChanged); this.tbNum.TextChanged -= new System.EventHandler(this.tbTextChanged); this.tbWater.TextChanged -= new System.EventHandler(this.tbTextChanged); this.tbWaterPlus.TextChanged -= new System.EventHandler(this.tbTextChanged); this.tbWaterMinus.TextChanged -= new System.EventHandler(this.tbTextChanged); this.tbTotalExit.TextChanged -= new System.EventHandler(this.tbTextChanged); this.tbNormativDoc.TextChanged -= new System.EventHandler(this.tbTextChanged); this.tbSource.TextChanged -= new System.EventHandler(this.tbTextChanged); this.tbPreview.TextChanged -= new System.EventHandler(this.tbTextChanged); this.cbTotalLoss.TextChanged -= new System.EventHandler(this.cbTextChanged); this.tbAcidity.TextChanged -= new System.EventHandler(this.tbTextChanged); dgvRawList.CellValueChanged -= new DataGridViewCellEventHandler(dgvRawList_CellValueChanged); myData = data; // настраиваем список потерь if (myTotalLoss == null) { myTotalLoss = Config.DP.TotalLossList; cbTotalLoss.Items.Clear(); if (myTotalLoss != null && myTotalLoss.Count > 0) { cbTotalLoss.Items.AddRange(myTotalLoss.ToArray()); } } // настраиваем список компонент if (myRaw == null) { myRaw = Config.DP.RawList; cbName.Items.Clear(); cbSetWater.Items.Clear(); if (myRaw != null && myRaw.Count > 0) { cbName.Items.AddRange(myRaw.ToArray()); cbSetWater.Items.AddRange(myRaw.ToArray()); } } // настраиваем список производственных потерь if (myProcessLoss == null) { myProcessLoss = Config.DP.ProcessLossList; dgvRecProcessLoss.Items.Clear(); if (myProcessLoss != null && myProcessLoss.Count > 0) { dgvRecProcessLoss.Items.AddRange(myProcessLoss.ToArray()); } } // шапка формы tbName.Text = data.Name; tbNum.Text = data.Id.ToString(CultureInfo.CurrentCulture); tbWater.Text = data.water.ToString(CultureInfo.CurrentCulture); tbWaterPlus.Text = data.waterPlus.ToString(CultureInfo.CurrentCulture); tbWaterMinus.Text = data.waterMinus.ToString(CultureInfo.CurrentCulture); tbTotalExit.Text = data.TotalExit.ToString(CultureInfo.CurrentCulture); tbCountExit.Text = data.CountExit.ToString(CultureInfo.CurrentCulture); tbPreview.Text = data.preview; tbSource.Text = data.source; tbNormativDoc.Text = data.normativDoc; if (data.totalLoss != null) { cbTotalLoss.SelectedIndex = data.totalLoss.TotalLossNum; } else { cbTotalLoss.SelectedIndex = 0; } tbAcidity.Text = data.Acidity.ToString(CultureInfo.CurrentCulture); // TODO: добавить хранение элемента "вода" в настройках проги и включить отображение пункта когда он будет готов // тело формы dgvRawList.Nodes.Clear(); //dgvRawList.Rows.Clear(); LoadReceptData(dgvRawList.Nodes, data); //MessageBox.Show("Start Load2: " + dgvRawList.Nodes.Count); rbCalcExit.Checked = data.isCalcExit; rbCalcWater.Checked = data.isCalcWater; rbSetWater.Checked = data.isSetWater; this.tbName.TextChanged += new System.EventHandler(this.tbTextChanged); this.tbNum.TextChanged += new System.EventHandler(this.tbTextChanged); this.tbWater.TextChanged += new System.EventHandler(this.tbTextChanged); this.tbWaterPlus.TextChanged += new System.EventHandler(this.tbTextChanged); this.tbWaterMinus.TextChanged += new System.EventHandler(this.tbTextChanged); this.tbTotalExit.TextChanged += new System.EventHandler(this.tbTextChanged); this.tbNormativDoc.TextChanged += new System.EventHandler(this.tbTextChanged); this.tbSource.TextChanged += new System.EventHandler(this.tbTextChanged); this.tbPreview.TextChanged += new System.EventHandler(this.tbTextChanged); this.cbTotalLoss.TextChanged += new System.EventHandler(this.cbTextChanged); dgvRawList.CellValueChanged += new DataGridViewCellEventHandler(dgvRawList_CellValueChanged); this.tbAcidity.TextChanged += new System.EventHandler(this.tbTextChanged); // Устанавливаем радиокнопки выбора // this.rbCalcWater.CheckedChanged -= new System.EventHandler(this.RbCheckedChanged); // this.rbCalcExit.CheckedChanged -= new System.EventHandler(this.RbCheckedChanged); // this.rbSetWater.CheckedChanged -= new System.EventHandler(this.RbCheckedChanged); // rbCalcExit.Checked = data.isCalcExit; // rbCalcWater.Checked = data.isCalcWater; // rbSetWater.Checked = data.isSetWater; // this.rbCalcWater.CheckedChanged += new System.EventHandler(this.RbCheckedChanged); // this.rbCalcExit.CheckedChanged += new System.EventHandler(this.RbCheckedChanged); // this.rbSetWater.CheckedChanged += new System.EventHandler(this.RbCheckedChanged); myData.Changed += new EventHandler <DataBaseEventArgs> (_data_Changed); }