public void AddRowinFromBase(FromDataBase svGr) { FromDataBaseWide fromDataBaseWide = new FromDataBaseWide(); fromDataBaseWide.ChangeDataBaseWide(svGr); fromDataBaseWide.Id = ++idCounter; FromDataBaseCl.Add(fromDataBaseWide); }
private void ChangeSpec() { if (ComboDate.Items.Count > 0 && ComboDate.DataSource != null) { FromDataBase newDataBase = ComboDate.SelectedItem as FromDataBase; SveraParam.ChangeSpec(sverPDataGrid, newDataBase); } else { for (int i = 0; i <= sverPDataGrid.Rows.Count - 1; i++) { sverPDataGrid.Rows[i].Cells[sverPDataGrid.Columns[SveraParam.ColDatagridNames.Value].Index].Value = ""; } } }
public static string GetNaim(List <FromDataBase> fromDataBase, long idBase) { string getNaim = ""; if (fromDataBase != null && fromDataBase.Count > 0) { FromDataBase fromBaseId = fromDataBase.FirstOrDefault <FromDataBase>(fr => fr.IdBase == idBase); if (fromBaseId != null && fromBaseId.IdBase > 0) { getNaim = fromBaseId.GetNaim(); } } return(getNaim); }
public static List <FromDataBase> LoadFromDataBase() { SQLiteDataAdapter da = null; DataSet ds = null; SQLiteConnection SQLconnect = null; SQLiteDataReader reader = null; SQLiteCommand command = null; try { List <FromDataBase> dataBaseList = new List <FromDataBase>(); string strSelect; string databasePath = FunctionUse.GetDataBasePath(); if (System.IO.File.Exists(databasePath) == true) { SQLconnect = new SQLiteConnection(); SQLconnect.ConnectionString = "Data Source=" + databasePath + ";"; SQLconnect.ParseViaFramework = true; SQLconnect.Open(); command = new SQLiteCommand(SQLconnect); command.CommandText = "SELECT name FROM sqlite_master WHERE type = 'table' AND name = 'Production';"; reader = command.ExecuteReader(); if (reader.HasRows == true) { FunctionUse.TestTableAndColumns(SQLconnect); strSelect = "SELECT id, naim, naimKrat, elGroup, tipPostav, tipOborud, markaOborud, docObozn, kod, postav, edIzm, edIzmW, koefToWord, massa, vedRabot, vzriv, klimat, otdel, ip, vedTable FROM Production"; da = new SQLiteDataAdapter(strSelect, SQLconnect); ds = new DataSet(); da.Fill(ds, "Production"); if (ds.Tables["Production"].Rows.Count > 0) { FromDataBase fromDataBaseSample; for (int i = 0; i <= ds.Tables["Production"].Rows.Count - 1; i++) { fromDataBaseSample = new FromDataBase( long.Parse(ds.Tables["Production"].Rows[i].ItemArray[0].ToString()), ds.Tables["Production"].Rows[i].ItemArray[1].ToString(), ds.Tables["Production"].Rows[i].ItemArray[2].ToString(), (YesNoDif)int.Parse(ds.Tables["Production"].Rows[i].ItemArray[3].ToString()), ds.Tables["Production"].Rows[i].ItemArray[4].ToString(), ds.Tables["Production"].Rows[i].ItemArray[5].ToString(), ds.Tables["Production"].Rows[i].ItemArray[6].ToString(), ds.Tables["Production"].Rows[i].ItemArray[7].ToString(), ds.Tables["Production"].Rows[i].ItemArray[8].ToString(), ds.Tables["Production"].Rows[i].ItemArray[9].ToString(), ds.Tables["Production"].Rows[i].ItemArray[10].ToString(), ds.Tables["Production"].Rows[i].ItemArray[11].ToString(), double.Parse(ds.Tables["Production"].Rows[i].ItemArray[12].ToString()), double.Parse(ds.Tables["Production"].Rows[i].ItemArray[13].ToString()), ds.Tables["Production"].Rows[i].ItemArray[14].ToString(), ds.Tables["Production"].Rows[i].ItemArray[15].ToString(), ds.Tables["Production"].Rows[i].ItemArray[16].ToString(), ds.Tables["Production"].Rows[i].ItemArray[17].ToString(), ds.Tables["Production"].Rows[i].ItemArray[18].ToString(), BytesToList(ds.Tables["Production"].Rows[i].ItemArray[19] as byte[])); dataBaseList.Add(fromDataBaseSample); } dataBaseList.Sort(); } } if (da != null) { da.Dispose(); } if (SQLconnect != null) { SQLconnect.Close(); } if (reader != null) { reader.Dispose(); } if (command != null) { command.Dispose(); } } return(dataBaseList); } catch (Exception ex) { if (da != null) { da.Dispose(); } if (SQLconnect != null) { SQLconnect.Close(); } if (reader != null) { reader.Dispose(); } if (command != null) { command.Dispose(); } throw new Exception("LoadFromDataBase", ex); } }
private void prinat_Click(object sender, EventArgs e) { try { DetalizedCl detUse = null; if (ComboDate.SelectedIndex > -1) { SveraGrFormDataBase sveraGrDb = ComboDate.SelectedItem as SveraGrFormDataBase; FromDataBase svGr = sveraGr.FromDataBase.FirstOrDefault(sv => sv.IdBase == sveraGrDb.NaimId); bool ins = false; int ind = -1; if (sveraGr.FromDataBaseCl.Count > 0) { ind = sveraGr.FromDataBaseCl.FindIndex(cp => cp.IdBase == sveraGrDb.NaimId); if (ind > -1) { } else { ins = true; } } else { ins = true; } if (ins == true) { sveraGr.AddRowinFromBase(svGr); sveraGr.UpdateDetalized(sveraGr.Detalized); } if (ind == -1) { ind = sveraGr.FromDataBaseCl.FindIndex(cp => cp.IdBase == sveraGrDb.NaimId); } sveraGr.FromDataBaseCl[ind].ElGroup = YesNoDif.Yes; sveraGr.FromDataBaseCl[ind].PosicUse = YesNoDif.Yes; sveraGr.FromDataBaseCl[ind].Detail = SveraParam.Detalization[(int)SveraClass.detalizationEnum.Detail]; sveraGr.FromDataBaseCl[ind].DetailW = SveraParam.Detalization[(int)SveraClass.detalizationEnum.DetailSum]; if (sveraGr.Detalized != null && sveraGr.Detalized.Count > 0) { detUse = sveraGr.Detalized.First(d => d.IdBase == svGr.IdBase); detUse.Check = true; } if (sveraGrDb.GroupId != null && sveraGrDb.GroupId != "") { List <DetalizedCl.IdAndKol> KolAndId = sveraGr.HashOutKolAndId(sveraGrDb.GroupId); if (KolAndId != null && KolAndId.Count > 0) { foreach (DetalizedCl.IdAndKol klId in KolAndId) { int indsec = sveraGr.FromDataBaseCl.FindIndex(n => n.IdBase == klId.Id); FromDataBase svGrKol = sveraGr.FromDataBase.FirstOrDefault(sv => sv.IdBase == klId.Id); if (indsec > -1) { klId.Id = sveraGr.FromDataBaseCl[indsec].Id; } else { sveraGr.AddRowinFromBase(svGrKol); indsec = sveraGr.FromDataBaseCl.Count - 1; klId.Id = sveraGr.FromDataBaseCl[sveraGr.FromDataBaseCl.Count - 1].Id; } sveraGr.FromDataBaseCl[indsec].ElGroup = YesNoDif.No; sveraGr.FromDataBaseCl[indsec].PosicUse = YesNoDif.No; } if (detUse != null) { detUse.AddRows(KolAndId); } } } sveraGr.UpdateGroup(); updateCheck(sveraGr.Detalized); if (detUse != null) { checkGroup.SelectedIndex = sveraGr.Detalized.FindIndex(d => d.Id == detUse.Id); } } else { MessageBox.Show("Необходимо выбрать шаблон из базы", "База данных", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { MessageBox.Show(ex.Message); MessageBox.Show(ex.StackTrace); if (ex.InnerException != null) { MessageBox.Show(ex.InnerException.ToString()); } } }