/// <summary> /// به روز شدن یک فاکتور /// </summary> private void UpdateFactor() { //try //{ if (ChekVAX.Checked == true) { _Factor.VAXPrice = utility.ConvertCommaPrice(txtVAX.Text); } else { _Factor.VAXPrice = 0; } if (txtDescription.Text != "") { _Factor.Description = txtDescription.Text; } else { _Factor.Description = "ندارد"; } _Factor.FactorNumber = txtFactorNumber.Text.ToString().Trim(); DateTime DD = Convert.ToDateTime(Datepicker.GeoDate); DateTime D = new DateTime(DD.Year, DD.Month, DD.Day, DateTime.Now.Hour, DateTime.Now.Minute, 0); _Factor.Date = D; _Factor.TotalPrice = utility.ConvertCommaPrice(txtTotalCost.Text); int projeID = Convert.ToInt32(ComboProject.SelectedValue); _Factor.Project = db.Projects.First(p => p.ProjectID == projeID); //int SellerID = Convert.ToInt32(ComboSeller.SelectedValue); //_Factor.Seller = db.Sellers.First(p => p.SellerID == SellerID); _Factor.VAX = _VAX; //if (state == 1) //{ // if (_Factor.ProjectID != projeID) // { // //_Factor.Checks = SpecialUtility.ChangeProjectChecks(_Factor.Checks, projeID, ComboSeller.Text); // } //} var items = (from V in db.Factor_Items where V.FactorID == _Factor.FactorID select V).ToList<Factor_Item>(); _Factor.Factor_Items.Clear(); db.Factor_Items.RemoveRange(items); for (int i = 0; i < GridFactorReg.Rows.Count - 1; i++) { Factor_Item F = new Factor_Item() { Description = GridFactorReg.Rows[i].Cells[1].Value.ToString(), SoldPrice = utility.ConvertCommaPrice(GridFactorReg.Rows[i].Cells[2].Value.ToString()), Qty = Convert.ToInt32(GridFactorReg.Rows[i].Cells[3].Value.ToString()), FactorID = _Factor.FactorID, Tprice = utility.ConvertCommaPrice(GridFactorReg.Rows[i].Cells[4].Value.ToString()) }; db.Factor_Items.Add(F); } //if (state == 1) //{ // FormCheck FC = new FormCheck(_Factor); // FC.ShowDialog(); // if (!FC.GetStatusFactorState()) // return; // _CheckList = FC.GetRegCheckList(); // if (_CheckList.Count == 0) // { // Utility.ShowNotification("خطا", "شما هیچ چکی برای این هزینه ثبت نکردید ، توجه کنید که در صورتی می توانید این هزینه را ثبت کنید که چک های صادر شده را ثبت کنید", Utility.Icons.Information, 3000); // return; // } // else // { // foreach (var item in _CheckList) // { // db.Checks.First(p => p.CheckID == item.CheckID).FactorID = _Factor.FactorID; // } // } // db.SaveChanges(); //} db.SaveChanges(); utility.Show_Message("فاکتور با موفقیت ویرایش شد", "پیغام عملیات"); //} //catch (DbUpdateException ex) //{ // MessageBox.Show(SqlServerErrorManagment.ShowError(ex, "فاکتور"), "هشدار", MessageBoxButtons.OK, MessageBoxIcon.Error); //} //catch (Exception ex) //{ // MessageBox.Show(ex.Message, "هشدار", MessageBoxButtons.OK, MessageBoxIcon.Error); //} }
/// <summary> /// تابع ثبت اقلام فاکتور /// </summary> /// <returns></returns> private bool RegisterFactorItems() { //try //{ for (int i = 0; i < GridFactorReg.Rows.Count - 1; i++) { Factor_Item F = new Factor_Item() { Description = GridFactorReg.Rows[i].Cells[1].Value.ToString(), SoldPrice = utility.ConvertCommaPrice(GridFactorReg.Rows[i].Cells[2].Value.ToString()), Qty = Convert.ToInt32(GridFactorReg.Rows[i].Cells[3].Value.ToString()), FactorID = _NewID, Tprice = utility.ConvertCommaPrice(GridFactorReg.Rows[i].Cells[4].Value.ToString()) }; db.Factor_Items.Add(F); } db.SaveChanges(); return true; //} //catch (DbUpdateException ex) //{ // MessageBox.Show(SqlServerErrorManagment.ShowError(ex, "اقلام فاکتور"), "هشدار", MessageBoxButtons.OK, MessageBoxIcon.Error); // return false; //} //catch (Exception ex) //{ // MessageBox.Show(ex.Message, "هشدار", MessageBoxButtons.OK, MessageBoxIcon.Error); // return false; //} }