public ChequeAddForm(Cheque chq) : this() { this.edit = true; this.editID = chq.ID; this.cmbAccountants.SelectedValue = chq.Invoice.TarafID; this.chkPaidInvoices.Checked = true; this.txtInvoiceID.Text = chq.InvoiceID.ToString(); this.lstInvoiceForCheque.FindItemWithText(chq.InvoiceID.ToString(), true, 0, true).Selected = true; this.cmbBankNameAccount.SelectedValue = chq.AccountID; this.txtChequeNumber.Text = chq.CheckNum.ToString(); this.txtChequePrice.Text = chq.Price.ToString(); this.abrChequeDate.SelectedDate = (Utilities.getMiladiFromPersian(chq.Date)); }
public static void SaveDocument(Cheque chq) { var DB = new StoreDBEntities(); long accountid = 0; try { accountid = DB.Accounts.First(x => x.DistributorID == chq.Invoice.TarafID).Id; } catch (InvalidOperationException) { Account newAcc = new Account { Name = chq.Invoice.Distributor.Name, Description = " ", CustomerID = 0, DistributorID = chq.Invoice.TarafID, BankAccountID = 0 }; DB.Accounts.AddObject(newAcc); DB.SaveChanges(); accountid = DB.Accounts.OrderByDescending(x => x.Id).First().Id; } Document newDoc = new Document { AccountID = accountid, Description = "چک شماره" + chq.CheckNum + " بابت فاکتور خ شماره " + chq.InvoiceID, Value = chq.Price, Date = chq.Invoice.Date, SetDate = Utilities.getCurrentPersianDate(), Debt_Credit = true, ChequeID = chq.ID }; DB.Documents.AddObject(newDoc); DB.SaveChanges(); //-------------------------- long bankID = 0; try { bankID = DB.Accounts.First(x => x.BankAccountID == chq.BankAccount.ID).Id; } catch (InvalidOperationException) { Account newAcc = new Account { Name = "بانک " + chq.BankAccount.BankName, Description = " ", CustomerID = 0, DistributorID = 0, BankAccountID = chq.BankAccount.ID }; DB.Accounts.AddObject(newAcc); DB.SaveChanges(); bankID = DB.Accounts.OrderByDescending(x => x.Id).First().Id; } Document newBankDoc = new Document { AccountID = bankID, Description = "چک شماره" + chq.CheckNum + " در وجه " + chq.Invoice.Distributor.Name, Value = chq.Price, Date = chq.Date, SetDate = Utilities.getCurrentPersianDate(), Debt_Credit = false, ChequeID = chq.ID }; DB.Documents.AddObject(newBankDoc); DB.SaveChanges(); }
/// <summary> /// Create a new Cheque object. /// </summary> /// <param name="id">Initial value of the ID property.</param> /// <param name="accountID">Initial value of the AccountID property.</param> /// <param name="checkNum">Initial value of the CheckNum property.</param> /// <param name="invoiceID">Initial value of the InvoiceID property.</param> /// <param name="date">Initial value of the Date property.</param> /// <param name="price">Initial value of the Price property.</param> /// <param name="paid">Initial value of the Paid property.</param> public static Cheque CreateCheque(global::System.Int64 id, global::System.Int64 accountID, global::System.Int32 checkNum, global::System.Int64 invoiceID, global::System.String date, global::System.Int32 price, global::System.Boolean paid) { Cheque cheque = new Cheque(); cheque.ID = id; cheque.AccountID = accountID; cheque.CheckNum = checkNum; cheque.InvoiceID = invoiceID; cheque.Date = date; cheque.Price = price; cheque.Paid = paid; return cheque; }
private void btnSaveChequeData_Click(object sender, System.EventArgs e) { if (this.txtInvoiceID.Text == "") { this.errorProvider.SetError(this.txtInvoiceID, " شماره فاکتور وارد نشده است"); return; } if (this.txtChequeNumber.Text == "") { this.errorProvider.SetError(this.txtChequeNumber, "شماره چک وارد نشده است"); return; } if (this.txtChequePrice.Text == "") { this.errorProvider.SetError(this.txtChequePrice, "مبلغ چک وارد نشده است"); return; } if (this.cmbBankNameAccount.SelectedValue == null) { this.errorProvider.SetError(this.cmbBankNameAccount, "حساب بانکی انتخاب نشده است"); return; } long cheqID = 0L; if (this.edit) { Cheque cheque = this.DB.Cheques.First((Cheque x) => x.ID == this.editID); cheqID = editID; cheque.Date = this.abrChequeDate.SelectedDateString; cheque.AccountID = (long)this.cmbBankNameAccount.SelectedValue; cheque.Price = int.Parse(this.txtChequePrice.Text); cheque.CheckNum = int.Parse(this.txtChequeNumber.Text); DB.Cheques.ApplyCurrentValues(cheque); this.DB.SaveChanges(); this.edit = false; } else { long accid = long.Parse(this.cmbBankNameAccount.SelectedValue.ToString()); int num = int.Parse(this.txtChequeNumber.Text); long invid = long.Parse(this.txtInvoiceID.Text); string dte = this.abrChequeDate.SelectedDateString; int prc = int.Parse(this.txtChequePrice.Text); bool pd = false; Cheque chq = new Cheque() { AccountID = accid, CheckNum = num, InvoiceID = invid, Price = prc, Date = dte, Paid = pd }; DB.Cheques.AddObject(chq); DB.SaveChanges(); cheqID = DB.Cheques.OrderByDescending(x => x.ID).First().ID; } //////////////////////////////////////////////////////////////// SaveDocument(DB.Cheques.First(x=>x.ID == cheqID)); ///////////////////////////////////////////////////////////////////////////// FarsiMessage.Show("چک با موفقیت ثبت شد", "تمام"); if (this.lstInvoiceForCheque.SelectedItems.Count == 0) { this.lstInvoiceForCheque.SelectedIndices.Add(this.lstInvoiceForCheque.FindItemWithText(this.txtInvoiceID.Text, true, 0, true).Index); } if (this.lstInvoiceForCheque.SelectedItems[0].SubItems[5].Text == "پ نشده" && FarsiMessage.Show("آیا مایل هستید فاکتور پرداخت شده در نظر گرفته شود؟", "تمام", FarsiMessageBoxButtons.YesNo, FarsiMessageBoxIcons.Question) == DialogResult.Yes) { long id = long.Parse(this.txtInvoiceID.Text); Invoice invoice = this.DB.Invoices.First((Invoice x) => x.InvoiceID == id); invoice.Paid = true; DB.Invoices.ApplyCurrentValues(invoice); this.DB.SaveChanges(); } if (this.edit) { base.Close(); return; } this.InitializeForm(); }
/// <summary> /// Deprecated Method for adding a new object to the Cheques EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToCheques(Cheque cheque) { base.AddObject("Cheques", cheque); }