public static void InsertFromANTables(DataSet tableList) { using (var currentContext = new TrudoyomkostDBContext(Properties.Settings.Default.TrudoyomkostDBConnectionString)) { LinqQueryForTrudoyomkost.FilldcInfProducts(currentContext, ref DcInfProducts); LinqQueryForTrudoyomkost.FillDictDetNumID(currentContext, ref DicDetNumAndId); LinqQueryForTrudoyomkost.FillDictDepIDCode(currentContext, ref DicDepCodeAndId); Properties.Settings.Default.DetID = currentContext.InfDet.ToList().Count == 0 ? 0 : ++currentContext.InfDet.ToList().Last().ID; } if (int.Parse((tableList.Tables[0].Rows[0].Field <string>("CEH").Trim())) != Properties.Settings.Default.DepNum) { return; } _whereUseTableAdapter.DeleteAllQuery(); foreach (DataTable itemTable in tableList.Tables) { foreach (DataRow itemRow in itemTable.Rows) { string NDET = (string)itemRow["NDET"]; if (!DicDetNumAndId.ContainsKey(NDET)) { var infDetItem = FillItemInfDet(itemRow); FilltmpInfDetRow(ref infDetItem); DicDetNumAndId.Add(NDET, Properties.Settings.Default.DetID); Properties.Settings.Default.DetID++; } var itemWhereuse = FillItemWhereUse(itemRow); FilltmpWhereUseRow(itemWhereuse); } } Properties.Settings.Default.Save(); SqlCeBulkCopy bulkInsert = new SqlCeBulkCopy(connString); DataTable tmptbInfDet = InfDetDataTable; DataTable tmptbWhereUse = WhereUseDataTable; if (tmptbInfDet.Rows.Count > 0) { bulkInsert.DestinationTableName = "infDet"; bulkInsert.WriteToServer(tmptbInfDet); } if (tmptbWhereUse.Rows.Count > 0) { bulkInsert.DestinationTableName = "whereUse"; bulkInsert.WriteToServer(tmptbWhereUse); } WhereUseDataTable.Clear(); InfDetDataTable.Clear(); bulkInsert.Close(); }
public static void InsertDt <T>(ref T dtInput, string tableName) where T : DataTable { SqlCeBulkCopy bulkInsert = new SqlCeBulkCopy(connString); DataTable tmptable = dtInput; if (tmptable.Rows.Count > 0) { bulkInsert.DestinationTableName = tableName; bulkInsert.WriteToServer(tmptable); } dtInput.Clear(); bulkInsert.Close(); bulkInsert.Dispose(); tmptable.Dispose(); }
public static void InsertFromTARIF() { foreach (var item in TarifDataTable) { InfTariff infTariff = FillInfTarifItem(item); FilltmpInfTarifDetRow(ref infTariff); } SqlCeBulkCopy bulkInsert = new SqlCeBulkCopy(connString); DataTable tmpInfTariff = InfTariffDataTable; if (tmpInfTariff.Rows.Count > 0) { bulkInsert.DestinationTableName = "infTariff"; bulkInsert.WriteToServer(tmpInfTariff); } bulkInsert.Close(); bulkInsert.Dispose(); tmpInfTariff.Dispose(); }
public void AddDoubleItems() { this.Enabled = false; var labourNormlist = LinqQueryForTrudoyomkost.FillLabournNormForDet(_destinationDetID); foreach (var item in labourNormlist) { var whereOperUselstdel = LinqQueryForTrudoyomkost.FillWhereOperationUseList(item.ID); if (whereOperUselstdel.Count() > 0) { foreach (var applydel in whereOperUselstdel) { FillTrudoyomkostDB.WhereOperationUseList.Remove(applydel); } } FillTrudoyomkostDB.LabourNormTableAdapter.DeleteQuery(item.ID); FillTrudoyomkostDB.WhereOperationUseTableAdapter.DeleteQuery(item.ID); FillTrudoyomkostDB.LabourNormList.Remove(item); } labourNormlist = LinqQueryForTrudoyomkost.FillLabournNormForDet(_sourceDetID); using (var currentContext = new TrudoyomkostDBContext(Properties.Settings.Default.TrudoyomkostDBConnectionString)) { int Id = 0; int whereOperUseId = FillTrudoyomkostDB.WhereOperationUseList.Last().Id; Id = currentContext.LabourNorm.ToList().Max().ID; foreach (var item in labourNormlist) { var whereOperUselst = LinqQueryForTrudoyomkost.FillWhereOperationUseList(item.ID); if (whereOperUselst.Count() > 0) { Id++; //FillTrudoyomkostDB.LabourNormTableAdapter.InsertQuery(_destinationDetID, item.OperNum, item.DepRegion, item.ProfCode, item.NameKindWork, // item.TariffNetNum, item.KindPay, item.WorkerRate, item.ItemCTN, item.PreparTimeCTN, //item.ItemPayNorm, item.PreparTimePayNorm, item.Valuation, item.ValPreparTime, item.CoeffCTN, item.DocNum, item.Date, item.TaskNumber); FillTrudoyomkostDB.FilltmpLabourNormRow(new LabourNorm(Id, _destinationDetID, item.OperNum, item.DepRegion, item.ProfCode, item.NameKindWork, item.TariffNetNum, item.KindPay, item.WorkerRate, item.ItemCTN, item.PreparTimeCTN, item.ItemPayNorm, item.PreparTimePayNorm, item.Valuation, item.ValPreparTime, item.CoeffCTN, item.DocNum, DateTime.Now, item.TaskNumber)); FillTrudoyomkostDB.LabourNormList.Add(new LabourNorm(Id, _destinationDetID, item.OperNum, item.DepRegion, item.ProfCode, item.NameKindWork, item.TariffNetNum, item.KindPay, item.WorkerRate, item.ItemCTN, item.PreparTimeCTN, item.ItemPayNorm, item.PreparTimePayNorm, item.Valuation, item.ValPreparTime, item.CoeffCTN, item.DocNum, DateTime.Now, item.TaskNumber)); //currentContext.LabourNorm.InsertOnSubmit(new LabourNorm(Id, _destinationDetID, item.OperNum, item.DepRegion, item.ProfCode, // item.NameKindWork, item.TariffNetNum, item.KindPay, item.WorkerRate, item.ItemCTN, item.PreparTimeCTN, item.ItemPayNorm, item.PreparTimePayNorm, // item.Valuation, item.ValPreparTime, item.CoeffCTN, item.DocNum, DateTime.Now, item.TaskNumber)); foreach (var applyItem in whereOperUselst) { whereOperUseId++; FillTrudoyomkostDB.FilltmpWhereOperUseRow(new WhereOperationUse(Id, applyItem.SeriaFrom, applyItem.SeriaTo, applyItem.InfProductsChipher)); FillTrudoyomkostDB.WhereOperationUseList.Add(new WhereOperationUse(Id, applyItem.SeriaFrom, applyItem.SeriaTo, applyItem.InfProductsChipher, whereOperUseId)); //currentContext.WhereOperationUse.InsertOnSubmit(new WhereOperationUse(Id, applyItem.SeriaFrom, applyItem.SeriaTo, applyItem.InfProductsChipher,whereOperUseId)); //FillTrudoyomkostDB.WhereOperationUseTableAdapter.InsertQuery(Id, applyItem.SeriaFrom, applyItem.SeriaTo, applyItem.InfProductsChipher); } } //currentContext.SubmitChanges(); } DataTable tmpWhereOperUse = FillTrudoyomkostDB.WhereOperationUseDataTable; DataTable tmpLabourNorm = FillTrudoyomkostDB.LabourNormDataTable; SqlCeBulkCopy bulkInsert = new SqlCeBulkCopy(Properties.Settings.Default.TrudoyomkostDBConnectionString); if (tmpWhereOperUse.Rows.Count > 0) { bulkInsert.DestinationTableName = "whereOperationUse"; bulkInsert.WriteToServer(tmpWhereOperUse); } if (tmpLabourNorm.Rows.Count > 0) { bulkInsert.DestinationTableName = "LabourNorm"; bulkInsert.WriteToServer(tmpLabourNorm); } FillTrudoyomkostDB.LabourNormDataTable.Clear(); FillTrudoyomkostDB.WhereOperationUseDataTable.Clear(); bulkInsert.Close(); } this.Enabled = true; }
public static void InsertFromTNTables() { InfDetDataTable.Clear(); using (var newLocalDb = new TrudoyomkostDBContext(Properties.Settings.Default.TrudoyomkostDBConnectionString)) { LinqQueryForTrudoyomkost.FillDictDetNumID(newLocalDb, ref DicDetNumAndId); LinqQueryForTrudoyomkost.FillDictDepIDCode(newLocalDb, ref DicDepCodeAndId); LinqQueryForTrudoyomkost.FillDictInfProfession(newLocalDb, ref DictInfProfession); } int whereOperUseId = 1; foreach (var item in Tn148DataTable) { if (DicDetNumAndId.ContainsKey(item.NDET)) { LabourNorm itemlabourNorm = FillItemLabourNorm(item); itemlabourNorm.ID = whereOperUseId; FilltmpLabourNormRow(itemlabourNorm); WhereOperationUse itemWhereOperUse = FillItemWhereOperationUse(item); itemWhereOperUse.LabourNormID = whereOperUseId; FilltmpWhereOperUseRow(itemWhereOperUse); ListAllLabourNorm.Add(item.NDET); whereOperUseId++; } } using (var newLocalDb = new TrudoyomkostDBContext(Properties.Settings.Default.TrudoyomkostDBConnectionString)) { LinqQueryForTrudoyomkost.FillDictDetNumID(newLocalDb, ref DicDetNumAndId); } DicCheckRepeatTN.Clear(); foreach (var item in Tn158DataTable) { if (DicDetNumAndId.ContainsKey(item.NDET)) { LabourNorm itemlabourNorm = FillItemLabourNorm(item); itemlabourNorm.ID = whereOperUseId; FilltmpLabourNormRow(itemlabourNorm); WhereOperationUse itemWhereOperUse = FillItemWhereOperationUse(item); itemWhereOperUse.LabourNormID = whereOperUseId; FilltmpWhereOperUseRow(itemWhereOperUse); ListAllLabourNorm.Add(item.NDET); whereOperUseId++; } } Properties.Settings.Default.Save(); SqlCeBulkCopy bulkInsert = new SqlCeBulkCopy(connString); DataTable tmptbLabourNorm = LabourNormDataTable; DataTable tmpWhereOperUse = WhereOperationUseDataTable; if (tmptbLabourNorm.Rows.Count > 0) { bulkInsert.DestinationTableName = "LabourNorm"; bulkInsert.WriteToServer(tmptbLabourNorm); } if (tmpWhereOperUse.Rows.Count > 0) { bulkInsert.DestinationTableName = "whereOperationUse"; bulkInsert.WriteToServer(tmpWhereOperUse); } LabourNormDataTable.Clear(); WhereOperationUseDataTable.Clear(); bulkInsert.Close(); }
public static void InsertFromANTables(DataSet tableList) { using (var currentContext = new TrudoyomkostDBContext(Properties.Settings.Default.TrudoyomkostDBConnectionString)) { LinqQueryForTrudoyomkost.FilldcInfProducts(currentContext, ref DcInfProducts); LinqQueryForTrudoyomkost.FillDictDetNumID(currentContext, ref DicDetNumAndId); LinqQueryForTrudoyomkost.FillDictDepIDCode(currentContext, ref DicDepCodeAndId); Properties.Settings.Default.DetID = currentContext.InfDet.ToList().Count == 0 ? 0 : ++currentContext.InfDet.ToList().Last().ID; } if (int.Parse((tableList.Tables[0].Rows[0].Field<string>("CEH").Trim())) != Properties.Settings.Default.DepNum) return; _whereUseTableAdapter.DeleteAllQuery(); foreach (DataTable itemTable in tableList.Tables) { foreach (DataRow itemRow in itemTable.Rows) { string NDET = (string)itemRow["NDET"]; if (!DicDetNumAndId.ContainsKey(NDET)) { var infDetItem = FillItemInfDet(itemRow); FilltmpInfDetRow(ref infDetItem); DicDetNumAndId.Add(NDET, Properties.Settings.Default.DetID); Properties.Settings.Default.DetID++; } var itemWhereuse = FillItemWhereUse(itemRow); FilltmpWhereUseRow(itemWhereuse); } } Properties.Settings.Default.Save(); SqlCeBulkCopy bulkInsert = new SqlCeBulkCopy(connString); DataTable tmptbInfDet = InfDetDataTable; DataTable tmptbWhereUse = WhereUseDataTable; if (tmptbInfDet.Rows.Count > 0) { bulkInsert.DestinationTableName = "infDet"; bulkInsert.WriteToServer(tmptbInfDet); } if (tmptbWhereUse.Rows.Count > 0) { bulkInsert.DestinationTableName = "whereUse"; bulkInsert.WriteToServer(tmptbWhereUse); } WhereUseDataTable.Clear(); InfDetDataTable.Clear(); bulkInsert.Close(); }