void B_Sell_Click(object sender, System.EventArgs e) { if (!int.TryParse(T_Amount.Text, out int amount) || amount < 1) { MessageBox.Show(this, Resources.INVALID_SKU_QTY_IS_ENTERED, Resources.FAILURE, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } if (amount > _selectedCell.Amount) { MessageBox.Show(this, Resources.QTY_TOO_BIG_FOR_GIVEN_CELL, Resources.FAILURE, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } if (!int.TryParse(T_PriceOfSell.Text, out int unitPrice) || unitPrice < 0) { MessageBox.Show(this, Resources.INVALID_UNIT_PRICE_OF_SELL, Resources.FAILURE, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } DateTime dateOfSale = DateTime.Today; bool dateNotSelected = true; bool paymentByCard = false; while (dateNotSelected) { using (FRM_SelectDateOfSale frmDateSelector = new FRM_SelectDateOfSale(_skuInStock.Article.Name, amount, unitPrice)) { if (frmDateSelector.ShowDialog(this) != DialogResult.OK) { return; } dateOfSale = frmDateSelector.Date; DateTime maxOldDate = DateTime.Today.AddDays(-19); if (maxOldDate.CompareTo(dateOfSale) > 0) { string month = c_months[dateOfSale.Month - 1].ToUpper(); if (MessageBox.Show(this, string.Format(Resources.CONFIRM_SELECTED_DATE, dateOfSale.Day, month), Resources.QUESTION_ABOUT_DATE, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { continue; } } Settings.Default.LastDateOfSale = frmDateSelector.Date; Settings.Default.Save(); dateNotSelected = false; paymentByCard = frmDateSelector.PaymentByCard; } } // TODO: Implement transaction _selectedCell = _skuInStock[_selectedCell.X, _selectedCell.Y]; // This is because of whilst render of the size chart, it's current cell can detach itself from the SKU on the object level (see comment about re-calculating above) _selectedCell.Amount -= amount; _skuInStock.Flush(); DocSale sale = DocSale.CreateNew(dateOfSale, _skuInStock.Article, _skuInStock.PointOfSale, unitPrice, amount, _selectedCell, paymentByCard); sale.Flush(); ((PanelViewSku)Parent.Parent.Parent).UpdateWOldSearch(); }
void RefillTable(DateTime in_dateBegin, DateTime in_dateEnd, DocSale.ShowRows in_paymentTypes) { Cursor oldCur = this.Cursor; try { this.Cursor = Cursors.WaitCursor; DGV_SalesJournal.DataSource = DocSale.ReadSalesJournal(Registry.CurrentPointOfSale, in_dateBegin, in_dateEnd, in_paymentTypes); // Re-order columns manually; I was unable to figure out why they began to be shown disordered after translating UI to English DGV_SalesJournal.Columns["COL_Date"].DisplayIndex = 0; DGV_SalesJournal.Columns["COL_ArticleName"].DisplayIndex = 1; DGV_SalesJournal.Columns["COL_Y"].DisplayIndex = 2; DGV_SalesJournal.Columns["COL_X"].DisplayIndex = 3; DGV_SalesJournal.Columns["COL_Units"].DisplayIndex = 4; DGV_SalesJournal.Columns["COL_PriceOfPurchase"].DisplayIndex = 5; DGV_SalesJournal.Columns["COL_PricePlan"].DisplayIndex = 6; DGV_SalesJournal.Columns["COL_Price"].DisplayIndex = 7; DGV_SalesJournal.Columns["COL_PriceSum"].DisplayIndex = 8; DGV_SalesJournal.Columns["COL_Id"].DisplayIndex = 9; DocSale.Summary summary = DocSale.GetSummary(Registry.CurrentPointOfSale, in_dateBegin, in_dateEnd, in_paymentTypes); L_Summary.Text = string.Format(Resources.SALES_SUMMARY_LABEL, summary.Count, summary.Sum, summary.Profit); B_VoidSale.Enabled = DGV_SalesJournal.Rows.Count != 0; } finally { this.Cursor = oldCur; } }
void B_ChangeDate_Click(object sender, EventArgs e) { if (DGV_SalesJournal.Rows.GetRowCount(DataGridViewElementStates.Selected) <= 0) { MessageBox.Show(this, Resources.NO_ROW_SELECTED, Resources.FAILURE, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } DataGridViewRow row = DGV_SalesJournal.SelectedRows[0]; DateTime oldDate = DateTime.Parse((string)row.Cells["COL_Date"].Value); DateTime newDate; using (FRM_SelectDateOfSale frmSelectDate = new FRM_SelectDateOfSale("-", -1, -1)) { if (frmSelectDate.ShowDialog(this) != System.Windows.Forms.DialogResult.OK) { return; } newDate = frmSelectDate.Date; } if (newDate == oldDate) { MessageBox.Show(this, Resources.NEW_DATE_IS_SAME_AS_OLD_ONE_SO_CHANGE_NOTHING, Resources.CANCELATION, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { DocSale sale = DocSale.Restore((int)(long)row.Cells["COL_Id"].Value); sale.TimeSold = newDate; sale.Flush(); } }
void B_VoidSale_Click(object sender, EventArgs e) { if (DGV_SalesJournal.Rows.GetRowCount(DataGridViewElementStates.Selected) <= 0) { MessageBox.Show(this, Resources.NO_ROW_SELECTED, Resources.FAILURE, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } DataGridViewRow row = DGV_SalesJournal.SelectedRows[0]; int id = (int)(long)row.Cells["COL_Id"].Value; string name = (string)row.Cells["COL_ArticleName"].Value; int sum = (int)(long)row.Cells["COL_PriceSum"].Value; if (MessageBox.Show(this, string.Format(Resources.ASK_CANCEL_SALE, name, sum), Resources.CONFIRMATION, MessageBoxButtons.YesNo, MessageBoxIcon.Question) != System.Windows.Forms.DialogResult.Yes) { return; } // TODO: Implement transaction DocSale sale = DocSale.Restore(id); sale.Doc.TimeCancelled = DateTime.Now; SkuInStock skuInStock = SkuInStock.Restore(Article.Restore(sale.ArticleId), PointOfSale.Restore(sale.PointOfSaleId)); CellInStock cell = CellInStock.Restore(sale.CellX, sale.CellY, skuInStock); if (cell == null) { cell = CellInStock.Restore(0, DateTime.Now, skuInStock, sale.CellX, sale.CellY, sale.UnitCount, true); } else { cell.Amount += sale.UnitCount; } sale.Doc.Flush(); cell.Flush(); RefillTable(); }
public void Create(string token, DocSale docSale) { throw new NotImplementedException(); }
public void impDocSales() { DateTime now = DateTime.Now; HashSet <System.Data.Linq.Binary> fndDocs = new HashSet <System.Data.Linq.Binary>(); HashSet <Tuple <System.Data.Linq.Binary, // IDRRef, Version System.Data.Linq.Binary> > fndDocVer = new HashSet <Tuple <System.Data.Linq.Binary, System.Data.Linq.Binary> >(); // Fill documents var docs = from d in dataContext.DocSales select d; foreach (DocSale doc in docs) { fndDocs.Add(doc.IDRRef); } foreach (DocSale doc in docs) { fndDocVer.Add(Tuple.Create(doc.IDRRef, doc.Version)); } // Fill documents // Warehouses var fWarehouses = from g in dataContext.DimWarehouses select g; foreach (DimWarehouses wh in fWarehouses) { fndWarehouses.Add(wh.IDRRef, wh.ID); } // Warehouses // Currencies var fCurrencies = from g in dataContext.DimCurrencies select g; foreach (DimCurrencies gd in fCurrencies) { fndCurrencies.Add(gd.IDRRef, gd.ID); } CurrRates = (from c in dataContext.FactCurrencyRates select c).ToArray(); // Currencies // Partners var fPartner = from p in dataContext.DimPartners select p; foreach (DimPartner dp in fPartner) { fndPartner.Add(dp.IDRRef, dp.ID); } // Partners // DateKey var fDateKey = from g in dataContext.DimDates select g; foreach (DimDates gd in fDateKey) { fndDateKey.Add(gd.Date, gd.DateKey); } // DateKey // for lines // Goods var fGoods = from g in dataContext.DimGoods select g; foreach (DimGoods gd in fGoods) { fndGoods.Add(gd.IDRRef, gd.ID); } // Goods // ed izm var edIzms = from e in dataContext.DimGoods select e; foreach (DimGoods ed in edIzms) { edIzmerId.Add(ed.ID, ed.BaseUnitID); } // ed izm // Marked deleted byte[] posted = new byte[1]; posted[0] = 1; // Marked deleted var salesDocs = from c in dataContextS1._Document822s where c._Posted == posted select c; int i = 0; foreach (_Document822 doc in salesDocs) { if (fndDocVer.Contains(Tuple.Create(doc._IDRRef, doc._Version)) == true) { i++; continue; } if (fndDocs.Contains(doc._IDRRef) == true) { // UPD var dp = (from n in dataContext.DocSales where n.IDRRef == doc._IDRRef select n).FirstOrDefault(); dp.NumberPrefix = doc._NumberPrefix; dp.DocNumber = doc._Number; // Warehouses if (fndWarehouses.ContainsKey(doc._Fld29564RRef)) { Int64 val; fndWarehouses.TryGetValue(doc._Fld29564RRef, out val); dp.WarehouseID = val; } //else // throw new Exception(); dp.DocDate = doc._Date_Time.AddYears(-2000); // DateKey if (fndDateKey.ContainsKey(dp.DocDate.Value.Date)) { int val; fndDateKey.TryGetValue(dp.DocDate.Value.Date, out val); dp.DateKey = val; } else { throw new Exception(); } dp.Posted = doc._Posted; // Partners if (fndPartner.ContainsKey(doc._Fld29560RRef)) { Int64 val; fndPartner.TryGetValue(doc._Fld29560RRef, out val); dp.PartnerID = val; } else { throw new Exception(); } // Currencies if (fndCurrencies.ContainsKey(doc._Fld29544RRef)) { Int64 val; fndCurrencies.TryGetValue(doc._Fld29544RRef, out val); dp.CurrencyID = val; } else { throw new Exception(); } if (dp.CurrencyID == currIDRubl) { dp.DocAmount = doc._Fld29559; } else { var rate = (from r in CurrRates where r.CurrencyID == dp.CurrencyID && r.Date >= dp.DocDate select r).FirstOrDefault(); dp.DocAmount = doc._Fld29559 * rate.Rate.Value / rate.Fold.Value; } dp.Version = doc._Version; if (doc._Posted == posted) { dp.Active = true; } else { dp.Active = false; } dataContext.SubmitChanges(); // update lines var lines = from l in dataContext.DocSalesLines where l.Document822_IDRRef == doc._IDRRef select l; dataContext.DocSalesLines.DeleteAllOnSubmit(lines); dataContext.SubmitChanges(); impDocSalesLines(doc._IDRRef, dp.CurrencyID.Value, dp.DocDate.Value); // import lines } else { // NEW DocSale dp = new DocSale(); dp.NumberPrefix = doc._NumberPrefix; dp.DocNumber = doc._Number; // Warehouses if (fndWarehouses.ContainsKey(doc._Fld29564RRef)) { Int64 val; fndWarehouses.TryGetValue(doc._Fld29564RRef, out val); dp.WarehouseID = val; } //else //throw new Exception(); dp.DocDate = doc._Date_Time.AddYears(-2000); // DateKey if (fndDateKey.ContainsKey(dp.DocDate.Value.Date)) { int val; fndDateKey.TryGetValue(dp.DocDate.Value.Date, out val); dp.DateKey = val; } else { throw new Exception(); } dp.Posted = doc._Posted; // Partners if (fndPartner.ContainsKey(doc._Fld29560RRef)) { Int64 val; fndPartner.TryGetValue(doc._Fld29560RRef, out val); dp.PartnerID = val; } else { throw new Exception(); } // Currencies if (fndCurrencies.ContainsKey(doc._Fld29544RRef)) { Int64 val; fndCurrencies.TryGetValue(doc._Fld29544RRef, out val); dp.CurrencyID = val; } else { throw new Exception(); } if (dp.CurrencyID == currIDRubl) { dp.DocAmount = doc._Fld29559; } else { var rate = (from r in CurrRates where r.CurrencyID == dp.CurrencyID && r.Date <= dp.DocDate orderby r.Date descending select r).FirstOrDefault(); dp.DocAmount = doc._Fld29559 * rate.Rate.Value / rate.Fold.Value; } dp.IDRRef = doc._IDRRef; dp.Version = doc._Version; if (doc._Posted == posted) { dp.Active = true; } else { dp.Active = false; } dataContext.DocSales.InsertOnSubmit(dp); dataContext.SubmitChanges(); impDocSalesLines(doc._IDRRef, dp.CurrencyID.Value, dp.DocDate.Value); // import lines } // if (fndDocs.Contains(doc._IDRRef) == true) if (i % 100 == 0) { dataContext.SubmitChanges(); } i++; } // foreach (_Document581 doc in prodDocs) dataContext.SubmitChanges(); }