public override void DeleteRec() { base.DeleteRec(); if (customGridView1.FocusedRowHandle < 0) { return; } try { var _id = Convert.ToInt32(this.customGridView1.GetRowCellValue(customGridView1.FocusedRowHandle, "Id")); if (MessageBoxAdv.Show(KontoGlobals.DeleteBeforeMsg, "Delete ?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } using (var db = new KontoContext()) { var model = db.Products.Find(_id); model.IsDeleted = true; db.SaveChanges(); customGridView1.DeleteRow(customGridView1.FocusedRowHandle); MessageBoxAdv.Show(KontoGlobals.DeleteAfterMsg, "Delete !!", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { Log.Error(ex, "product delete"); MessageBoxAdv.Show(this, "Error While Delete !!", "Exception ", ex.ToString()); } }
public override void DeleteRec() { base.DeleteRec(); if (customGridView1.FocusedRowHandle < 0) { return; } try { var _id = Convert.ToInt32(this.customGridView1.GetRowCellValue(customGridView1.FocusedRowHandle, "Id")); var _vid = Convert.ToInt32(this.customGridView1.GetRowCellValue(customGridView1.FocusedRowHandle, "VoucherId")); var _deleted = Convert.ToBoolean(this.customGridView1.GetRowCellValue(customGridView1.FocusedRowHandle, "IsDeleted")); // var _status = this.customGridView1.GetRowCellValue(customGridView1.FocusedRowHandle, "Status").ToString(); if (_deleted) { MessageBoxAdv.Show("Record Already in Deleted State", "Delete !!", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (MessageBoxAdv.Show(KontoGlobals.DeleteBeforeMsg, "Delete ?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } using (var db = new KontoContext()) { var model = db.Challans.Find(_id); bool result = LedgerEff.DataFreezeStatus(model.VoucherDate, model.TypeId, db); if (result == false) { MessageBox.Show(KontoGlobals.DeleteFreezeWarning); return; } var trans = db.ChallanTranses.Where(x => x.ChallanId == _id).ToList(); foreach (var ct in trans) { var delProdOut = db.ProdOuts.Where(p => p.TransId == ct.Id && p.RefId == model.Id).ToList(); //Challan Trans ct.IsDeleted = true; foreach (var poitem in delProdOut) { ProdModel pitem = db.Prods.Find(poitem.ProdId); if (pitem != null && pitem.RefId != model.Id && pitem.TransId != ct.Id && pitem.VoucherId != model.VoucherId) { pitem.ProdStatus = "STOCK"; } else { pitem.IsDeleted = true; } poitem.IsDeleted = true; } ct.IsDeleted = true; } var stk = db.StockTranses.Where(k => k.MasterRefId == model.RowId).ToList(); if (stk != null) { db.StockTranses.RemoveRange(stk); } model.IsDeleted = true; db.SaveChanges(); customGridView1.DeleteRow(customGridView1.FocusedRowHandle); MessageBoxAdv.Show(KontoGlobals.DeleteAfterMsg, "Delete !!", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { Log.Error(ex, "Store Issue delete"); MessageBoxAdv.Show(this, "Error While Delete !!", "Exception ", ex.ToString()); } }
public override void DeleteRec() { base.DeleteRec(); if (customGridView1.SelectedRowsCount <= 0) { return; } var drs = customGridView1.GetSelectedRows(); if (MessageBoxAdv.Show(KontoGlobals.DeleteBeforeMsg, "Delete ?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } using (var db = new KontoContext()) { using (var _tran = db.Database.BeginTransaction()) { try { foreach (var rowno in drs) { var row = customGridView1.GetDataRow(rowno); var _id = Convert.ToInt32(row["Id"]); var _vid = Convert.ToInt32(row["VoucherId"]); var _deleted = Convert.ToBoolean(row["IsDeleted"]); if (_deleted) { MessageBoxAdv.Show("Record Already in Deleted State", "Delete !!", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } var model = db.Boms.Find(_id); model.IsDeleted = true; var trans = db.BOMTranses.Where(x => x.BOMId == _id).ToList(); foreach (var item in trans) { item.IsDeleted = true; } } customGridView1.DeleteSelectedRows(); db.SaveChanges(); _tran.Commit(); MessageBoxAdv.Show(KontoGlobals.DeleteAfterMsg, "Delete !!", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { _tran.Rollback(); Log.Error(ex, "Sale Invoice delete"); MessageBoxAdv.Show(this, "Error While Delete !!", "Exception ", ex.ToString()); } } } }
private void BarcodeSimpleButton_Click(object sender, EventArgs e) { try { if (this.PrimaryKey == 0) { MessageBox.Show("Can Not Create Barcode BOM Not saved Yet !"); return; } if (bomOrderDtos.Where(x => x.Balance > 0).Any(x => x.EmpId == 0)) { MessageBox.Show("Cutting Employee Not Selected.. Plz Select.."); return; } using (var db = new KontoContext()) { if (!db.Barcodes.Any(x => x.RefId == this.PrimaryKey)) { var repid = db.Barcodes.DefaultIfEmpty().Max(x => x == null ? 0 : x.ReportId) + 1; if (bomOrderDtos.Count > 0) { var bcs = bomOrderDtos.Where(x => x.Balance > 0).ToList(); foreach (var item in bcs) { var bm = new BarcodeModel() { CompId = KontoGlobals.CompanyId, EmpId = item.EmpId, IsActive = true, IsDeleted = false, OrderTransId = item.OrderTransId, PcsNo = 1, AccId = item.AccId, Qty = Convert.ToInt32(item.Balance), ProductId = item.ProductId, RefId = this.PrimaryKey, ReportId = repid, IsLayer = true }; bm.BarcodeNo = GetNextBarcodeNo(db); //String.Format("{0:d9}", (DateTime.Now.Ticks / 10) % 1000000000); //KontoUtils.GetUniqueKey(8); db.Barcodes.Add(bm); } } else { var bm = new BarcodeModel() { CompId = KontoGlobals.CompanyId, IsActive = true, IsDeleted = false, PcsNo = 1, Qty = Convert.ToInt32(Convert.ToDecimal(targetQtyButtonEdit.EditValue)), ProductId = Convert.ToInt32(QualityLookup.Properties.SelectedValue), RefId = this.PrimaryKey, ReportId = repid, IsLayer = true }; bm.BarcodeNo = GetNextBarcodeNo(db); //String.Format("{0:d9}", (DateTime.Now.Ticks / 10) % 1000000000); //KontoUtils.GetUniqueKey(8); db.Barcodes.Add(bm); } db.SaveChanges(); if (MessageBox.Show("Barcode Generated.. Print ??", "Print !", MessageBoxButtons.YesNo) == DialogResult.Yes) { PrintBarcode(repid); } } else { var bc = db.Barcodes.FirstOrDefault(x => x.RefId == this.PrimaryKey); if (bc == null) { return; } if (MessageBox.Show("Barcode Already Generated.. do You Want to Print..?", "print !", MessageBoxButtons.YesNo) == DialogResult.Yes) { PrintBarcode(bc.ReportId); } } } } catch (Exception ex) { MessageBox.Show(ex.ToString()); Log.Error(ex, "BOM Barcode Print"); } }
private void SaveDataAsync(bool newmode) { int ID; var bm = new BomModel(); List <BOMTransModel> btmlist = new List <BOMTransModel>(); bool IsSaved = false; if (!ValidateData()) { return; } BomModel bom = new BomModel(); using (var db = new KontoContext()) { using (var _tran = db.Database.BeginTransaction()) { try { if (this.PrimaryKey != 0) { bm = db.Boms.Find(this.PrimaryKey); } bm.VoucherDate = Convert.ToInt32(voucherDateEdit.DateTime.ToString("yyyyMMdd")); bm.IsActive = true; bm.DivisionId = divLookUpEdit.EditValue != null?Convert.ToInt32(divLookUpEdit.EditValue) : 0; bm.ProductId = QualityLookup.Properties.SelectedValue != null?Convert.ToInt32(QualityLookup.Properties.SelectedValue) : 0; bm.VoucherId = voucherLookup1.SelectedValue != null?Convert.ToInt32(voucherLookup1.SelectedValue) : 0; bm.VoucherNo = voucherNoTextEdit.Text != null?Convert.ToString(voucherNoTextEdit.Text) : ""; bm.Remark = remarkTextEdit.Text != string.Empty ? remarkTextEdit.Text : ""; bm.IsDeleted = false; bm.IsActive = true; bm.Description = Convert.ToString(ordertypeLookUpEdit1.EditValue); bm.TargetQty = Convert.ToDecimal(targetQtyButtonEdit.EditValue); if (bm.Id == 0) { bm.CompId = KontoGlobals.CompanyId; bm.YearId = KontoGlobals.YearId; bm.BranchId = KontoGlobals.BranchId; db.Boms.Add(bm); db.SaveChanges(); } var _bomtarns = new List <BOMTransModel>(); foreach (var item in PFormula) { var btm = new BOMTransModel(); if (item.Id > 0) { btm = db.BOMTranses.Find(item.Id); } btm.BOMId = bm.Id; btm.UomId = item.UomId; btm.ProductId = item.ProductId; btm.ColorId = item.ColorId; btm.BaseQty = item.BaseQty; btm.RequireQty = item.RequireQty; btm.Stock = item.Stock; btm.Remark1 = item.Remark1; btm.Rate = item.Rate; btm.ShortQty = item.ShortQty; btm.Amount = item.Amount; btm.TransType = 1; btm.IsDeleted = false; btm.IsActive = true; if (btm.Id == 0) { db.BOMTranses.Add(btm); } _bomtarns.Add(btm); } foreach (var item in bomOrderDtos) { var btm = new BOMTransModel(); if (item.Id > 0) { btm = db.BOMTranses.Find(item.Id); } btm.ProductId = item.ProductId; btm.UomId = item.EmpId; btm.OrderTransId = item.OrderTransId; btm.AccId = item.AccId; btm.BaseQty = item.Qty; btm.Stock = item.StockQty; btm.ShortQty = item.Balance; btm.Remark1 = item.Remark1; btm.Remark2 = item.Remark2; btm.TransType = 2; btm.IsDeleted = false; btm.IsActive = true; if (btm.Id == 0) { btm.BOMId = bm.Id; db.BOMTranses.Add(btm); } } db.SaveChanges(); var stk = db.StockTranses.Where(k => k.MasterRefId == bm.RowId).ToList(); if (stk != null) { db.StockTranses.RemoveRange(stk); } // for stock effect from bom comsumuption & productoin if (BomPara.Auto_Consumption_And_Production) { var pdorg = db.Products.Find(bm.ProductId); if (pdorg.StockReq == "Yes") { StockEffect.Stock_Bom_Prod_Entry(bm, db); } foreach (var item in _bomtarns) { var pd = db.Products.Find(item.ProductId); if (pd.StockReq == "No") { continue; } StockEffect.Stock_Bom_Issue_Entry(bm, db, item); } } db.SaveChanges(); var repid = db.Barcodes.DefaultIfEmpty().Max(x => x == null ? 0 : x.ReportId) + 1; bool IsBarcodeGenerated = false; if (this.PrimaryKey == 0 && MessageBox.Show("Generate Barcode. for Cutting.?", "Barcode", MessageBoxButtons.YesNo) == DialogResult.Yes) { var bcs = bomOrderDtos.Where(x => x.Balance > 0).ToList(); foreach (var item in bcs) { var bc = new BarcodeModel() { CompId = KontoGlobals.CompanyId, EmpId = item.EmpId, IsActive = true, IsDeleted = false, OrderTransId = item.OrderTransId, PcsNo = 1, AccId = item.AccId, Qty = Convert.ToInt32(item.Balance), ProductId = item.ProductId, RefId = bm.Id, ReportId = repid, IsLayer = true }; bc.BarcodeNo = GetNextBarcodeNo(db); //String.Format("{0:d9}", (DateTime.Now.Ticks / 10) % 1000000000); // KontoUtils.GetUniqueKey(8); db.Barcodes.Add(bc); } if (bcs.Count == 0) { var bc = new BarcodeModel() { CompId = KontoGlobals.CompanyId, IsActive = true, IsDeleted = false, PcsNo = 1, EmpId = 0, Qty = Convert.ToInt32(targetQtyButtonEdit.EditValue), ProductId = Convert.ToInt32(QualityLookup.Properties.SelectedValue), RefId = bm.Id, ReportId = repid, IsLayer = true }; bc.BarcodeNo = GetNextBarcodeNo(db); //String.Format("{0:d9}", (DateTime.Now.Ticks / 10) % 1000000000); //KontoUtils.GetUniqueKey(8); db.Barcodes.Add(bc); } db.SaveChanges(); IsBarcodeGenerated = true; } _tran.Commit(); MessageBoxAdv.Show("Record Save Successfully.."); if (this.PrimaryKey == 0 && IsBarcodeGenerated && MessageBox.Show("Print Barcode ... ?", "Print !", MessageBoxButtons.YesNo) == DialogResult.Yes) { PrintBarcode(repid); } this.ResetPage(); this.NewRec(); } catch (Exception ex) { _tran.Rollback(); Log.Error(ex, "BOM Save"); MessageBoxAdv.Show(this, "Error While Save !!", "Exception ", ex.ToString()); } if (this.OpenForLookup) { this.Close(); this.Dispose(); } } } }
private void UpdateBarcodeData(BarcodeModel bcm) { int divid = Convert.ToInt32(divLookUpEdit.EditValue.ToString()); using (var db = new KontoContext()) { using (var tr = db.Database.BeginTransaction()) { try { var bt = new BarcodeTrans() { BarcodeId = bcm.Id, DivId = divid, EmpId = Convert.ToInt32(empLookup1.SelectedValue), IsActive = true, IsDeleted = false, BarcodeNo = bcm.BarcodeNo, CompId = KontoGlobals.CompanyId, YearId = KontoGlobals.YearId, ProductId = bcm.ProductId, Qty = Convert.ToDecimal(qtyTextEdit.EditValue), TransType = 2, Remarks = RemarkTextEdit1.Text.Trim(), VoucherDate = Convert.ToInt32(voucherDateEdit.DateTime.ToString("yyyyMMdd")), }; db.BarcodeTrans.Add(bt); db.SaveChanges(); var bts = new BarcodeStock() { BarcodeId = Convert.ToInt32(bt.BarcodeId), BarcodeNo = bt.BarcodeNo, CompId = bt.CompId, DivId = bt.DivId, EmpId = bt.EmpId, IsActive = true, IsDeleted = false, Qty = -1 * bt.Qty, VoucherDate = bt.VoucherDate, YearId = bt.YearId, ProductId = bt.ProductId, RefId = bt.Id }; db.BarcodeStocks.Add(bts); db.SaveChanges(); tr.Commit(); var btDto = new BarcodeTransDto() { BarcodeId = bt.BarcodeId, BarcodeNo = bt.BarcodeNo, DivId = bt.DivId, DivName = divLookUpEdit.Text, EmpId = bt.EmpId, EmpName = empLookup1.SelectedText, Id = bt.Id, ProductId = bt.ProductId, ProductName = bcm.Product.ProductName, Qty = bt.Qty, TrnasType = 2, VoucherDate = bt.VoucherDate, Remarks = bt.Remarks }; barcodelist.Add(btDto); barcodeTransModelBindingSource.DataSource = barcodelist; gridControl1.RefreshDataSource(); barcode = null; barcodeNoTextEdit.Text = string.Empty; barcodeNoTextEdit.Focus(); stockTextEdit.Text = string.Empty; qtyTextEdit.Text = string.Empty; } catch (Exception ex) { tr.Rollback(); MessageBox.Show(ex.ToString()); Log.Error(ex, "barcode Scan Inward"); } } } }
public override void SaveDataAsync(bool newmode) { try { if (_bc == null) { return; } if (qtySpinEdit.Value == 0) { return; } var st = Convert.ToDecimal(stockLabelControl.Text); if (st - qtySpinEdit.Value < 0) { MessageBox.Show("Can not generate Barcode For Extra Qty"); return; } using (var db = new KontoContext()) { var repid = db.Barcodes.DefaultIfEmpty().Max(x => x == null ? 0 : x.ReportId) + 1; var barcode = Convert.ToInt32(GetNextBarcodeNo(db)); for (int i = 0; i < qtySpinEdit.Value; i++) { var bm = new BarcodeModel() { CompId = KontoGlobals.CompanyId, IsActive = true, IsDeleted = false, OrderTransId = _bc.OrderTransId, PcsNo = 1, AccId = _bc.AccId, Qty = 1, ProductId = _bc.ProductId, ReportId = repid, RefBarcodeId = _bc.Id }; if (i == 0) { bm.BarcodeNo = barcode.ToString(); } else { barcode = barcode + 1; bm.BarcodeNo = barcode.ToString(); }//String.Format("{0:d9}", (DateTime.Now.Ticks / 10) % 1000000000); //KontoUtils.GetUniqueKey(8)).tos; db.Barcodes.Add(bm); } db.SaveChanges(); _bc = null; PageReport rpt = new PageReport(); rpt.Load(new FileInfo("reg\\doc\\Outwardbarcode.rdlx")); rpt.Report.DataSources[0].ConnectionProperties.ConnectString = KontoGlobals.sqlConnectionString.ConnectionString; GrapeCity.ActiveReports.Document.PageDocument doc = new GrapeCity.ActiveReports.Document.PageDocument(rpt); doc.Parameters["Party"].CurrentValue = partyLabelControl.Text; doc.Parameters["ReportId"].CurrentValue = repid; doc.Parameters["BarcodeNo"].CurrentValue = "0"; var frm = new KontoRepViewer(doc); frm.Text = "Barcode"; var _tab = this.Parent.Parent as TabControlAdv; if (_tab == null) { return; } var pg1 = new TabPageAdv(); pg1.Text = "Barcode Print"; _tab.TabPages.Add(pg1); _tab.SelectedTab = pg1; frm.TopLevel = false; frm.Parent = pg1; frm.Location = new System.Drawing.Point(pg1.Location.X + pg1.Width / 2 - frm.Width / 2, pg1.Location.Y + pg1.Height / 2 - frm.Height / 2); frm.Show();// = true; } this.ResetPage(); barcodeTextEdit.Focus(); } catch (Exception ex) { Log.Error(ex, "Barcode Save"); MessageBox.Show(ex.ToString()); } }
private void SaveSimpleButton_Click(object sender, EventArgs e) { if (!ValidateData()) return; if (Convert.ToBoolean(radioGroup1.EditValue) == false && string.IsNullOrEmpty(remarkLookUpEdit.Text)) { MessageBox.Show("Please Select Remark."); remarkLookUpEdit.Focus(); return; } if (barcode == null) return; int divid = Convert.ToInt32(divLookUpEdit.EditValue.ToString()); using (var db = new KontoContext()) { using (var tr = db.Database.BeginTransaction()) { try { var bt = new BarcodeTrans() { BarcodeId = barcode.Id, DivId = divid, EmpId = Convert.ToInt32(empLookup1.SelectedValue), IsActive = true, IsDeleted = false, BarcodeNo = barcode.BarcodeNo, CompId = KontoGlobals.CompanyId, YearId = KontoGlobals.YearId, ProductId = barcode.ProductId, Qty = barcode.Qty, TransType = 1, Remarks = remarkLookUpEdit.Text, VoucherDate = Convert.ToInt32(voucherDateEdit.DateTime.ToString("yyyyMMdd")), QcPassed = Convert.ToBoolean(radioGroup1.EditValue) }; db.BarcodeTrans.Add(bt); db.SaveChanges(); if (bt.QcPassed && Convert.ToBoolean(divLookUpEdit.GetColumnValue("IsQcOut"))) { var bts = new BarcodeStock() { BarcodeId = Convert.ToInt32(bt.BarcodeId), BarcodeNo = bt.BarcodeNo, CompId = bt.CompId, DivId = bt.DivId, EmpId = bt.EmpId, IsActive = true, IsDeleted = false, Qty = -1*bt.Qty, VoucherDate = bt.VoucherDate, YearId = bt.YearId, ProductId = bt.ProductId, RefId = bt.Id }; db.BarcodeStocks.Add(bts); db.SaveChanges(); } tr.Commit(); var btDto = new BarcodeTransDto() { BarcodeId = bt.BarcodeId, BarcodeNo = bt.BarcodeNo, DivId = bt.DivId, DivName = divLookUpEdit.Text, EmpId = bt.EmpId, EmpName = empLookup1.SelectedText, Id = bt.Id, ProductId = bt.ProductId, ProductName = barcode.Product.ProductName, Qty = bt.Qty, TrnasType = 1, QcPassed = bt.QcPassed, Remarks = bt.Remarks }; barcodelist.Add(btDto); barcodeTransModelBindingSource.DataSource = barcodelist; gridControl1.RefreshDataSource(); barcode = null; remarkLookUpEdit.EditValue = "NA"; barcodeNoTextEdit.Text = string.Empty; barcodeNoTextEdit.Focus(); } catch (Exception ex) { tr.Rollback(); Log.Error(ex, "qc saved"); } } } }