private void addToDateSumOtgruz(int q, string num, string good) { double priceBuy = (from g in datacontext.GetTable <Goods>() where g.Name == "" select g.PriceBuy).First(); double summ = priceBuy * q; var otgruzka = new DateSum { contract = num, Data = DateTime.Now.Date, good = good, quant = q, Summa = summ }; datacontext.GetTable <DateSum>().InsertOnSubmit(otgruzka); datacontext.SubmitChanges(); }
public boolInt addQuantityLeftInGoods(int q, int GinC, string login) { var goodIn = (from g in datacontext.GetTable <GoodsInContract>() where g.id == GinC select g).First(); if (q > goodIn.QuantityLeft || (goodIn.Quantity < (goodIn.QuantityLeft - q))) { return new boolInt { b = false, q = goodIn.QuantityLeft } } ; goodIn.QuantityLeft = goodIn.QuantityLeft - q; int quant = goodIn.QuantityLeft; var classTmp = (from g in datacontext.GetTable <Goods>() from gin in datacontext.GetTable <GoodsInContract>() where g.ID == goodIn.IdGood && gin.id == GinC && gin.IdGood == g.ID select new { priceBuy = g.PriceBuy, Good = g.Name, pricsSold = gin.PriceSold }).First(); double summ = classTmp.priceBuy * q; double summ2 = classTmp.pricsSold * q; var otgruzka = new DateSum { contract = (from c in datacontext.GetTable <Contracts>() where c.id == goodIn.idContract select c.Number).First(), Data = DateTime.Now.Date, good = classTmp.Good, quant = q, Summa = summ, summSold = summ2, whoIs = login }; datacontext.GetTable <DateSum>().InsertOnSubmit(otgruzka); // datacontext.SubmitChanges(); try { datacontext.SubmitChanges(); } catch (ChangeConflictException) { { try { goodIn = (from g in datacontext.GetTable <GoodsInContract>() where g.id == GinC select g).First(); if (q > goodIn.QuantityLeft || (goodIn.Quantity < (goodIn.QuantityLeft - q))) { return new boolInt { b = false, q = goodIn.QuantityLeft } } ; goodIn.QuantityLeft = goodIn.QuantityLeft - q; datacontext.SubmitChanges(); } catch (ChangeConflictException) { Console.WriteLine("Конфликт повторился, откатываемся."); } } } //try //{ // datacontext.SubmitChanges(); //} //catch (ChangeConflictException) //{ // datacontext.ChangeConflicts.ResolveAll(RefreshMode.KeepChanges); // { // try // { // datacontext.SubmitChanges(); // } // catch (ChangeConflictException) // { // Console.WriteLine("Конфликт повторился, откатываемся."); // } // } //} return(new boolInt { q = quant, b = true }); }