private void ListDateRange1_GetButtonClick(object sender, EventArgs e) { try { using (var _db = new KontoContext()) { _db.Database.CommandTimeout = 0; customGridView1.ShowLoadingPanel(); barcode_translist = (from bo in _db.BarcodeTrans join it in _db.Products on bo.ProductId equals it.Id join b in _db.Barcodes on bo.BarcodeId equals b.Id join e1 in _db.Emps on bo.EmpId equals e1.Id join dv in _db.Divisions on bo.DivId equals dv.Id where bo.TransType == 2 && bo.VoucherDate >= listDateRange1.FromDate && bo.VoucherDate <= listDateRange1.ToDate select new BarcodeTransDto { VoucherDate = bo.VoucherDate, BarcodeNo = bo.BarcodeNo, ProductName = it.ProductName, Remarks = bo.Remarks, Qty = bo.Qty, EmpName = e1.EmpName, TrnasType = bo.TransType, DivName = dv.DivisionName, Id = bo.Id } ).ToList(); customGridView1.Columns.Clear(); customGridControl1.DataSource = barcode_translist; customGridView1.HideLoadingPanel(); if (string.IsNullOrEmpty(this.GridLayoutFileName) || this.KontoView == null) { return; } if (barcode_translist.Count == 0) { listAction1.EditDeleteDisabled(false); } else { if (customGridView1.Columns.ColumnByFieldName("Id") != null && customGridView1.Columns.ColumnByFieldName("VoucherId") != null) { listAction1.EditDeleteDisabled(true); } else { listAction1.EditDeleteDisabled(false); } } if (string.IsNullOrEmpty(this.GridLayoutFileName) || this.KontoView == null) { return; } KontoUtils.RestoreLayoutGrid(this.GridLayoutFileName, this.KontoView); this.ActiveControl = customGridControl1; } } catch (Exception ex) { string str = ex.ToString(); } }
private void ListDateRange1_GetButtonClick(object sender, EventArgs e) { this.GridLayoutFileName = listDateRange1.SelectedItem.LayoutFile; var DtCriterias = new DataTable(); try { var db = new KontoContext(); using (var con = new SqlConnection(db.Database.Connection.ConnectionString)) { using (var cmd = new SqlCommand(listDateRange1.SelectedItem.SpName, con)) { cmd.CommandTimeout = 0; cmd.Parameters.Add("@fromDate", SqlDbType.Int).Value = listDateRange1.FromDate; cmd.Parameters.Add("@ToDate", SqlDbType.Int).Value = listDateRange1.ToDate; cmd.Parameters.Add("@CompanyId", SqlDbType.Int).Value = KontoGlobals.CompanyId; cmd.Parameters.Add("@BranchId", SqlDbType.Int).Value = KontoGlobals.BranchId; cmd.Parameters.Add("@YearId", SqlDbType.Int).Value = KontoGlobals.YearId; cmd.Parameters.Add("@VTypeId", SqlDbType.Int).Value = (int)VoucherTypeEnum.StoreIssue; if (listDateRange1.SelectedItem.Extra1 == "Deleted") { cmd.Parameters.Add("@Deleted", SqlDbType.Int).Value = 1; } if (listDateRange1.SelectedItem.GroupCol != null) { string grpCol = listDateRange1.SelectedItem.GroupCol; cmd.Parameters.Add("@GrpBy", SqlDbType.Text).Value = listDateRange1.SelectedItem.GroupCol; } cmd.CommandType = CommandType.StoredProcedure; con.Open(); DtCriterias.Load(cmd.ExecuteReader()); con.Close(); customGridView1.ShowLoadingPanel(); customGridView1.Columns.Clear(); customGridControl1.DataSource = DtCriterias; customGridView1.HideLoadingPanel(); } } if (DtCriterias.Rows.Count == 0) { listAction1.EditDeleteDisabled(false); } else { if (customGridView1.Columns.ColumnByFieldName("Id") != null && customGridView1.Columns.ColumnByFieldName("VoucherId") != null) { listAction1.EditDeleteDisabled(true); } else { listAction1.EditDeleteDisabled(false); } } if (string.IsNullOrEmpty(this.GridLayoutFileName) || this.KontoView == null) { return; } KontoUtils.RestoreLayoutGrid(this.GridLayoutFileName, this.KontoView); this.ActiveControl = customGridControl1; } catch (Exception ex) { Log.Error(ex, "SJ List Error"); MessageBoxAdv.Show(this, "Error While Generating List !!", "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"); } }
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 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 LoadData(BomModel model, KontoContext _context = null) { this.ResetPage(); this.PrimaryKey = model.Id; divLookUpEdit.EditValue = model.DivisionId; voucherLookup1.SelectedValue = model.VoucherId; Remark.Text = model.Remark; targetQtyButtonEdit.Text = Convert.ToString(model.TargetQty); ordertypeLookUpEdit1.EditValue = model.Description; voucherDateEdit.EditValue = KontoUtils.IToD(model.VoucherDate); voucherNoTextEdit.Text = model.VoucherNo; QualityLookup.Properties.SelectedValue = model.ProductId; //QualityLookup.Properties.DisplayText = using (var _db = new KontoContext()) { var prd = _db.Products.Find(model.ProductId); if (prd != null) { QualityLookup.EditValue = prd.ProductName; QualityLookup.Properties.DisplayText = prd.ProductName; } PFormula = (from b in _db.Boms join bt in _db.BOMTranses on b.Id equals bt.BOMId join q in _db.Products on bt.ProductId equals q.Id join cate in _db.CategroyModels on bt.UomId equals cate.Id into j1 from s1 in j1.DefaultIfEmpty() join col in _db.ColorModels on bt.ColorId equals col.Id into j2 from s2 in j2.DefaultIfEmpty() where b.Id == model.Id && bt.TransType == 1 orderby b.ProductId select new BomTransDto { Amount = bt.Amount, BaseQty = bt.BaseQty, BOMId = bt.BOMId, Id = bt.Id, OrderTransId = bt.OrderTransId, RefQty = bt.RefQty, RequireQty = bt.RequireQty, ShortQty = bt.ShortQty, Stock = bt.Stock, UomId = bt.UomId, ProductId = bt.ProductId, ProductName = q.ProductName, ColorId = bt.ColorId, ColorName = s2.ColorName, Rate = bt.Rate }).ToList(); gridControl1.DataSource = PFormula; bomOrderDtos = (from b in _db.Boms join bt in _db.BOMTranses on b.Id equals bt.BOMId join q in _db.Products on bt.ProductId equals q.Id join emp in _db.Emps on bt.UomId equals emp.Id into e1 from e2 in e1.DefaultIfEmpty() join ot in _db.OrdTranses on bt.OrderTransId equals ot.Id into o1 from o2 in o1.DefaultIfEmpty() join o in _db.Ords on o2.OrdId equals o.Id join a in _db.Accs on o.AccId equals a.Id into a1 from a2 in a1.DefaultIfEmpty() where b.Id == model.Id orderby b.ProductId select new BomOrderDto { Id = bt.Id, ProductId = bt.ProductId, ProductName = q.ProductName, OrderDate = o.VoucherDate, OrderNo = o.RefNo, EmpId = bt.UomId, EmployeeName = e2.EmpName, Qty = bt.BaseQty, AccId = bt.AccId, AccName = a2.AccName, RefNo = o.RefNo, Balance = bt.RequireQty, StockQty = bt.Stock, Remark1 = bt.Remark1, Remark2 = bt.Remark2, BomId = b.Id, OrderTransId = bt.OrderTransId }).ToList(); gridControl2.DataSource = bomOrderDtos; } }
private void BarcodeNoTextEdit_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode != Keys.Enter) { return; } if (string.IsNullOrEmpty(barcodeNoTextEdit.Text.Trim())) { return; } try { var _trans = this.bindingSource1.DataSource as List <JobIssueBarcodeDto>; if (_trans == null) { _trans = new List <JobIssueBarcodeDto>(); } if (_trans.Any(x => x.Barcode == barcodeNoTextEdit.Text.Trim())) { MessageBox.Show("Barcode No Already Exist"); barcodeNoTextEdit.Text = string.Empty; return; } using (var db = new KontoContext()) { db.Database.CommandTimeout = 0; var _model = db.Database.SqlQuery <DetailStockDto>( "dbo.GetBoxTakaByBarcode @compid={0} ,@barcodeno={1}", KontoGlobals.CompanyId, barcodeNoTextEdit.Text.Trim()).FirstOrDefault(); if (_model == null) { MessageBox.Show("Barcode does not exists,Please enter valid barcode"); return; } _Data = new JobIssueBarcodeDto() { Barcode = _model.Extra1, ChallanNo = _model.VoucherNo, Color = _model.ColorName, VoucherNo = _model.VoucherNo, ColorId = _model.ColorId, Id = _model.Id, LotNo = _model.LotNo, Product = _model.YarnName, ProductId = _model.ProductId, Qty = (decimal)_model.Qty, RefId = _model.RefId, TransId = _model.TransId, Weaver = _model.Weaver, VoucherDate = (int)_model.VoucherDate, SrNo = _model.SrNo, OrgQty = (decimal)_model.OrgQty }; ProducttextEdit.Text = _Data.Product; QtyEdit.Text = _model.OrgQty.ToString(); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
private void GetForumla() { try { if (this.PrimaryKey != 0) { return; } if (string.IsNullOrEmpty(ordertypeLookUpEdit1.Text)) { return; } if (string.IsNullOrEmpty(targetQtyButtonEdit.Text)) { return; } if (Convert.ToInt32(QualityLookup.Properties.SelectedValue) == 0) { return; } var _qty = Convert.ToDecimal(targetQtyButtonEdit.Text); var pid = Convert.ToInt32(QualityLookup.Properties.SelectedValue); using (var db = new KontoContext()) { PFormula = (from p in db.PFormulas join pd in db.Products on p.RefProductId equals pd.Id join cl in db.ColorModels on p.ColorId equals cl.Id into j1 from j2 in j1.DefaultIfEmpty() where p.ProductId == pid select new BomTransDto { ProductName = pd.ProductName, ProductId = (int)p.RefProductId, BaseQty = ordertypeLookUpEdit1.EditValue.ToString() == "Bulk" ? p.Cut : p.Qty, Rate = p.Rate, Amount = p.Total, UomId = (int)p.UomId, RequireQty = ordertypeLookUpEdit1.EditValue.ToString() == "Bulk" ? _qty * p.Cut : _qty * p.Qty, Remark1 = p.Remark, ColorId = p.ColorId, ColorName = j2.ColorName }).ToList(); foreach (var item in PFormula) { item.Stock = StockEffect.GetStock(item.ProductId); if (item.Stock - item.RequireQty > 0) { item.ShortQty = 0; } else { item.ShortQty = item.RequireQty - item.Stock; } } gridControl1.DataSource = PFormula; gridControl1.RefreshDataSource(); } } catch (Exception ex) { Log.Error(ex, "bom Quality Lookup chane"); MessageBox.Show(ex.ToString()); } }
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"); } } } }
private void barcodeNoTextEdit_KeyDown(object sender, KeyEventArgs e) { try { if (e.KeyCode != Keys.Return) { return; } if (!ValidateData()) { return; } using (var db = new KontoContext()) { int divid = Convert.ToInt32(divLookUpEdit.EditValue.ToString()); barcode = db.Barcodes.Include("Product").FirstOrDefault(x => x.BarcodeNo == barcodeNoTextEdit.Text.Trim()); if (barcode == null) { barcodeNoTextEdit.Text = string.Empty; MessageBox.Show("Barcode no does not exist.."); barcodeNoTextEdit.Focus(); e.Handled = true; return; } if (barcode.IsLayer) { MessageBox.Show("Layer/Cutting Division Barcode can not out.."); barcode = null; barcodeNoTextEdit.Text = string.Empty; barcodeNoTextEdit.Focus(); return; } //var bcs = db.BarcodeStocks.Where(x => x.BarcodeNo == barcode.BarcodeNo) // .GroupBy(x => x.DivId) // .Where(g => g.Sum(p => p.Qty) > 0) // .Select(g => new {divId= g.Key,Qty= g.Sum(x => x.Qty) }); // join bt in _db.BOMTranses on b.Id equals bt.BOMId var empid = Convert.ToInt32(empLookup1.SelectedValue); var bcs = (from p in db.BarcodeStocks join dv in db.Divisions on p.DivId equals dv.Id where p.BarcodeId == barcode.Id && dv.IsOutward && p.EmpId == empid && p.DivId == divid group p by p.BarcodeId into g select new { sum = g.Sum(x => x.Qty) }).FirstOrDefault(); if (bcs != null && bcs.sum == 1) { stockTextEdit.EditValue = barcode.Qty; qtyTextEdit.EditValue = barcode.Qty; UpdateBarcodeData(barcode); e.Handled = true; } else { MessageBox.Show("Selected Employee/Divisoin does not have stock"); barcodeNoTextEdit.Text = string.Empty; barcodeNoTextEdit.Focus(); e.Handled = true; barcode = null; } } } catch (Exception ex) { MessageBox.Show(ex.ToString()); Log.Error(ex, "barcode scan inward"); } }
private void barcodeNoTextEdit_KeyDown(object sender, KeyEventArgs e) { try { if (e.KeyCode != Keys.Return) { return; } if (!ValidateData()) { return; } using (var db = new KontoContext()) { int divid = Convert.ToInt32(divLookUpEdit.EditValue.ToString()); barcode = db.Barcodes.Include("Product").FirstOrDefault(x => x.BarcodeNo == barcodeNoTextEdit.Text.Trim()); if (barcode == null) { barcodeNoTextEdit.Text = string.Empty; MessageBox.Show("Barcode no does not exist.."); barcodeNoTextEdit.Focus(); e.Handled = true; return; } var dv1 = db.Divisions.Find(divid); if (barcode.IsLayer) { if (dv1 != null && dv1.Priority != 1) { MessageBox.Show("Entered Barcode can only issued in Layer/Cutting Division"); barcode = null; return; } } else { if (dv1.Priority == 1) { MessageBox.Show("Entered Barcode can not be issued in Layer/Cutting Division"); barcodeNoTextEdit.Text = string.Empty; barcode = null; barcodeNoTextEdit.Focus(); e.Handled = true; return; } } //var bcs = db.BarcodeStocks.Where(x => x.BarcodeNo == barcode.BarcodeNo) // .GroupBy(x => x.DivId) // .Where(g => g.Sum(p => p.Qty) > 0) // .Select(g => new {divId= g.Key,Qty= g.Sum(x => x.Qty) }); // join bt in _db.BOMTranses on b.Id equals bt.BOMId var bcs = (from p in db.BarcodeStocks join dv in db.Divisions on p.DivId equals dv.Id where p.BarcodeId == barcode.Id group p by new { dv.Id, dv.DivisionName } into g where g.Sum(x => x.Qty) > 0 from p in g select new { id = g.Key.Id, Div = g.Key.DivisionName, Qty = g.Sum(x => x.Qty) }).FirstOrDefault(); if (bcs == null) { stockTextEdit.EditValue = barcode.Qty; qtyTextEdit.EditValue = barcode.Qty; UpdateBarcodeData(barcode); e.Handled = true; } else { MessageBox.Show("Barcode Already Exist in Division : " + bcs.Div); barcodeNoTextEdit.Text = string.Empty; barcodeNoTextEdit.Focus(); e.Handled = true; barcode = null; } } } catch (Exception ex) { MessageBox.Show(ex.ToString()); Log.Error(ex, "barcode scan inward"); } //using (var db = new KontoContext()) //{ // try // { // int divid = Convert.ToInt32(divLookUpEdit.EditValue.ToString()); // barlist = db.BarcodeTrans.Where(p => p.DivId == divid && p.BarcodeNo == barcodeNoTextEdit.EditValue).ToList(); // int barcodeqty = Convert.ToInt32(barlist.Sum(p => p.Qty)); // if (barcodeqty == 0) // { // var bt = new BarcodeTrans(); // var selectedbarcode = db.Database.SqlQuery<BarcodeTransDto>("BarcodeSelected").FirstOrDefault(bs => bs.BarcodeNo == barcodeNoTextEdit.EditValue.ToString()); // if (selectedbarcode == null) // { // MessageBox.Show("Invalid Barcode"); // barcodeNoTextEdit.Focus(); // return; // } // else // { // bt.BarcodeNo = selectedbarcode.BarcodeNo; // bt.ProductName = selectedbarcode.ProductName; // bt.OrderId = selectedbarcode.OrderId; // bt.Qty = selectedbarcode.Qty; // bt.Remark = RemarkTextEdit1.EditValue.ToString()=="" ? "" : RemarkTextEdit1.EditValue.ToString(); // bt.CreateUser = KontoGlobals.UserName; // bt.CreateDate = DateTime.Now; // bt.EmployeeName = selectedbarcode.EmployeeName; // bt.EmployeeId = selectedbarcode.EmployeeId; // bt.VoucherDate = Convert.ToInt32(voucherDateEdit.DateTime.ToString("yyyyMMdd")); // bt.CompId = KontoGlobals.CompanyId; // bt.YearId = KontoGlobals.YearId; // bt.IsActive = true; // bt.IsDeleted = false; // bt.DivId = Convert.ToInt32(divLookUpEdit.EditValue); // bt.AccId = selectedbarcode.AccId; // bt.ProductId = selectedbarcode.ProductId; // bt.AccName = selectedbarcode.AccName; // bt.TransType = 3;//(Inward) // barcodelist.Add(bt); // this.barcodeTransModelBindingSource.DataSource = barcodelist; // gridControl1.RefreshDataSource(); // db.barcode_trans.Add(bt); // bt = new Barcode_TransModel(); // db.SaveChanges(); // RemarkTextEdit1.EditValue = ""; // barcodeNoTextEdit.EditValue = ""; // } // } // else // { // MessageBox.Show("Barcode not in stock please go for next process"); // barcodeNoTextEdit.Focus(); // return; // } // } // catch (Exception ex) // { // Log.Error(ex, "Apparel Inward Error"); // MessageBoxAdv.Show(this, "Error While Generating Apparel Inward !!", "Exception ", ex.ToString()); // } //} }
private void GetBarcodeData() { try { if (string.IsNullOrEmpty(barcodeTextEdit.Text.Trim())) { MessageBox.Show("Invalid Barcode"); barcodeTextEdit.Focus(); return; } using (var _db = new KontoContext()) { var bd = new BarcodeTransDto(); _bc = _db.Barcodes.Include("Product").Include("Acc").FirstOrDefault(p => p.BarcodeNo == barcodeTextEdit.Text); if (_bc == null) { MessageBox.Show("Invalid Barcode.."); ResetPage(); barcodeTextEdit.Focus(); return; } //check for layer qc entry var btdata = _db.BarcodeTrans.FirstOrDefault(p => p.BarcodeId == _bc.Id && p.TransType == 1 && p.QcPassed); if (btdata == null) { MessageBox.Show("Barcode not found in layer QC"); ResetPage(); barcodeTextEdit.Focus(); _bc = null; return; } // check for generated Barcode... var sum = _db.Barcodes.Where(x => x.RefBarcodeId == _bc.Id).Count(); if (sum == _bc.Qty) { MessageBox.Show("Barcode Already Generated"); ResetPage(); barcodeTextEdit.Focus(); _bc = null; return; } qtySpinEdit.Value = _bc.Qty - sum; if (_bc.Acc != null) { partyLabelControl.Text = _bc.Acc.AccName; } productLabelControl.Text = _bc.Product.ProductName; stockLabelControl.Text = (_bc.Qty - sum).ToString(); qtySpinEdit.Focus(); } } catch (Exception ex) { Log.Error(ex, "Barcode find"); MessageBox.Show(ex.ToString()); } }
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"); } } } }
private void barcodeNoTextEdit_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode != Keys.Return) return; if (!ValidateData()) return; using(var db = new KontoContext()) { int divid = Convert.ToInt32(divLookUpEdit.EditValue.ToString()); barcode = db.Barcodes.Include("Product").FirstOrDefault(x => x.BarcodeNo == barcodeNoTextEdit.Text.Trim()); if (barcode == null) { barcodeNoTextEdit.Text = string.Empty; MessageBox.Show("Barcode no does not exist.."); barcodeNoTextEdit.Focus(); e.Handled = true; return; } // check for already Qc var existqc = db.BarcodeTrans.Any(x => x.BarcodeId == barcode.Id && x.DivId == divid && x.TransType == 1 && x.QcPassed); if(existqc) { MessageBox.Show("Already Qc Done For This barcode ?"); barcodeNoTextEdit.Text = string.Empty; barcodeNoTextEdit.Focus(); e.Handled = true; barcode = null; return; } //check for inward in selected division var sum = db.BarcodeStocks.Where(x => x.BarcodeId == barcode.Id && x.DivId == divid) .DefaultIfEmpty() .Sum(x => x == null ? 0 : x.Qty); if (sum == 0) { MessageBox.Show("Barcode does Not Exist in Selected Division"); barcodeNoTextEdit.Text = string.Empty; barcodeNoTextEdit.Focus(); e.Handled = true; barcode = null; return; } divLookUpEdit.Enabled = false; productNameLabel.Text = barcode.Product.ProductName; } //using (var db = new KontoContext()) //{ // try // { // var frm = new ImageWindowFrm(); // var selectedbarcode = db.Database.SqlQuery<BarcodeTransDto>("BarcodeSelected").FirstOrDefault(bs => bs.BarcodeNo == barcodeNoTextEdit.EditValue.ToString()); // frm.pimagelist = db.PImagies.Where(p => p.ProductId == selectedbarcode.ProductId).ToList(); // frm.ShowDialog(); // int divid = Convert.ToInt32(divLookUpEdit.EditValue.ToString()); // barlist = db.barcode_trans.Where(p => p.DivId == divid && p.BarcodeNo == barcodeNoTextEdit.EditValue).ToList(); // int barcodeqty = Convert.ToInt32(barlist.Sum(p => p.Qty)); // if (barcodeqty == 0) // { // var bt = new Barcode_TransModel(); // //var selectedbarcode = db.Database.SqlQuery<BarcodeTransDto>("BarcodeSelected trans={0},Div={1}", 0, divLookUpEdit.EditValue).FirstOrDefault(bs => bs.BarcodeNo == barcodeNoTextEdit.EditValue.ToString()); // //var selectedbarcode = db.Database.SqlQuery<BarcodeTransDto>("BarcodeSelected").FirstOrDefault(bs => bs.BarcodeNo == barcodeNoTextEdit.EditValue.ToString()); // if (selectedbarcode == null) // { // MessageBox.Show("Invalid Barcode"); // barcodeNoTextEdit.Focus(); // return; // } // else // { // bt.BarcodeNo = selectedbarcode.BarcodeNo; // bt.ProductName = selectedbarcode.ProductName; // bt.OrderId = selectedbarcode.OrderId; // bt.Qty = selectedbarcode.Qty; // //bt.Remark = remarkLookUpEdit.EditValue.ToString(); // if (frm._responce == false) // { // bt.IsPass = "******"; // } // else if (frm._responce == true) // { // bt.IsPass = "******"; // } // else // { // bt.IsPass = ispassLookUpEdit1.Text; // } // if (frm.remark != "") // { // bt.Remark = frm.remark; // } // else // { // bt.Remark = remarkLookUpEdit.EditValue.ToString(); // } // bt.CreateUser = KontoGlobals.UserName; // bt.CreateDate = DateTime.Now; // bt.EmployeeName = selectedbarcode.EmployeeName; // bt.EmployeeId = selectedbarcode.EmployeeId; // bt.VoucherDate = Convert.ToInt32(voucherDateEdit.DateTime.ToString("yyyyMMdd")); // bt.CompId = KontoGlobals.CompanyId; // bt.YearId = KontoGlobals.YearId; // bt.IsActive = true; // bt.IsDeleted = false; // bt.DivId = Convert.ToInt32(divLookUpEdit.EditValue); // bt.ProductId = selectedbarcode.ProductId; // bt.AccName = selectedbarcode.AccName; // bt.TransType = 1;//(Inward) // barcodelist.Add(bt); // this.barcodeTransModelBindingSource.DataSource = barcodelist; // gridControl1.RefreshDataSource(); // db.barcode_trans.Add(bt); // bt = new Barcode_TransModel(); // db.SaveChanges(); // remarkLookUpEdit.EditValue = ""; // barcodeNoTextEdit.EditValue = ""; // } // } // else // { // MessageBox.Show("Barcode not in stock please go for next process"); // barcodeNoTextEdit.Focus(); // return; // } // } // catch (Exception ex) // { // Log.Error(ex, "Apparel Inward Error"); // MessageBoxAdv.Show(this, "Error While Generating Apparel Inward !!", "Exception ", ex.ToString()); // } //} }