//构造函数 public StockOutForm(BathDBDataContext dc, StockOut _stockout) { db = dc; if (_stockout != null) { newStockout = false; stockout = _stockout; } InitializeComponent(); }
//private double totalsum = 0; public EditStockOutForm(BathDBDataContext dc, StockOut stkout) { db = dc; stockout = stkout; InitializeComponent(); stock.Items.AddRange(db.Stock.Select(x => x.name).ToArray()); goodsCat.Items.AddRange(db.GoodsCat.Select(x => x.name).ToArray()); var employees = db.Employee.Where(x => !db.Job.FirstOrDefault(y => y.id == x.jobId).name.Contains("技师")); receiver.Items.AddRange(employees.Select(x => x.name).ToArray()); checker.Items.AddRange(employees.Select(x => x.name).ToArray()); transactor.Items.AddRange(employees.Select(x => x.name).ToArray()); ComboUnit.Items.AddRange(db.Unit.Select(x => x.name).ToArray()); }
//确定 private void okBtn_Click(object sender, EventArgs e) { if (!validateTextFields()) return; stockout.name = name.Text; stockout.amount = MConvert<double>.ToTypeOrDefault(amount.Text, 0); stockout.unit = ComboUnit.Text; stockout.stockId = db.Stock.FirstOrDefault(x => x.name == stock.Text).id; stockout.date = dtPickerIntoStock.Value; stockout.receiver = receiver.Text; stockout.transactor = transactor.Text; stockout.checker = checker.Text; stockout.note = note.Text; if (newStockout) { db.StockOut.InsertOnSubmit(stockout); string unit_txt = ComboUnit.Text.Trim(); if (unit_txt != "") { if (!db.Unit.Any(x => x.name == unit_txt)) { var unit_instance = new Unit(); unit_instance.name = unit_txt; db.Unit.InsertOnSubmit(unit_instance); } } db.SubmitChanges(); stockout = new StockOut(); goodsCat.SelectedIndex = -1; stock.SelectedIndex = -1; name.Text =""; amount.Text = ""; ComboUnit.Text = ""; receiver.Text = LogIn.m_User.name; transactor.Text = LogIn.m_User.name; checker.Text = LogIn.m_User.name; note.Text = ""; } else { db.SubmitChanges(); this.DialogResult = DialogResult.OK; this.Close(); } }
partial void DeleteStockOut(StockOut instance);
partial void UpdateStockOut(StockOut instance);
partial void InsertStockOut(StockOut instance);
//确定 private void okBtn_Click(object sender, EventArgs e) { if (!validateTextFields()) return; StockOut outStock = new StockOut(); outStock.name = name.Text; outStock.amount = Convert.ToInt32(amount.Text); outStock.stockId = db.Stock.FirstOrDefault(x => x.name == stock.Text).id; if (toStock.Text != "") outStock.toStockId = db.Stock.FirstOrDefault(x => x.name == toStock.Text).id; outStock.note = note.Text; outStock.date = BathClass.Now(LogIn.connectionString); outStock.receiver = receiver.Text; outStock.transactor = transactor.Text; outStock.checker = checker.Text; db.StockOut.InsertOnSubmit(outStock); //bool newSList = false; //var storage = db.StorageList.FirstOrDefault(x => x.name == name.Text && x.stockId == outStock.stockId); //var toStorage = db.StorageList.FirstOrDefault(x => x.name == name.Text && x.stockId == outStock.toStockId); //if (storage == null) //{ // newSList = true; // storage = new StorageList(); //} //bool newToSList = false; //if (toStorage == null) //{ // newToSList = true; // toStorage = new StorageList(); //} //storage.name = name.Text; //storage.amountThisMonth = MConvert<int>.ToTypeOrDefault(storage.amountThisMonth) - outStock.amount; //storage.stockId = outStock.stockId; //if (newSList) // db.StorageList.InsertOnSubmit(storage); //toStorage.name = name.Text; //toStorage.amountThisMonth = MConvert<int>.ToTypeOrDefault(toStorage.amountThisMonth) + outStock.amount; //toStorage.stockId = outStock.toStockId; //if (newToSList) // db.StorageList.InsertOnSubmit(toStorage); db.SubmitChanges(); this.DialogResult = DialogResult.OK; this.Close(); }