private void txt_gnt_deal_article_sell_jeribMinuteSecond_LostFocus(object sender, RoutedEventArgs e) { var dataBase = DDB.NewContext(); if (selectedArticle.gnt_deal_article_gnt_water_id == 0) { return; } var ownership = new tbl_gnt_ownership(); ownership.tbl_gnt_water = dataBase.tbl_gnt_water.Where(w => w.gnt_water_id == selectedArticle.gnt_deal_article_gnt_water_id).First(); ownership.gnt_ownership_jerib = selectedArticle.gnt_deal_article_sell_jerib; ownership.gnt_ownership_minute = selectedArticle.gnt_deal_article_sell_minute; ownership.gnt_ownership_second = selectedArticle.gnt_deal_article_sell_second; selectedArticle.gnt_deal_article_sell_jerib = ownership.gnt_ownership_correct_jerib; selectedArticle.gnt_deal_article_sell_minute = ownership.gnt_ownership_correct_minute; selectedArticle.gnt_deal_article_sell_second = ownership.gnt_ownership_correct_second; selectedArticle.gnt_deal_article_sell_credit = ownership.gnt_ownership_correct_credit; selectedArticle.gnt_deal_article_sell_earth = ownership.gnt_ownership_correct_earth; selectedArticle.gnt_deal_article_sell_all_price = (int)Math.Round(selectedArticle.gnt_deal_article_sell_credit * selectedArticle.gnt_deal_article_sell_price); selectedArticle.gnt_deal_article_sell_agreement_price = selectedArticle.gnt_deal_article_sell_all_price; MoveCollectionViewArticle(); }
private void txt_gnt_ownership_jeribMinuteSecond_LostFocus(object sender, RoutedEventArgs e) { var ownership = new tbl_gnt_ownership(); ownership.InitialFromRecord(selectedRecord); selectedRecord.gnt_ownership_jerib = ownership.gnt_ownership_correct_jerib; selectedRecord.gnt_ownership_minute = ownership.gnt_ownership_correct_minute; selectedRecord.gnt_ownership_second = ownership.gnt_ownership_correct_second; selectedRecord.gnt_ownership_earth = ownership.gnt_ownership_correct_earth; selectedRecord.gnt_ownership_credit = ownership.gnt_ownership_correct_credit; MoveCollectionView(); }
private void SaveDealToOwnerships() { try { var dataBase = DDB.NewContext(); var deal = dataBase.tbl_gnt_deal.Where(d => d.gnt_deal_id == selectedRecord.gnt_deal_id).First(); foreach (var article in deal.tbl_gnt_deal_article) { var ownership = tbl_gnt_ownership.FindRecord(dataBase, article.gnt_deal_article_gnt_ownership_id); if (ownership == null) { Messages.ErrorMessage("مالکیت سهامدار یافت نشد"); return; } if (ownership.TotalSeconds > article.TotlaSeconds) { ownership.TotalSeconds -= article.TotlaSeconds; /* Decrease old Ownership */ dataBase.tbl_gnt_ownership.ApplyCurrentValues(ownership); } else if (ownership.TotalSeconds == article.TotlaSeconds) { dataBase.tbl_gnt_ownership.DeleteObject(ownership); } else { string message = "سهام انتقال یافته بیش از سهام مالک است" + "\n" + "نام مالک :" + ownership.tbl_gnt_creditor.gnt_creditor_family + "\n" + "نام آب :" + ownership.tbl_gnt_water.gnt_water_name; Messages.ErrorMessage(message); return; } tbl_gnt_ownership newOwnership = new tbl_gnt_ownership(); /* Create New Ownership with amount of selling*/ newOwnership.gnt_ownership_gnt_water_id = ownership.gnt_ownership_gnt_water_id; newOwnership.gnt_ownership_gnt_creditor_id = article.gnt_deal_article_gnt_buy_creditor_id; newOwnership.TotalSeconds = article.TotlaSeconds; newOwnership.gnt_ownership_glb_branch_id = GlobalVariables.current_branch_id; dataBase.tbl_gnt_ownership.AddObject(newOwnership); } dataBase.SaveChanges(); } catch (Exception exception) { string message = "خطا در ذخیره سازی تغییرات" + "\n" + exception.Message; if (exception.InnerException != null) { message += "\n" + "خطای پایگاه داده " + "\n" + exception.InnerException.Message; } Messages.ErrorMessage(message); } }