private void SaveInfo(bool ed) { using (ClubDBEntities club = new ClubDBEntities()) { DateTime date = Convert.ToDateTime(tbDate.Text); if (ed) { var re = club.CashMovs.Where(a => a.Date == date).First(); re.Balance = Convert.ToDecimal(tbCTotal.Text); re.Bank = Convert.ToDecimal(tbCBank.Text); re.BuffetIncome = 0; re.Expenses = Convert.ToDecimal(tbCExpenses.Text); re.InvIncome = Convert.ToDecimal(tbCIncome.Text); re.MigBalance = Convert.ToDecimal(tbCMigBalance.Text); re.PreBalance = Convert.ToDecimal(tbCPreBalance.Text); if (re.Bank > 0) { BankTran b = new BankTran(); b.Amount = re.Bank; b.Note = "إيداع نقدي"; b.Date = Convert.ToDateTime(tbBankDate.Text); club.BankTrans.AddObject(b); re.BankID = b.ID; } else if (re.Bank == 0) { var b = club.BankTrans.Where(a => a.ID == re.BankID).FirstOrDefault(); if (b != null) { club.BankTrans.DeleteObject(b); } } } else { // buffet //BuffetMov buff = new BuffetMov(); //buff.Date = date; //buff.Balance = Convert.ToDecimal(tbTIncome.Text); //buff.PreBalance = Convert.ToDecimal(tbPreBalance.Text); //buff.MigBalance = Convert.ToDecimal(tbMigBalance.Text); //buff.Purchase = Convert.ToDecimal(tbIncome.Text); //buff.Sales = Convert.ToDecimal(tbSales.Text); //club.BuffetMovs.AddObject(buff); // ohda //ExpensesMov ex = new ExpensesMov(); //ex.Date = date; //ex.Balance = 0; //ex.Expenses = 0; //ex.MigBalance = 0; //ex.PlusBalance = 0; //ex.PreBalance = 0; //club.ExpensesMovs.AddObject(ex); // cash CashMov cash = new CashMov(); cash.Date = date; cash.Balance = Convert.ToDecimal(tbCTotal.Text); cash.Bank = Convert.ToDecimal(tbCBank.Text); cash.BuffetIncome = 0; cash.Expenses = Convert.ToDecimal(tbCExpenses.Text); cash.InvIncome = Convert.ToDecimal(tbCIncome.Text); cash.MigBalance = Convert.ToDecimal(tbCMigBalance.Text); cash.PreBalance = Convert.ToDecimal(tbCPreBalance.Text); club.CashMovs.AddObject(cash); // bank if (cash.Bank > 0) { BankTran b = new BankTran(); b.Amount = cash.Bank; b.Note = "إيداع نقدي"; b.Date = Convert.ToDateTime(tbBankDate.Text); club.BankTrans.AddObject(b); cash.BankID = b.ID; } } try { club.SaveChanges(); saved = true; Date = date; lblError.Visible = false; string Message = " تم حفظ المعلومات "; ScriptManager.RegisterStartupScript(Page, this.GetType(), "alert", string.Format("alert('{0}');", Message), true); } catch { lblError.Text = "خطأ في التاريخ. الرجاء التأكد من المعلومات"; lblError.Visible = true; } } }
protected void btnSave_Click(object sender, EventArgs e) { string toPerson = tbTo.Text; decimal amount = Convert.ToDecimal(tbAmount.Text); string amountW = tbAmountW.Text; string note = tbNotes.Text; int? type = null; bool bank = false; if (ddlDep.SelectedIndex == 0) { lblError.Text = "لم يتم اختيار نوع الفاتورة"; lblError.Visible = true; } else { type = Convert.ToInt32(lbType.SelectedValue); using (ClubDBEntities club = new ClubDBEntities()) { string username = User.Identity.Name; var emp = (from o in club.Employees where o.UserName == username select o.EmpID).First(); Withdraw with = new Withdraw(); with.Amount = amount; with.AmountW = amountW; with.WithType = type; with.Date = Convert.ToDateTime(tbDate1.Text);//Change this with.EmpID = emp; with.Notes = note; with.ToPerson = toPerson; club.Withdraws.AddObject(with); club.SaveChanges(); if (rbType.SelectedIndex == 1) { DateTime date = Convert.ToDateTime(tbDate.Text); BankTran bb = new BankTran(); bb.Date = date; bb.Amount = amount * -1; bb.Note = toPerson; with.Date = Convert.ToDateTime(tbDate.Text); with.CheckNum = string.IsNullOrEmpty(tbCheck.Text)? 0:Convert.ToInt64(tbCheck.Text); with.BankName = tbBank.Text; club.BankTrans.AddObject(bb); with.BankID = bb.ID; club.SaveChanges(); } withID = with.ID; string Message = " تم حفظ المعلومات "; ScriptManager.RegisterStartupScript(Page, this.GetType(), "alert", string.Format("alert('{0}');", Message), true); // print the bill //var result = club.getWithReport(with.ID); //WithdrawCR report = new WithdrawCR(); //report.Load(Server.MapPath("WithdrawCR.rpt")); //report.SetDataSource(result); //string printer = ""; //report.PrintOptions.PrinterName = ClubWebApp.Properties.Settings.Default.InvoicePrinter; //report.PrintOptions.PrinterName = printer; //report.PrintToPrinter(1, false, 0, 0); } } }