private bool SaveData()
 {
     try
     {
         decimal receiveWgh = lblWeight.Text.ToDecimal();
         string  createBy   = Helper.GetLocalIPAddress();
         barcode_no = Helper.GetMaxBarcode();
         using (var db = new SlaughterhouseEntities())
         {
             using (DbContextTransaction transaction = db.Database.BeginTransaction())
             {
                 try
                 {
                     //insert barcode
                     var barcode = new barcode
                     {
                         barcode_no      = barcode_no,
                         product_code    = productIssued.product_code,
                         production_date = productionDate,
                         lot_no          = productIssued.lot_no,
                         qty             = 1,
                         wgh             = receiveWgh,
                         active          = true,
                         create_by       = createBy,
                         qrcode_image    = Helper.GenerateQRCode(barcode_no.ToString()),
                         //location_code = locationCode
                     };
                     db.barcodes.Add(barcode);
                     //insert basic_yield_info
                     var basicYield = new basic_yield_info
                     {
                         production_date  = productionDate,
                         product_code     = barcode.product_code,
                         lot_no           = barcode.lot_no,
                         quantity         = barcode.qty,
                         weight           = barcode.wgh,
                         ref_product_code = PRODUCT_CODE,
                         ref_lot_no       = barcode.lot_no.Substring(0, barcode.lot_no.Length - 4),
                         barcode_no       = barcode_no,
                         create_by        = createBy
                     };
                     db.basic_yield_info.Add(basicYield);
                     db.SaveChanges();
                     transaction.Commit();
                     return(true);
                 }
                 catch (Exception)
                 {
                     transaction.Rollback();
                     throw;
                 }
             }
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
Exemplo n.º 2
0
 public static stock_item_running GetStockNo(string documentNo)
 {
     try
     {
         using (var db = new SlaughterhouseEntities())
         {
             var documentGenerate = db.document_generate.Find(Constants.STK);
             var stockItemRunning = db.stock_item_running.Where(p => p.doc_no.Equals(documentNo)).SingleOrDefault();
             if (stockItemRunning == null)
             {
                 //get new stock doc no
                 var stockNo = Constants.STK + documentGenerate.running.ToString().PadLeft(10 - Constants.STK.Length, '0');
                 //insert stock_item_running
                 var newStockItem = new stock_item_running
                 {
                     doc_no     = documentNo,
                     stock_no   = stockNo,
                     stock_item = 1,
                     create_by  = Helper.GetLocalIPAddress()
                 };
                 db.stock_item_running.Add(newStockItem);
                 documentGenerate.running        += 1;
                 db.Entry(documentGenerate).State = System.Data.Entity.EntityState.Modified;
                 db.SaveChanges();
                 return(newStockItem);
             }
             else
             {
                 //documentGenerate.running += 1;
                 //db.Entry(documentGenerate).State = System.Data.Entity.EntityState.Modified;
                 //db.SaveChanges();
                 stockItemRunning.stock_item     += 1;
                 db.Entry(stockItemRunning).State = System.Data.Entity.EntityState.Modified;
                 db.SaveChanges();
                 return(stockItemRunning);
             }
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
Exemplo n.º 3
0
 public static string GetDocGenerator(string docType)
 {
     try
     {
         using (var db = new SlaughterhouseEntities())
         {
             var docGenerator = db.document_generate.Find(docType);
             docGenerator.running += 1;
             var docNo = docType + docGenerator.running.ToString().PadLeft(10 - docType.Length, '0');
             db.SaveChanges();
             return(docNo);
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
Exemplo n.º 4
0
 public static long GetMaxBarcode()
 {
     try
     {
         int plantID = System.Configuration.ConfigurationManager.AppSettings["plantID"].ToInt16();
         using (var db = new SlaughterhouseEntities())
         {
             var barcodeGenerate = db.document_generate.Find(Constants.BAR);
             barcodeGenerate.running        += 1;
             db.Entry(barcodeGenerate).State = System.Data.Entity.EntityState.Modified;
             db.SaveChanges();
             var barString = barcodeGenerate.running.ToString().PadLeft(12, '0');
             return(string.Format("{0}{1}", plantID, barString).ToLong());
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
Exemplo n.º 5
0
        private void BtnCloseQueue_Click(object sender, EventArgs e)
        {
            try
            {
                var remainQty = lblRemainQty.Text.ToInt16();
                if (remainQty > 0)
                    throw new Exception("ไม่สามารถปิดคิว \nเนื่องจากรับไม่ครบ!");


                var receive_no = lblReceiveNo.Text;
                using (var db = new SlaughterhouseEntities())
                {
                    var receive = db.receives.Where(p => p.receive_no == receive_no).SingleOrDefault();

                    receive.receive_flag = 1;
                    receive.modified_at = DateTime.Now;
                    db.SaveChanges();

                    lblMessage.Text = "ปิดคิว เรียบร้อยแล้ว";
                }

                lblReceiveNo.Text = "";
                lblFarm.Text = "";
                lblBreeder.Text = "";
                lblTruckNo.Text = "";
                lblQueueNo.Text = "";
                lblFarmQty.Text = "0";
                lblFactoryQty.Text = "0";
                lblFactoryWgh.Text = "0";
                lblRemainQty.Text = "0";

            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 6
0
        private bool SaveData()
        {
            try
            {
                var    orderNo         = lblOrderNo.Text;
                var    scaleWeight     = lblWeight.Text.ToDecimal();
                var    refDocumentNo   = "";
                var    refDocumentType = "";
                string stockNo         = "";
                string transportNo     = "";
                int    transportItem   = 0;
                var    truckId         = cboTruckNo.SelectedValue.ToString().ToInt16();
                string createBy        = Helper.GetLocalIPAddress();
                using (var db = new SlaughterhouseEntities())
                {
                    using (DbContextTransaction transaction = db.Database.BeginTransaction())
                    {
                        try
                        {
                            refDocumentNo   = orderNo;
                            refDocumentType = Constants.SO;
                            //update order
                            var orderItem = db.orders_item.Where(p => p.order_no == orderNo &&
                                                                 p.product_code == product.product_code).SingleOrDefault();
                            if (orderItem.order_qty - orderItem.unload_qty == 0)
                            {
                                throw new Exception("ไม่สามารถจ่ายได้!\rจำนวนจ่ายครบแล้ว");
                            }

                            var transport = db.transports.Where(p => p.ref_document_no == orderNo).SingleOrDefault();
                            if (transport == null)
                            {
                                transportNo   = Helper.GetDocGenerator(Constants.TP);
                                transportItem = 1;
                            }
                            else
                            {
                                transportNo   = transport.transport_no;
                                transportItem = transport.transport_item.Count() + 1;
                            }

                            if (transport == null)
                            {
                                var trans = new transport
                                {
                                    transport_no    = transportNo,
                                    transport_date  = DateTime.Today,
                                    ref_document_no = orderNo,
                                    truck_id        = truckId,
                                    transport_flag  = 0,
                                    create_at       = DateTime.Now,
                                    create_by       = createBy
                                };
                                db.transports.Add(trans);
                            }
                            else
                            {
                                transport.truck_id        = truckId;
                                db.Entry(transport).State = EntityState.Modified;
                            }
                            //insert transport item
                            var transItem = new transport_item
                            {
                                transport_no  = transportNo,
                                product_code  = product.product_code,
                                seq           = transportItem,
                                transport_qty = 1,
                                transport_wgh = scaleWeight,
                                stock_no      = stockNo,
                                lot_no        = lotNo,
                                truck_id      = truckId,
                                barcode_no    = 0,
                                bom_code      = 0,
                                create_at     = DateTime.Now,
                                create_by     = createBy
                            };
                            db.transport_item.Add(transItem);

                            orderItem.unload_qty     += 1;
                            orderItem.unload_wgh     += scaleWeight;
                            orderItem.modified_at     = DateTime.Now;
                            orderItem.modified_by     = createBy;
                            db.Entry(orderItem).State = EntityState.Modified;

                            db.SaveChanges();
                            transaction.Commit();
                        }
                        catch (Exception)
                        {
                            transaction.Rollback();
                            throw;
                        }
                    }
                }
                return(true);
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 7
0
 private bool SaveData()
 {
     try
     {
         var    orderNo         = lblOrderNo.Text;
         var    scaleWeight     = lblWeight.Text.ToDecimal();
         var    refDocumentNo   = "";
         var    refDocumentType = "";
         var    transportNo     = "";
         var    truckId         = cboTruckNo.SelectedValue.ToString().ToInt16();
         string createBy        = Helper.GetLocalIPAddress();
         using (var db = new SlaughterhouseEntities())
         {
             var receiveItem = db.receive_item.Where(p => p.product_code == product.product_code &&
                                                     p.lot_no == lotNo &&
                                                     p.chill_qty == 0)
                               .OrderBy(p => p.seq).Take(1).SingleOrDefault();
             if (receiveItem == null)
             {
                 LoadLotNo();
                 throw new Exception("ไม่พบ Lot No\rกรุณาเลือก Lot No ใหม่!");
             }
             using (DbContextTransaction transaction = db.Database.BeginTransaction())
             {
                 try
                 {
                     int    seq     = 0;
                     string stockNo = "";
                     int    bomCode = 0;
                     if (!string.IsNullOrEmpty(orderNo))
                     {
                         refDocumentNo   = orderNo;
                         refDocumentType = Constants.SO;
                         //update order
                         var orderItem = db.orders_item.Where(p => p.order_no == orderNo &&
                                                              p.product_code == product.product_code).SingleOrDefault();
                         if (orderItem.order_qty - orderItem.unload_qty == 0)
                         {
                             throw new Exception("ไม่สามารถจ่ายได้!\rจำนวนจ่ายครบแล้ว");
                         }
                         bomCode = orderItem.bom_code;
                         //update production order
                         orderItem.unload_qty     += 1;
                         orderItem.unload_wgh     += scaleWeight;
                         orderItem.modified_at     = DateTime.Now;
                         orderItem.modified_by     = createBy;
                         db.Entry(orderItem).State = EntityState.Modified;
                         var transport        = db.transports.Where(p => p.ref_document_no == orderNo).SingleOrDefault();
                         var transportGenrate = db.document_generate.Find(Constants.TP);
                         if (transport == null)
                         {
                             transportNo = Constants.TP + transportGenrate.running.ToString().PadLeft(10 - Constants.TP.Length, '0');
                             //update transport running
                             transportGenrate.running        += 1;
                             db.Entry(transportGenrate).State = EntityState.Modified;
                         }
                         else
                         {
                             transportNo = transport.transport_no;
                         }
                     }
                     else
                     {
                         var issDoc = db.document_generate.Find(Constants.ISS);// (from p in db.document_generate where p.document_type == Constants.ISS select p).SingleOrDefault();
                         refDocumentNo   = Constants.ISS + issDoc.running.ToString().PadLeft(10 - Constants.ISS.Length, '0');
                         refDocumentType = Constants.ISS;
                     }
                     var stockGenerate = db.document_generate.Find(Constants.STK);
                     //check stock_item_running
                     var stockItemRunning = db.stock_item_running.Where(p => p.doc_no.Equals(refDocumentNo)).SingleOrDefault();
                     if (stockItemRunning == null)
                     {
                         //get new stock doc no
                         stockNo = Constants.STK + stockGenerate.running.ToString().PadLeft(10 - Constants.STK.Length, '0');
                         seq     = 1;
                     }
                     else
                     {
                         stockNo = stockItemRunning.stock_no;
                         seq     = stockItemRunning.stock_item + 1;
                     }
                     if (!string.IsNullOrEmpty(orderNo))
                     {
                         //update receive item
                         receiveItem.transfer_qty = 1;
                         receiveItem.transfer_wgh = scaleWeight;
                         var transport = db.transports.Find(transportNo);
                         if (transport == null)
                         {
                             var trans = new transport
                             {
                                 transport_no    = transportNo,
                                 transport_date  = DateTime.Today,
                                 ref_document_no = orderNo,
                                 truck_id        = truckId,
                                 transport_flag  = 0,
                                 create_at       = DateTime.Now,
                                 create_by       = createBy
                             };
                             db.transports.Add(trans);
                         }
                         else
                         {
                             transport.truck_id        = truckId;
                             db.Entry(transport).State = EntityState.Modified;
                         }
                         //insert transport item
                         var transItem = new transport_item
                         {
                             transport_no  = transportNo,
                             product_code  = product.product_code,
                             seq           = seq,
                             transport_qty = 1,
                             transport_wgh = scaleWeight,
                             stock_no      = stockNo,
                             lot_no        = lotNo,
                             truck_id      = truckId,
                             barcode_no    = 0,
                             bom_code      = bomCode,
                             create_at     = DateTime.Now,
                             create_by     = createBy
                         };
                         db.transport_item.Add(transItem);
                     }
                     else
                     {
                         //var issued = db.issued_info.Where(p => p.issued_date == productionDate
                         //                                && p.product_code == product.product_code
                         //                                && p.lot_no == lotNo).SingleOrDefault();
                         var issuedInfo = db.issued_info.Find(productionDate, product.product_code, lotNo);
                         if (issuedInfo == null)
                         {
                             var newIssued = new issued_info
                             {
                                 issued_date  = productionDate,
                                 product_code = product.product_code,
                                 lot_no       = lotNo,
                                 issued_qty   = 1,
                                 issued_wgh   = scaleWeight,
                                 usage_qty    = 0,
                                 usage_wgh    = 0,
                                 active       = true,
                                 create_at    = DateTime.Now,
                                 create_by    = createBy
                             };
                             db.issued_info.Add(newIssued);
                         }
                         else
                         {
                             issuedInfo.issued_qty     += 1;
                             issuedInfo.issued_wgh     += scaleWeight;
                             issuedInfo.modified_at     = DateTime.Now;
                             issuedInfo.modified_by     = createBy;
                             db.Entry(issuedInfo).State = EntityState.Modified;
                         }
                     }
                     //update receive item
                     receiveItem.chill_qty       = 1;
                     receiveItem.chill_wgh       = scaleWeight;
                     receiveItem.modified_at     = DateTime.Now;
                     receiveItem.modified_by     = createBy;
                     db.Entry(receiveItem).State = EntityState.Modified;
                     //insert stock
                     var stock = new stock
                     {
                         stock_date        = productionDate,
                         stock_no          = stockNo,
                         stock_item        = seq,
                         product_code      = product.product_code,
                         stock_qty         = 1,
                         stock_wgh         = scaleWeight,
                         ref_document_no   = refDocumentNo,
                         ref_document_type = refDocumentType,
                         lot_no            = lotNo,
                         location_code     = 2, //ห้องเย็นเก็บหมุซีก
                         barcode_no        = 0,
                         transaction_type  = 2,
                         create_by         = createBy
                     };
                     db.stocks.Add(stock);
                     //รับหมูซีก เครื่องใน ไม่ต้อง update stock_item_running เพราะเริ่มตาม receive_item.seq
                     if (stockItemRunning == null)
                     {
                         //insert stock_item_running
                         var newStockItem = new stock_item_running
                         {
                             doc_no     = refDocumentNo,
                             stock_no   = stockNo,
                             stock_item = 1,
                             create_by  = createBy
                         };
                         db.stock_item_running.Add(newStockItem);
                         //update document_generate
                         stockGenerate.running        += 1;
                         db.Entry(stockGenerate).State = EntityState.Modified;
                     }
                     else
                     {
                         //update stock_item_running
                         stockItemRunning.stock_item     += 1;
                         db.Entry(stockItemRunning).State = EntityState.Modified;
                     }
                     db.SaveChanges();
                     transaction.Commit();
                 }
                 catch (Exception)
                 {
                     transaction.Rollback();
                     throw;
                 }
             }
         }
         return(true);
     }
     catch (Exception)
     {
         throw;
     }
 }
Exemplo n.º 8
0
        //private static void PlayNotificationSound(string sound)
        //{
        //    var soundsFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Sounds");
        //    var soundFile = Path.Combine(soundsFolder, sound + ".wav");

        //    using (var player = new System.Media.SoundPlayer(soundFile))
        //    {
        //        player.Play();
        //    }
        //}

        private bool SaveData()
        {
            try
            {
                var receive_wgh = lblWeight.Text.ToDecimal();
                using (var db = new SlaughterhouseEntities())
                {
                    //update receive
                    var receive = db.receives.Where(p => p.receive_no.Equals(lblReceiveNo.Text)).SingleOrDefault();

                    int stock_qty = receive.receive_item.Where(p => p.product_code.Equals(product.product_code)).Sum(p => p.receive_qty);
                    if (receive.factory_qty - stock_qty == 0)
                    {
                        throw new Exception("จำนวนรับครบแล้ว ไม่สามารถรับเพิ่มได้!");
                    }


                    int seq = receive.receive_item.Where(p => p.product_code.Equals(product.product_code)).Count();
                    //int seq = db.receive_item.Where(p => p.receive_no == receive.receive_no).Count();
                    seq += 1;
                    var item = new receive_item
                    {
                        receive_no   = receive.receive_no,
                        product_code = product.product_code,
                        seq          = seq,
                        lot_no       = receive.lot_no,
                        sex_flag     = "",
                        receive_qty  = 1,
                        receive_wgh  = receive_wgh,
                        chill_qty    = 0,
                        chill_wgh    = 0,
                        create_by    = Constants.CREATE_BY
                    };

                    string stock_no = db.stock_item_running.Where(p => p.doc_no.Equals(receive.receive_no)).Select(p => p.stock_no).SingleOrDefault();

                    //var documentGenerate = (from p in db.document_generate where p.document_type == Constants.STK select p).SingleOrDefault();


                    //check stock_item_running
                    //var stockItemRunning = db.stock_item_running.Where(p => p.doc_no.Equals(receive.receive_no)).SingleOrDefault();
                    //if (stockItemRunning == null)
                    //{
                    //    //get new stock doc no
                    //    stock_no = Constants.STK + documentGenerate.running.ToString().PadLeft(10 - Constants.STK.Length, '0');
                    //}
                    //else
                    //{
                    //    stock_no = stockItemRunning.stock_no;
                    //}


                    using (DbContextTransaction transaction = db.Database.BeginTransaction())
                    {
                        try
                        {
                            //receive.factory_qty += item.receive_qty;
                            //receive.factory_wgh += item.receive_wgh;
                            //db.Entry(receive).State = EntityState.Modified;

                            db.receive_item.Add(item);

                            //insert stock
                            var stock = new stock
                            {
                                stock_date        = DateTime.Today,
                                stock_no          = stock_no,
                                stock_item        = item.seq,
                                product_code      = item.product_code,
                                stock_qty         = item.receive_qty,
                                stock_wgh         = item.receive_wgh,
                                ref_document_no   = receive.receive_no,
                                ref_document_type = Constants.REV,
                                lot_no            = receive.lot_no,
                                location_code     = 2, //ห้องเย็นเก็บหมุซีก
                                barcode_no        = 0,
                                transaction_type  = 1,
                                create_by         = item.create_by
                            };

                            db.stocks.Add(stock);

                            //รับหมูซีก เครื่องใน ไม่ต้อง update stock_item_running เพราะเริ่มตาม receive_item.seq

                            //if (stockItemRunning == null)
                            //{
                            //    //insert stock_item_running
                            //    var newStockItem = new stock_item_running
                            //    {
                            //        doc_no = receive.receive_no,
                            //        stock_no = stock_no,
                            //        stock_item = 1,
                            //        create_by = item.create_by

                            //    };

                            //    db.stock_item_running.Add(newStockItem);

                            //    //update document_generate
                            //    documentGenerate.running += 1;
                            //    db.Entry(documentGenerate).State = EntityState.Modified;


                            //}
                            //else
                            //{

                            //    //update stock_item_running
                            //    stockItemRunning.stock_item += 1;
                            //    db.Entry(stockItemRunning).State = EntityState.Modified;
                            //}



                            db.SaveChanges();
                            transaction.Commit();
                        }
                        catch (Exception)
                        {
                            transaction.Rollback();
                            throw;
                        }
                    }
                }


                return(true);
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 9
0
 private bool SaveData()
 {
     try
     {
         decimal receiveWgh = lblWeight.Text.ToDecimal();
         string  createBy   = Helper.GetLocalIPAddress();
         //string stockNo = "";
         //int stockItem = 0;
         barcode_no = Helper.GetMaxBarcode();
         using (var db = new SlaughterhouseEntities())
         {
             //var barcodeGenerate = db.document_generate.Find(Constants.BAR);
             //barcodeGenerate.running += 1;
             //barcodeNo = barcodeGenerate.running;
             //db.Entry(barcodeGenerate).State = System.Data.Entity.EntityState.Modified;
             //db.SaveChanges();
             //var stocks = db.stocks.Where(p => p.stock_date == productionDate
             //    && p.product_code == product_code
             //    && p.lot_no == lot_no
             //    && p.transaction_type == 1).ToList();
             //if (stocks.Count == 0)
             //{
             //    var stockGenerate = db.document_generate.Find(Constants.STK);
             //    stockNo = Constants.STK + stockGenerate.running.ToString().PadLeft(10 - Constants.STK.Length, '0');
             //    stockItem = 1;
             //    stockGenerate.running += 1;
             //    db.Entry(stockGenerate).State = System.Data.Entity.EntityState.Modified;
             //    db.SaveChanges();
             //}
             //else
             //{
             //    stockNo = stocks[0].stock_no;
             //    stockItem = stocks.Count + 1;
             //}
             using (DbContextTransaction transaction = db.Database.BeginTransaction())
             {
                 try
                 {
                     //Get Barcode
                     //var maxValue = db.barcodes.Max(x => (long?)x.barcode_no) ?? 0;
                     //if (maxValue == 0)
                     //{
                     //    barcode_no = string.Format("{0}0000000001", plantID).ToLong();
                     //}
                     //else
                     //{
                     //    barcode_no = maxValue + 1;
                     //}
                     //var barString = barcodeNo.ToString().PadLeft(12, '0');
                     //barcode_no = string.Format("{0}{1}", plantID, barString).ToLong();
                     //insert barcode
                     var barcode = new barcode
                     {
                         barcode_no      = barcode_no,
                         product_code    = product_code,
                         production_date = productionDate,
                         lot_no          = lot_no,
                         qty             = 1,
                         wgh             = receiveWgh,
                         active          = true,
                         create_by       = createBy,
                         qrcode_image    = Helper.GenerateQRCode(barcode_no.ToString()),
                         //location_code = locationCode
                     };
                     db.barcodes.Add(barcode);
                     //insert basic_yield_info
                     var basicYield = new basic_yield_info
                     {
                         production_date  = productionDate,
                         product_code     = barcode.product_code,
                         lot_no           = barcode.lot_no,
                         quantity         = barcode.qty,
                         weight           = barcode.wgh,
                         ref_product_code = PRODUCT_CODE,
                         ref_lot_no       = barcode.lot_no.Substring(0, barcode.lot_no.Length - 4),
                         barcode_no       = barcode_no,
                         create_by        = createBy
                     };
                     db.basic_yield_info.Add(basicYield);
                     //insert receive_item
                     //db.receive_item.Add(item);
                     //insert stock
                     //var stock = new stock
                     //{
                     //    stock_date = productionDate,
                     //    stock_no = stockNo,
                     //    stock_item = stockItem,
                     //    product_code = barcode.product_code,
                     //    stock_qty = barcode.qty,
                     //    stock_wgh = barcode.wgh,
                     //    //ref_document_no = receive.receive_no,
                     //    //ref_document_type = Constants.REV,
                     //    lot_no = barcode.lot_no,
                     //    location_code = locationCode,
                     //    barcode_no = barcode_no,
                     //    transaction_type = 1,
                     //    create_by = createBy
                     //};
                     //db.stocks.Add(stock);
                     db.SaveChanges();
                     transaction.Commit();
                     return(true);
                 }
                 catch (Exception)
                 {
                     transaction.Rollback();
                     throw;
                 }
             }
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
Exemplo n.º 10
0
 private bool SaveData()
 {
     try
     {
         var    createBy    = Helper.GetLocalIPAddress();
         var    orderNo     = lblOrderNo.Text;
         var    barcodeNo   = txtBarcodeNo.Text.ToLong();
         var    truckId     = cboTruckNo.SelectedValue.ToString().ToInt16();
         string stockNo     = "";
         int    stockItem   = 0;
         string transportNo = "";
         using (var db = new SlaughterhouseEntities())
         {
             var barcode = db.barcodes.Find(barcodeNo);
             if (barcode == null)
             {
                 throw new Exception("ไม่พบข้อมูลบาร์โค็ดนี้! \rหรือจ่ายออกแล้ว");
             }
             //if (barcode.active == false)
             //{
             //    throw new Exception("ข้อมูลบาร์โค็ด จ่ายออกแล้ว!");
             //}
             var orderItems = db.orders_item.Where(p => p.order_no == orderNo &&
                                                   p.product_code == barcode.product_code)
                              .OrderBy(p => p.seq).SingleOrDefault();
             if (orderItems == null)
             {
                 throw new Exception("สินค้าไม่ตรง กับรายการสั่งขาย!");
             }
             if (orderItems.unload_qty >= orderItems.order_qty)
             {
                 throw new Exception("จ่ายสินค้า ครบแล้ว!");
             }
             var transport        = db.transports.Where(p => p.ref_document_no == orderNo).SingleOrDefault();
             var transportGenrate = db.document_generate.Find(Constants.TP);
             if (transport == null)
             {
                 var stockGenerate = db.document_generate.Find(Constants.STK);
                 stockNo = Constants.STK + stockGenerate.running.ToString().PadLeft(10 - Constants.STK.Length, '0');
                 stockGenerate.running        += 1;
                 db.Entry(stockGenerate).State = EntityState.Modified;
                 db.SaveChanges();
                 stockItem   = 1;
                 transportNo = Constants.TP + transportGenrate.running.ToString().PadLeft(10 - Constants.TP.Length, '0');
             }
             else
             {
                 transportNo = transport.transport_no;
                 var transportItem = db.transport_item.Where(p => p.transport_no == transport.transport_no).ToList();
                 if (transportItem.Count == 0)
                 {
                     var stockGenerate = db.document_generate.Find(Constants.STK);
                     stockNo = Constants.STK + stockGenerate.running.ToString().PadLeft(10 - Constants.STK.Length, '0');
                     stockGenerate.running        += 1;
                     db.Entry(stockGenerate).State = EntityState.Modified;
                     db.SaveChanges();
                     transportNo = transport.transport_no;
                 }
                 else
                 {
                     stockNo = transportItem[0].stock_no;
                 }
                 stockItem = transportItem.Count + 1;
                 //if (transport.transport_item.Count == 0)
                 //{
                 //    stockNo = Constants.STK + stockGenerate.running.ToString().PadLeft(10 - Constants.STK.Length, '0');
                 //    transportNo = transport.transport_no;
                 //}
                 //else
                 //{
                 //    stockNo = transport.transport_item.Select(p => p.stock_no).First();
                 //}
                 //stockItem = transport.transport_item.Count() + 1;
             }
             using (DbContextTransaction transaction = db.Database.BeginTransaction())
             {
                 try
                 {
                     //insert stock
                     var stock = new stock
                     {
                         stock_date        = productionDate,
                         stock_no          = stockNo,
                         stock_item        = stockItem,
                         product_code      = barcode.product_code,
                         stock_qty         = barcode.qty,
                         stock_wgh         = barcode.wgh,
                         ref_document_no   = orderNo,
                         ref_document_type = Constants.SO,
                         lot_no            = barcode.lot_no,
                         location_code     = 0,
                         barcode_no        = barcode.barcode_no,
                         transaction_type  = 2,
                         create_by         = createBy
                     };
                     db.stocks.Add(stock);
                     //insert transport
                     if (transport == null)
                     {
                         var trans = new transport
                         {
                             transport_no    = transportNo,
                             transport_date  = DateTime.Today,
                             truck_id        = truckId,
                             ref_document_no = orderNo,
                             transport_flag  = 0,
                             create_at       = DateTime.Now,
                             create_by       = createBy
                         };
                         db.transports.Add(trans);
                         //update transport running
                         transportGenrate.running        += 1;
                         db.Entry(transportGenrate).State = EntityState.Modified;
                     }
                     //insert transport item
                     var transItem = new transport_item
                     {
                         transport_no  = transportNo,
                         product_code  = barcode.product_code,
                         seq           = stockItem,
                         transport_qty = barcode.qty,
                         transport_wgh = barcode.wgh,
                         stock_no      = stockNo,
                         lot_no        = barcode.lot_no,
                         truck_id      = truckId,
                         barcode_no    = barcode.barcode_no,
                         bom_code      = orderItems.bom_code,
                         create_at     = DateTime.Now,
                         create_by     = createBy
                     };
                     db.transport_item.Add(transItem);
                     //var genDoc = db.document_generate.Find(Constants.STK);
                     //set unload
                     orderItems.unload_qty     += barcode.qty;
                     orderItems.unload_wgh     += barcode.wgh;
                     orderItems.modified_by     = createBy;
                     orderItems.modified_at     = DateTime.Now;
                     db.Entry(orderItems).State = EntityState.Modified;
                     //set barcode
                     barcode.active          = false;
                     db.Entry(barcode).State = EntityState.Modified;
                     //var barcodeHis = new barcode_history();
                     //barcodeHis.barcode_no = barcode.barcode_no;
                     //barcodeHis.product_code = barcode.product_code;
                     //barcodeHis.production_date = barcode.production_date;
                     //barcodeHis.lot_no = barcode.lot_no;
                     //barcodeHis.qty = barcode.qty;
                     //barcodeHis.wgh = barcode.wgh;
                     //barcodeHis.active = barcode.active;
                     //barcodeHis.qrcode_image = barcode.qrcode_image;
                     //barcodeHis.location_code = barcode.location_code;
                     //barcodeHis.create_at = barcode.create_at;
                     //barcodeHis.qrcode_image = barcode.qrcode_image;
                     ////delete barcode
                     //db.barcodes.Remove(barcode);
                     db.SaveChanges();
                     transaction.Commit();
                     return(true);
                 }
                 catch (Exception)
                 {
                     transaction.Rollback();
                     throw;
                 }
             }
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
Exemplo n.º 11
0
 private void SaveData()
 {
     try
     {
         var weight = lblWeight.Text.ToDecimal();
         using (var db = new SlaughterhouseEntities())
         {
             //update receive
             var receive = db.receives.Find(lblReceiveNo.Text);
             if (receive.farm_qty - receive.factory_qty == 0)
             {
                 throw new Exception("ไม่สามารถรับเพิ่มได้! \rจำนวนรับครบแล้ว");
             }
             int seq = receive.receive_item.Count();
             //int seq = db.receive_item.Where(p => p.receive_no == receive.receive_no).Count();
             seq += 1;
             //string stock_no = "";
             //var stockDocument = (from p in db.document_generate where p.document_type == Constants.STK select p).SingleOrDefault();
             ////check stock_item_running
             //var stockItemRunning = db.stock_item_running.Where(p => p.doc_no.Equals(receive.receive_no)).SingleOrDefault();
             //if (stockItemRunning == null)
             //{
             //    //get new stock doc no
             //    stock_no = Constants.STK + stockDocument.running.ToString().PadLeft(10 - Constants.STK.Length, '0');
             //}
             //else
             //{
             //    stock_no = stockItemRunning.stock_no;
             //}
             using (DbContextTransaction transaction = db.Database.BeginTransaction())
             {
                 try
                 {
                     var item = new receive_item
                     {
                         receive_no   = receive.receive_no,
                         product_code = product.product_code,
                         seq          = seq,
                         lot_no       = receive.lot_no,
                         sex_flag     = sexFlag,
                         receive_qty  = 1,
                         receive_wgh  = weight,
                         chill_qty    = 0,
                         chill_wgh    = 0,
                         create_by    = createBy
                     };
                     db.receive_item.Add(item);
                     receive.factory_qty    += 1;
                     receive.factory_wgh    += weight;
                     receive.receive_flag    = 1;
                     db.Entry(receive).State = System.Data.Entity.EntityState.Modified;
                     ////insert stock
                     //var stock = new stock
                     //{
                     //    stock_date = productionDate,
                     //    stock_no = stock_no,
                     //    stock_item = item.seq,
                     //    product_code = item.product_code,
                     //    stock_qty = item.receive_qty,
                     //    stock_wgh = item.receive_wgh,
                     //    ref_document_no = receive.receive_no,
                     //    ref_document_type = Constants.REV,
                     //    lot_no = receive.lot_no,
                     //    location_code = 1,
                     //    barcode_no = 0,
                     //    transaction_type = 1,
                     //    create_by = item.create_by
                     //};
                     //if (stockItemRunning == null)
                     //{
                     //    //insert stock_item_running
                     //    var newStockItem = new stock_item_running
                     //    {
                     //        doc_no = receive.receive_no,
                     //        stock_no = stock_no,
                     //        stock_item = 1,
                     //        create_by = item.create_by
                     //    };
                     //    db.stock_item_running.Add(newStockItem);
                     //    //update document_generate
                     //    stockDocument.running += 1;
                     //    db.Entry(stockDocument).State = System.Data.Entity.EntityState.Modified;
                     //}
                     //else
                     //{
                     //    //update stock_item_running
                     //    stockItemRunning.stock_item += 1;
                     //    db.Entry(stockItemRunning).State = System.Data.Entity.EntityState.Modified;
                     //}
                     //db.stocks.Add(stock);
                     db.SaveChanges();
                     transaction.Commit();
                     lblMessage.Text = Constants.SAVE_SUCCESS;
                 }
                 catch (Exception)
                 {
                     transaction.Rollback();
                     throw;
                 }
             }
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
Exemplo n.º 12
0
        //private void BtnControl(bool start, bool ok, bool close)
        //{
        //    btnStart.Enabled = start;

        //    BtnOK.Enabled = ok;
        //    btnStop.Enabled = close;
        //}

        private bool SaveData()
        {
            try
            {
                var weight = lblWeight.Text.ToDecimal();
                using (var db = new SlaughterhouseEntities())
                {
                    //update receive
                    var receive = db.receives.Where(p => p.receive_no.Equals(lblReceiveNo.Text)).SingleOrDefault();

                    if (receive.farm_qty - receive.factory_qty == 0)
                    {
                        throw new Exception("จำนวนรับครบแล้ว ไม่สามารถรับเพิ่มได้!");
                    }


                    int seq = receive.receive_item.Count();
                    //int seq = db.receive_item.Where(p => p.receive_no == receive.receive_no).Count();
                    seq += 1;
                    var item = new receive_item
                    {
                        receive_no = receive.receive_no,
                        product_code = productCode,
                        seq = seq,
                        lot_no = receive.lot_no,
                        sex_flag = sexFlag,
                        receive_qty = 1,
                        receive_wgh = weight,
                        chill_qty = 0,
                        chill_wgh = 0,
                        create_by = Constants.CREATE_BY

                    };

                    string stock_no = "";
                    var documentGenerate = (from p in db.document_generate where p.document_type == Constants.STK select p).SingleOrDefault();
                    //check stock_item_running
                    var stockItemRunning = db.stock_item_running.Where(p => p.doc_no.Equals(receive.receive_no)).SingleOrDefault();
                    if (stockItemRunning == null)
                    {
                        //get new stock doc no
                        stock_no = Constants.STK + documentGenerate.running.ToString().PadLeft(10 - Constants.STK.Length, '0');
                    }
                    else
                    {
                        stock_no = stockItemRunning.stock_no;

                    }
                    using (DbContextTransaction transaction = db.Database.BeginTransaction())
                    {
                        try
                        {



                            receive.factory_qty += item.receive_qty;
                            receive.factory_wgh += item.receive_wgh;
                            db.Entry(receive).State = System.Data.Entity.EntityState.Modified;

                            db.receive_item.Add(item);

                            //insert stock
                            var stock = new stock
                            {
                                stock_date = receive.receive_date,
                                stock_no = stock_no,
                                stock_item = item.seq,
                                product_code = item.product_code,
                                stock_qty = item.receive_qty,
                                stock_wgh = item.receive_wgh,
                                ref_document_no = receive.receive_no,
                                ref_document_type = Constants.REV,
                                lot_no = receive.lot_no,
                                location_code = 1,
                                barcode_no = 0,
                                transaction_type = 1,
                                create_by = item.create_by
                            };

                            if (stockItemRunning == null)
                            {
                                //insert stock_item_running
                                var newStockItem = new stock_item_running
                                {
                                    doc_no = receive.receive_no,
                                    stock_no = stock_no,
                                    stock_item = 1,
                                    create_by = item.create_by
                                };

                                db.stock_item_running.Add(newStockItem);

                                //update document_generate
                                documentGenerate.running += 1;
                                db.Entry(documentGenerate).State = System.Data.Entity.EntityState.Modified;


                            }
                            else
                            {
                                //update stock_item_running
                                stockItemRunning.stock_item += 1;
                                db.Entry(stockItemRunning).State = System.Data.Entity.EntityState.Modified;
                            }



                            db.stocks.Add(stock);
                            db.SaveChanges();
                            transaction.Commit();
                            lblMessage.Text = Constants.SAVE_SUCCESS;
                        }
                        catch (Exception)
                        {

                            transaction.Rollback();
                            throw;
                        }

                    }

                }

                //ReceiveItem receiveItem = new ReceiveItem
                //{
                //    ReceiveNo = receive.ReceiveNo,
                //    ProductCode = this.productCode,
                //    SexFlag = sexFlag,
                //    ReceiveQty = 1,
                //    ReceiveWgh = lblWeight.Text.ToDecimal(),
                //    CreateBy = "Auto"
                //};
                //return ReceiveController.InsertItem(receiveItem);
                return true;
            }
            catch (Exception)
            {

                throw;
            }

        }
Exemplo n.º 13
0
        private void SaveData()
        {
            try
            {
                var receiveWgh = lblWeight.Text.ToDecimal();
                var createBy   = Helper.GetLocalIPAddress();
                using (var db = new SlaughterhouseEntities())
                {
                    var receive   = db.receives.Where(p => p.receive_no.Equals(lblReceiveNo.Text)).SingleOrDefault();
                    int remainQty = receive.farm_qty - receive.head_qty.ToString().ToInt16();
                    if (remainQty == 0)
                    {
                        throw new Exception("จำนวนรับครบแล้ว ไม่สามารถรับเพิ่มได้!");
                    }
                    //int receive_qty = receive.receive_item.Where(p => p.product_code.Equals(product.product_code)).Sum(p => p.receive_qty);
                    //if (receive.farm_qty - receive_qty == 0)
                    //{
                    //    throw new Exception("จำนวนรับครบแล้ว ไม่สามารถรับเพิ่มได้!");
                    //}
                    int seq = receive.receive_item.Where(p => p.product_code.Equals(product.product_code)).Count();
                    seq       += 1;
                    barcode_no = Helper.GetMaxBarcode();
                    //int count = db.barcodes.Count();
                    //if (count == 0)
                    //{
                    //    barcode_no = string.Format("{0}0000000001", plant.plant_id).ToLong();
                    //}
                    //else
                    //{
                    //    barcode_no = db.barcodes.Max(p => p.barcode_no) + 1;
                    //    if (barcode_no.ToString().Length > 11)
                    //    {
                    //        var tempBarcode = barcode_no.ToString().TrimStart('1');
                    //        var running = tempBarcode.ToLong();
                    //        var code = running.ToString().PadLeft(10, '0');
                    //        barcode_no = ("1" + code).ToLong();
                    //    }
                    //}

                    var item = new receive_item
                    {
                        receive_no   = receive.receive_no,
                        product_code = product.product_code,
                        seq          = seq,
                        lot_no       = receive.lot_no,
                        sex_flag     = "",
                        receive_qty  = 1,
                        receive_wgh  = receiveWgh,
                        chill_qty    = 0,
                        chill_wgh    = 0,
                        barcode_no   = barcode_no,
                        create_by    = createBy
                    };
                    //string stock_no = db.stock_item_running.Where(p => p.doc_no.Equals(receive.receive_no)).Select(p => p.stock_no).SingleOrDefault();
                    using (DbContextTransaction transaction = db.Database.BeginTransaction())
                    {
                        try
                        {
                            //insert barcode
                            //var qrData = string.Format("{0}|00{1}{2}", barcode_no, item.product_code, Convert.ToInt64(receiveWgh * 10000).ToString().PadLeft(6, '0'));
                            //insert barcode
                            var barcode = new barcode
                            {
                                barcode_no      = barcode_no,
                                product_code    = item.product_code,
                                production_date = plant.production_date,
                                lot_no          = receive.lot_no,
                                qty             = 1,
                                wgh             = receiveWgh,
                                active          = true,
                                create_by       = createBy,
                                qrcode_image    = Helper.GenerateQRCode(barcode_no.ToString()),
                                //location_code = locationCode,
                            };
                            //var barcode = new barcode
                            //{
                            //    barcode_no = barcode_no,
                            //    product_code = item.product_code,
                            //    production_date = plant.production_date,
                            //    lot_no = receive.lot_no,
                            //    qty = 1,
                            //    wgh = receiveWgh,
                            //    active = true,
                            //    create_by = createBy
                            //};
                            db.barcodes.Add(barcode);
                            db.receive_item.Add(item);

                            //insert stock
                            //var stock = new stock
                            //{
                            //    stock_date = plant.production_date,
                            //    stock_no = stock_no,
                            //    stock_item = item.seq,
                            //    product_code = item.product_code,
                            //    stock_qty = item.receive_qty,
                            //    stock_wgh = item.receive_wgh,
                            //    ref_document_no = receive.receive_no,
                            //    ref_document_type = Constants.REV,
                            //    lot_no = receive.lot_no,
                            //    location_code = locationCode,
                            //    barcode_no = barcode_no,
                            //    transaction_type = 1,
                            //    create_by = createBy
                            //};
                            //db.stocks.Add(stock);
                            receive.head_qty += item.receive_qty;
                            receive.head_wgh += item.receive_wgh;
                            db.SaveChanges();
                            transaction.Commit();
                        }
                        catch (Exception)
                        {
                            transaction.Rollback();
                            throw;
                        }
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 14
0
        private void Gv_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                DataGridView senderGrid = (DataGridView)sender;
                if (senderGrid.Columns[e.ColumnIndex] is DataGridViewButtonColumn && e.RowIndex >= 0)
                {
                    string barcode_no = gv.Rows[e.RowIndex].Cells[0].Value.ToString();
                    if (senderGrid.Columns[e.ColumnIndex].Name == "btnDelete")
                    {
                        if (MessageBox.Show($"ต้องการลบข้อมูล บาร์โค็ด {barcode_no} Yes/No?", "ยืนยัน", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                        {
                            return;
                        }
                        //delete barcode
                        using (var db = new SlaughterhouseEntities())
                        {
                            //string stockNo = "";
                            var createBy       = Helper.GetLocalIPAddress();
                            var barcode        = db.barcodes.Find(barcode_no.ToLong());
                            var receive        = db.receives.Find(ReceiveNo);
                            var delReceiveItem = receive.receive_item.Where(p => p.barcode_no == barcode.barcode_no).SingleOrDefault();
                            using (DbContextTransaction transaction = db.Database.BeginTransaction())
                            {
                                try
                                {
                                    var stock = db.stocks.Where(p => p.stock_date == barcode.production_date &&
                                                                p.product_code == barcode.product_code &&
                                                                p.ref_document_no == receive.receive_no &&
                                                                p.barcode_no == barcode.barcode_no).SingleOrDefault();
                                    //var sqlParams = new[]{
                                    //       new MySqlParameter("@production_date",barcode.production_date),
                                    //       new MySqlParameter("@product_code", barcode.product_code)
                                    //    };
                                    //db.Database.ExecuteSqlCommand("delete from stock where ")
                                    //var stockGenerate = db.document_generate.Find(Constants.DEL);
                                    //stockNo = Constants.DEL + stockGenerate.running.ToString().PadLeft(10 - Constants.DEL.Length, '0');
                                    ////insert stock
                                    //var stock = new stock
                                    //{
                                    //    stock_date = barcode.production_date,
                                    //    stock_no = stockNo,
                                    //    stock_item = 1,
                                    //    product_code = barcode.product_code,
                                    //    stock_qty = barcode.qty,
                                    //    stock_wgh = barcode.wgh,
                                    //    ref_document_no = receive.receive_no,
                                    //    ref_document_type = Constants.REV,
                                    //    lot_no = barcode.lot_no,
                                    //    location_code = (int?)barcode.location_code ?? 0,
                                    //    barcode_no = barcode.barcode_no,
                                    //    transaction_type = 2,
                                    //    create_by = createBy
                                    //};
                                    //db.stocks.Add(stock);
                                    //stockGenerate.running += 1;
                                    //db.Entry(stockGenerate).State = System.Data.Entity.EntityState.Modified;
                                    //update qty,weight
                                    db.stocks.Remove(stock);
                                    switch (CoreProductCode)
                                    {
                                    case "04001":
                                        receive.head_qty -= barcode.qty;
                                        receive.head_wgh -= barcode.wgh;
                                        break;

                                    case "00101":
                                        receive.byproduct_red_qty -= barcode.qty;
                                        receive.byproduct_red_wgh -= barcode.wgh;
                                        break;

                                    case "00201":
                                        receive.byproduct_white_qty -= barcode.qty;
                                        receive.byproduct_white_wgh -= barcode.wgh;
                                        break;
                                    }
                                    db.Entry(receive).State = System.Data.Entity.EntityState.Modified;
                                    //delete receive item
                                    db.receive_item.Remove(delReceiveItem);
                                    db.barcodes.Remove(barcode);
                                    db.SaveChanges();
                                    transaction.Commit();
                                    DisplayNotification("Success", $"ลบข้อมูลบาร์โค็ด {barcode_no} เรียบร้อยแล้ว", Color.Green);
                                    //MessageBox.Show($"ลบข้อมูลบาร์โค็ด {barcode_no} เรียบร้อยแล้ว", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                    LoadData();
                                }
                                catch (Exception)
                                {
                                    transaction.Rollback();
                                    throw;
                                }
                            }
                        }
                    }
                    else
                    {
                        //var reportPath = Application.StartupPath;
                        //ds.WriteXml(string.Format(path, "barcode.xml"), XmlWriteMode.WriteSchema);
                        doc.Load(Constants.REPORT_FILE);
                        //doc.Load(reportPath + $"\\Report\\Rpt\\{Constants.REPORT_FILE}");
                        DataTable dt = Helper.GetBarcode(barcode_no.ToLong());
                        //dt.WriteXml(reportPath + "\\Report\\Rpt\\barcode.xml");
                        doc.SetDataSource(dt);
                        doc.PrintToPrinter(1, true, 0, 0);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 15
0
        private void SaveData()
        {
            try
            {
                var receiveNo  = lblReceiveNo.Text;
                var receiveWgh = lblWeight.Text.ToDecimal();
                var receiveQty = lblQty.Text.ToInt16();
                var createBy   = Helper.GetLocalIPAddress();
                using (var db = new SlaughterhouseEntities())
                {
                    //int plantID = System.Configuration.ConfigurationManager.AppSettings["plantID"].ToInt16();
                    //var productionDate = db.plants.Find(plantID).production_date;
                    //update receive
                    var receive = db.receives.Find(receiveNo);
                    //int receive_qty = receive.receive_item.Where(p => p.product_code.Equals(productSelected.product_code)).Sum(p => p.receive_qty);
                    //if (receive.farm_qty - receive_qty == 0)
                    //{
                    //    throw new Exception("จำนวนรับครบแล้ว\rไม่สามารถรับเพิ่มได้!");
                    //}
                    int seq = receive.receive_item.Where(p => p.barcode_no > 0).Count();
                    //var receiveByProductBom = db.receive_item_by_product.Find(receiveNo, CoreProductCode, CoreProductCode);
                    //var receiveByProduct = db.receive_item_by_product.Find(receiveNo, CoreProductCode, productSelected.product_code);
                    //if (receiveByProductBom.target_qty - receiveByProduct.actual_qty == 0)
                    //{
                    //    throw new Exception("จำนวนรับครบแล้ว\rไม่สามารถรับเพิ่มได้!");
                    //}
                    //var maxValue = db.barcodes.Max(x => (long?)x.barcode_no) ?? 0;
                    //if (maxValue == 0)
                    //{
                    //    barcode_no = string.Format("{0}0000000001", plantID).ToLong();
                    //}
                    //else
                    //{
                    //    barcode_no = maxValue + 1;
                    //}
                    //int count = db.barcodes.Count();
                    //if (count == 0)
                    //{
                    //    barcode_no = string.Format("{0}0000000001", plantID).ToLong();
                    //}
                    //else
                    //{
                    //    barcode_no = db.barcodes.Max(p => p.barcode_no) + 1;
                    //    if (barcode_no.ToString().Length > 11)
                    //    {
                    //        var tempBarcode = barcode_no.ToString().TrimStart('1');
                    //        var running = tempBarcode.ToLong();
                    //        var code = running.ToString().PadLeft(10, '0');
                    //        barcode_no = string.Format("{0}{1}", plantID, code).ToLong();
                    //    }
                    //}
                    //int seq = db.receive_item.Where(p => p.receive_no == receive.receive_no).Count();
                    //
                    seq       += 1;
                    barcode_no = Helper.GetMaxBarcode();
                    var item = new receive_item
                    {
                        receive_no   = receive.receive_no,
                        product_code = productSelected.product_code,
                        seq          = seq,
                        lot_no       = receive.lot_no,
                        sex_flag     = "",
                        receive_qty  = receiveQty,
                        receive_wgh  = receiveWgh,
                        chill_qty    = 0,
                        chill_wgh    = 0,
                        barcode_no   = barcode_no,
                        create_by    = createBy
                    };
                    //string stock_no = "";
                    //var stockDocument = (from p in db.document_generate where p.document_type == Constants.STK select p).SingleOrDefault();
                    ////check stock_item_running
                    //var stockItemRunning = db.stock_item_running.Where(p => p.doc_no.Equals(receive.receive_no)).SingleOrDefault();
                    //if (stockItemRunning == null)
                    //{
                    //    //get new stock doc no
                    //    stock_no = Constants.STK + stockDocument.running.ToString().PadLeft(10 - Constants.STK.Length, '0');
                    //}
                    //else
                    //{
                    //    stock_no = stockItemRunning.stock_no;
                    //}
                    //var stockNo = StockHelper.GetStockNo(receiveNo).stock_no;
                    using (DbContextTransaction transaction = db.Database.BeginTransaction())
                    {
                        try
                        {
                            //var qrData = string.Format("{0}|00{1}{2}", barcode_no, item.product_code, Convert.ToInt64(receiveWgh * 10000).ToString().PadLeft(6, '0'));
                            //insert barcode
                            var barcode = new barcode
                            {
                                barcode_no      = barcode_no,
                                product_code    = productSelected.product_code,
                                production_date = productionDate,
                                lot_no          = receive.lot_no,
                                qty             = receiveQty,
                                wgh             = receiveWgh,
                                active          = true,
                                create_by       = createBy,
                                qrcode_image    = Helper.GenerateQRCode(barcode_no.ToString()),
                                //location_code = LocationCode,
                            };
                            db.barcodes.Add(barcode);
                            db.receive_item.Add(item);
                            //var stocks = new List<stock>();
                            //stocks.Add(new stock
                            //{
                            //    stock_date = DateTime.Today,
                            //    stock_no = stock_no,
                            //    stock_item = item.seq,
                            //    product_code = item.product_code,
                            //    stock_qty = item.receive_qty,
                            //    stock_wgh = item.receive_wgh,
                            //    ref_document_no = receive.receive_no,
                            //    ref_document_type = Constants.REV,
                            //    lot_no = receive.lot_no,
                            //    location_code = 1,
                            //    barcode_no = 0,
                            //    transaction_type = 2,
                            //    create_by = item.create_by
                            //});
                            //insert stock
                            //var stock = new stock
                            //{
                            //    stock_date = productionDate,
                            //    stock_no = stockNo,
                            //    stock_item = seq,
                            //    product_code = productSelected.product_code,
                            //    stock_qty = receiveQty,
                            //    stock_wgh = receiveWgh,
                            //    ref_document_no = receive.receive_no,
                            //    ref_document_type = Constants.REV,
                            //    lot_no = receive.lot_no,
                            //    location_code = LocationCode,
                            //    barcode_no = barcode_no,
                            //    transaction_type = 1,
                            //    create_by = createBy
                            //};
                            //db.stocks.Add(stock);
                            switch (CoreProductCode)
                            {
                            //case "04001":
                            //    receive.head_qty += item.receive_qty;
                            //    receive.head_wgh += item.receive_wgh;
                            //    break;
                            case "00-0101":
                                receive.byproduct_red_qty += receiveQty;
                                receive.byproduct_red_wgh += receiveWgh;
                                break;

                            case "00-0201":
                                receive.byproduct_white_qty += receiveQty;
                                receive.byproduct_white_wgh += receiveWgh;
                                break;
                            }
                            db.Entry(receive).State = System.Data.Entity.EntityState.Modified;

                            //if (CoreProductCode == productSelected.product_code)
                            //{
                            //    //var bomItems = (from a in db.boms
                            //    //                join b in db.bom_item on a.bom_code equals b.bom_code
                            //    //                where a.product_code == BomProductCode
                            //    //                select b).ToList();
                            //    var listOfByProduct = db.receive_item_by_product.Where(p => p.receive_no.Equals(receiveNo)
                            //    && p.bom_product_code == CoreProductCode
                            //    && p.product_code != CoreProductCode).ToList();
                            //    foreach (var proudct in listOfByProduct)
                            //    {
                            //        proudct.actual_qty += 1;
                            //        proudct.actual_wgh += 1;
                            //        //db.Entry(proudct).State = System.Data.Entity.EntityState.Modified;
                            //    }
                            //    receiveByProductBom.actual_qty += listOfByProduct.Count;
                            //    receiveByProductBom.actual_wgh += item.receive_wgh;
                            //    //listOfByProduct.ForEach(p => p.actual_qty += item.receive_qty, p.actual_wgh = item.receive_wgh);
                            //}
                            //else
                            //{
                            //    receiveByProductBom.actual_qty += item.receive_qty;
                            //    receiveByProductBom.actual_wgh += item.receive_wgh;
                            //    receiveByProduct.actual_qty += item.receive_qty;
                            //    receiveByProduct.actual_wgh += item.receive_wgh;
                            //    //db.Entry(receiveByProduct).State = System.Data.Entity.EntityState.Modified;
                            //}
                            db.SaveChanges();
                            transaction.Commit();
                            //PrintBarcode();
                        }
                        catch (Exception)
                        {
                            transaction.Rollback();
                            throw;
                        }
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 16
0
 private void SaveData()
 {
     try
     {
         string createBy     = Helper.GetLocalIPAddress();
         string stockNo      = string.Empty;
         int    stockItem    = 0;
         int    locationCode = cboLocation.SelectedValue.ToString().ToInt16();
         using (var db = new SlaughterhouseEntities())
         {
             long barcodeNo = txtBarcodeNo.Text.ToLong();
             var  barcode   = db.barcodes.Find(barcodeNo);
             if (barcode == null)
             {
                 throw new Exception("ไม่พบข้อมูลบาร์โค็ดนี้!");
             }
             //if (barcode.active == false)
             //{
             //    throw new Exception("ข้อมูลบาร์โค็ด จ่ายออกแล้ว!");
             //}
             if (barcode.location_code != null)
             {
                 throw new Exception("รหัสบาร์โค็ดนี้ รับเข้าคลังแล้ว!");
             }
             var stocks = db.stocks.Where(p => p.stock_date == productionDate &&
                                          p.product_code == barcode.product_code &&
                                          p.lot_no == barcode.lot_no &&
                                          p.transaction_type == 1).ToList();
             if (stocks.Count == 0)
             {
                 var stockGenerate = db.document_generate.Find(Constants.STK);
                 stockNo                       = Constants.STK + stockGenerate.running.ToString().PadLeft(10 - Constants.STK.Length, '0');
                 stockItem                     = 1;
                 stockGenerate.running        += 1;
                 db.Entry(stockGenerate).State = System.Data.Entity.EntityState.Modified;
                 db.SaveChanges();
             }
             else
             {
                 stockNo   = stocks[0].stock_no;
                 stockItem = stocks.Count + 1;
             }
             using (DbContextTransaction transaction = db.Database.BeginTransaction())
             {
                 try
                 {
                     //insert stock
                     var stock = new stock
                     {
                         stock_date   = productionDate,
                         stock_no     = stockNo,
                         stock_item   = stockItem,
                         product_code = barcode.product_code,
                         stock_qty    = barcode.qty,
                         stock_wgh    = barcode.wgh,
                         //ref_document_no = receive.receive_no,
                         //ref_document_type = Constants.REV,
                         lot_no           = barcode.lot_no,
                         location_code    = locationCode,
                         barcode_no       = barcode.barcode_no,
                         transaction_type = 1,
                         create_by        = createBy
                     };
                     db.stocks.Add(stock);
                     //update stock location
                     //stock.location_code =locationCode;
                     //db.Entry(stock).State = System.Data.Entity.EntityState.Modified;
                     //update barcode location
                     barcode.location_code   = locationCode;
                     barcode.modified_at     = DateTime.Now;
                     barcode.modified_by     = modifiedBy;
                     db.Entry(barcode).State = System.Data.Entity.EntityState.Modified;
                     db.SaveChanges();
                     transaction.Commit();
                 }
                 catch (Exception)
                 {
                     transaction.Rollback();
                     throw;
                 }
             }
             //foreach (int locationCode in _locations)
             //{
             //    if (barcode.location_code == locationCode)
             //        throw new Exception("รหัสบาร์โค็ดนี้ รับเข้าคลังแล้ว!");
             //}
             //lblWeight.Text = barcode.wgh.ToFormat2Decimal();
             //lblProduct.Text = barcode.product.product_name;
             //lblLotNo.Text = barcode.lot_no;
             //Get Location เดิม
             //var stocks = db.stocks.Where(p => p.stock_date == productionDate
             //    && p.product_code == barcode.product_code
             //    && p.location_code == barcode.location_code
             //    && p.barcode_no == barcode.barcode_no).ToList();
             //if (stocks.Count == 1)
             //{
             //    //var stock = db.stocks.Where(p => p.stock_date == productionDate
             //    //&& p.stock_no == stocks[0].stock_no
             //    //&& p.stock_item == stocks[0].stock_item
             //    //&& p.product_code == stocks[0].product_code).SingleOrDefault();
             //    //var stock = db.stocks.Find(productionDate, stocks[0].stock_no, stocks[0].stock_item, stocks[0].product_code);
             //}
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
Exemplo n.º 17
0
 private void Gv_CellClick(object sender, DataGridViewCellEventArgs e)
 {
     try
     {
         DataGridView senderGrid = (DataGridView)sender;
         if (senderGrid.Columns[e.ColumnIndex] is DataGridViewButtonColumn && e.RowIndex >= 0)
         {
             long barcodeNo = gv.Rows[e.RowIndex].Cells[IDX_BARCODE_NO].Value.ToString().ToLong();
             if (MessageBox.Show(string.Format("ต้องการยกเลิก รหัสบาร์โค็ด \r\n{0}\r\n ใช่หรือไม่?", barcodeNo), "ยืนยัน",
                                 MessageBoxButtons.YesNo,
                                 MessageBoxIcon.Warning) == DialogResult.Yes)
             {
                 string transportNo = gv.Rows[e.RowIndex].Cells[IDX_TRANSPORT_NO].Value.ToString();
                 string productCode = gv.Rows[e.RowIndex].Cells[IDX_PRODUCT_CODE].Value.ToString();
                 int    seq         = gv.Rows[e.RowIndex].Cells[IDX_SEQ].Value.ToString().ToInt16();
                 string stockNo     = gv.Rows[e.RowIndex].Cells[IDX_STOCK_NO].Value.ToString();
                 int    bomCode     = gv.Rows[e.RowIndex].Cells[IDX_BOM_CODE].Value.ToString().ToInt16();
                 using (var db = new SlaughterhouseEntities())
                 {
                     using (DbContextTransaction transaction = db.Database.BeginTransaction())
                     {
                         try
                         {
                             //update barcode
                             var barcode = db.barcodes.Find(barcodeNo);
                             if (barcode == null)
                             {
                                 throw new Exception("ไม่พบข้อมูลบาร์โค็ดนี้!");
                             }
                             if (barcode.active)
                             {
                                 throw new Exception("ข้อมูลบาร์โค็ด ทำรายการแล้ว!");
                             }
                             barcode.active          = true;
                             db.Entry(barcode).State = EntityState.Modified;
                             //update transport item
                             //var transportItem = db.transport_item.Where(p => p.transport_no == transportNo
                             //                    && p.product_code == productCode
                             //                    && p.seq == seq).SingleOrDefault();
                             var transportItem = db.transport_item.Find(transportNo, productCode, seq);
                             db.transport_item.Remove(transportItem);
                             //update order item
                             var orderItem = db.orders_item.Where(p => p.order_no == OrderNo &&
                                                                  p.product_code == productCode &&
                                                                  p.bom_code == bomCode).SingleOrDefault();
                             orderItem.unload_qty     -= barcode.qty;
                             orderItem.unload_wgh     -= barcode.wgh;
                             orderItem.modified_at     = null;
                             orderItem.modified_by     = null;
                             db.Entry(orderItem).State = EntityState.Modified;
                             //remove stock
                             //var stock = db.stocks.Where(p => p.stock_no == stockNo
                             //     && p.stock_date == productionDate
                             //     && p.stock_item == seq
                             //     && p.product_code == productCode).FirstOrDefault();
                             var stock = db.stocks.Find(productionDate, stockNo, seq, productCode);
                             db.stocks.Remove(stock);
                             db.SaveChanges();
                             transaction.Commit();
                             DisplayNotification("Success", $"ยกเลิก บาร์โค็ด {barcodeNo} \rเรียบร้อยแล้ว.", Color.Green);
                             LoadData();
                         }
                         catch (Exception)
                         {
                             transaction.Rollback();
                             throw;
                         }
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         DisplayNotification("Error", ex.Message, Color.Red);
     }
 }
Exemplo n.º 18
0
        private bool SaveData()
        {
            try
            {
                decimal receive_wgh = lblWeight.Text.ToDecimal();
                string  create_by   = Helper.GetLocalIPAddress();
                using (var db = new SlaughterhouseEntities())
                {
                    //update receive
                    var receive = db.receives.Where(p => p.receive_no.Equals(lblReceiveNo.Text)).SingleOrDefault();
                    int seq     = receive.receive_item.Where(p => p.product_code.Equals(product.product_code)).Count();

                    barcode_no = db.barcodes.Max(p => p.barcode_no) + 1;
                    //int seq = db.receive_item.Where(p => p.receive_no == receive.receive_no).Count();

                    seq += 1;
                    var item = new receive_item
                    {
                        receive_no   = receive.receive_no,
                        product_code = product.product_code,
                        seq          = seq,
                        sex_flag     = "",
                        lot_no       = receive.lot_no,
                        receive_qty  = 1,
                        receive_wgh  = receive_wgh,
                        chill_qty    = 0,
                        chill_wgh    = 0,
                        barcode_no   = barcode_no,
                        create_by    = create_by
                    };


                    string stock_no = db.stock_item_running.Where(p => p.doc_no.Equals(receive.receive_no)).Select(p => p.stock_no).SingleOrDefault();
                    using (DbContextTransaction transaction = db.Database.BeginTransaction())
                    {
                        try
                        {
                            //insert barcode
                            var barcode = new barcode
                            {
                                barcode_no      = barcode_no,
                                product_code    = item.product_code,
                                production_date = DateTime.Today,
                                lot_no          = receive.lot_no,
                                qty             = 1,
                                wgh             = receive_wgh,
                                create_by       = create_by
                            };

                            db.barcodes.Add(barcode);
                            //insert receive_item
                            db.receive_item.Add(item);
                            //insert stock
                            var stock = new stock
                            {
                                stock_date        = DateTime.Today,
                                stock_no          = stock_no,
                                stock_item        = item.seq,
                                product_code      = barcode.product_code,
                                stock_qty         = barcode.qty,
                                stock_wgh         = barcode.wgh,
                                ref_document_no   = receive.receive_no,
                                ref_document_type = Constants.REV,
                                lot_no            = barcode.lot_no,
                                location_code     = _locationCode,
                                barcode_no        = barcode_no,
                                transaction_type  = 1,
                                create_by         = create_by
                            };

                            db.stocks.Add(stock);
                            db.SaveChanges();
                            transaction.Commit();
                            PrintBarcode();
                            return(true);
                        }
                        catch (Exception)
                        {
                            transaction.Rollback();
                            throw;
                        }
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 19
0
 private void Gv_CellContentClick(object sender, DataGridViewCellEventArgs e)
 {
     try
     {
         DataGridView senderGrid = (DataGridView)sender;
         if (senderGrid.Columns[e.ColumnIndex] is DataGridViewButtonColumn && e.RowIndex >= 0)
         {
             string barcode_no = gv.Rows[e.RowIndex].Cells[0].Value.ToString();
             if (senderGrid.Columns[e.ColumnIndex].Name == "btnDelete")
             {
                 if (MessageBox.Show($"ต้องการลบข้อมูล บาร์โค็ด {barcode_no} Yes/No?", "ยืนยัน", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                 {
                     return;
                 }
                 //delete barcode
                 using (var db = new SlaughterhouseEntities())
                 {
                     var barcode = db.barcodes.Find(barcode_no.ToLong());
                     if (barcode.location_code != null)
                     {
                         throw new Exception("ไม่สามารถ ลบข้อมูลบาร์โค็ด\r เนื่องจากรับเข้าคลังแล้ว.");
                     }
                     using (DbContextTransaction transaction = db.Database.BeginTransaction())
                     {
                         try
                         {
                             if (IsMainProduct)
                             {
                                 var mainProduct = db.basic_yield_info.Where(p => p.barcode_no == barcode.barcode_no).SingleOrDefault();
                                 db.basic_yield_info.Remove(mainProduct);
                             }
                             else
                             {
                                 var specialProduct = db.special_yield_info.Where(p => p.barcode_no == barcode.barcode_no).SingleOrDefault();
                                 db.special_yield_info.Remove(specialProduct);
                             }
                             db.barcodes.Remove(barcode);
                             db.SaveChanges();
                             transaction.Commit();
                             DisplayNotification("Success", $"ลบข้อมูลบาร์โค็ด {barcode_no} เรียบร้อยแล้ว", Color.Green);
                             LoadData();
                         }
                         catch (Exception)
                         {
                             transaction.Rollback();
                             throw;
                         }
                     }
                 }
             }
             else
             {
                 doc.Load(Constants.REPORT_FILE);
                 DataTable dt = Helper.GetBarcode(barcode_no.ToLong());
                 doc.SetDataSource(dt);
                 doc.PrintToPrinter(1, true, 0, 0);
             }
         }
     }
     catch (Exception ex)
     {
         DisplayNotification("Error", ex.Message, Color.Red);
     }
 }
Exemplo n.º 20
0
 private void SaveData()
 {
     try
     {
         var    receiveWgh     = lblWeight.Text.ToDecimal();
         string createBy       = Helper.GetLocalIPAddress();
         var    productionDate = plant.production_date;
         using (var db = new SlaughterhouseEntities())
         {
             var receive = db.receives.Where(p => p.receive_no.Equals(lblReceiveNo.Text)).SingleOrDefault();
             //var carcassQty = receive.carcass_qty == 0 ? receive.carcass_qty : (receive.carcass_qty / RECEIVE_QTY);
             if (receive.farm_qty - receive.carcass_qty == 0)
             {
                 throw new Exception("จำนวนรับครบแล้ว\rไม่สามารถรับเพิ่มได้!");
             }
             int seq = receive.receive_item.Where(p => p.product_code.Equals(product.product_code)).Count();
             ////หารับหมูเป็นมาตัดออกจาก stock
             //var swine = receive.receive_item.Where(p => p.product_code == "P001"
             //    && p.seq == seq).Select(p => new { p.receive_qty, p.receive_wgh }).SingleOrDefault();
             seq += 1;
             //string stock_no = db.stock_item_running.Where(p => p.doc_no.Equals(receive.receive_no)).Select(p => p.stock_no).SingleOrDefault();
             string stock_no      = "";
             var    stockDocument = (from p in db.document_generate where p.document_type == Constants.STK select p).SingleOrDefault();
             //check stock_item_running
             var stockItemRunning = db.stock_item_running.Where(p => p.doc_no.Equals(receive.receive_no)).SingleOrDefault();
             if (stockItemRunning == null)
             {
                 //get new stock doc no
                 stock_no = Constants.STK + stockDocument.running.ToString().PadLeft(10 - Constants.STK.Length, '0');
             }
             else
             {
                 stock_no = stockItemRunning.stock_no;
             }
             using (DbContextTransaction transaction = db.Database.BeginTransaction())
             {
                 try
                 {
                     var item = new receive_item
                     {
                         receive_no   = receive.receive_no,
                         product_code = product.product_code,
                         seq          = seq,
                         lot_no       = receive.lot_no,
                         sex_flag     = sexFlag,
                         receive_qty  = 1,
                         receive_wgh  = receiveWgh,
                         chill_qty    = 0,
                         chill_wgh    = 0,
                         create_by    = createBy
                     };
                     db.receive_item.Add(item);
                     //var stocks = new List<stock>();
                     //stocks.Add(new stock
                     //{
                     //    stock_date = productionDate,
                     //    stock_no = stock_no,
                     //    stock_item = item.seq,
                     //    product_code = item.product_code,
                     //    stock_qty = item.receive_qty,
                     //    stock_wgh = item.receive_wgh,
                     //    ref_document_no = receive.receive_no,
                     //    ref_document_type = Constants.REV,
                     //    lot_no = receive.lot_no,
                     //    location_code = 1,
                     //    barcode_no = 0,
                     //    transaction_type = 2,
                     //    create_by = item.create_by
                     //});
                     //insert stock
                     var stock = new stock
                     {
                         stock_date        = productionDate,
                         stock_no          = stock_no,
                         stock_item        = item.seq,
                         product_code      = item.product_code,
                         stock_qty         = 1,
                         stock_wgh         = receiveWgh,
                         ref_document_no   = receive.receive_no,
                         ref_document_type = Constants.REV,
                         lot_no            = receive.lot_no,
                         location_code     = 2, //ห้องเย็นเก็บหมุซีก
                         barcode_no        = 0,
                         transaction_type  = 1,
                         create_by         = createBy
                     };
                     db.stocks.Add(stock);
                     receive.carcass_qty += 1;
                     receive.carcass_wgh += receiveWgh;
                     if (stockItemRunning == null)
                     {
                         //insert stock_item_running
                         var newStockItem = new stock_item_running
                         {
                             doc_no     = receive.receive_no,
                             stock_no   = stock_no,
                             stock_item = 1,
                             create_by  = createBy
                         };
                         db.stock_item_running.Add(newStockItem);
                         //update document_generate
                         stockDocument.running        += 1;
                         db.Entry(stockDocument).State = System.Data.Entity.EntityState.Modified;
                     }
                     else
                     {
                         //update stock_item_running
                         stockItemRunning.stock_item     += 1;
                         db.Entry(stockItemRunning).State = System.Data.Entity.EntityState.Modified;
                     }
                     db.SaveChanges();
                     transaction.Commit();
                 }
                 catch (Exception)
                 {
                     transaction.Rollback();
                     throw;
                 }
             }
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
Exemplo n.º 21
0
        private bool SaveData()
        {
            try
            {
                string  createBy    = Helper.GetLocalIPAddress();
                string  stockNo     = "";
                int     stockItem   = 1;
                decimal scaleWeight = lblWeight.Text.ToDecimal();
                using (var db = new SlaughterhouseEntities())
                {
                    long barcodeNo = txtBarcodeNo.Text.ToLong();
                    var  barcode   = db.barcodes.Find(barcodeNo);
                    if (barcode == null)
                    {
                        //throw new Exception("ข้อมูลบาร์โค็ด จ่ายออกแล้ว!");
                        throw new Exception("ไม่พบข้อมูลบาร์โค็ดนี้ \rหรือจ่ายออกแล้ว!");
                    }
                    //if (barcode.active == false)
                    //{
                    //    throw new Exception("ข้อมูลบาร์โค็ด จ่ายออกแล้ว!");
                    //}
                    //barcodeIssuedList.Add(barcode);
                    using (DbContextTransaction transaction = db.Database.BeginTransaction())
                    {
                        try
                        {
                            //var issDoc = db.document_generate.Find(Constants.ISS);// (from p in db.document_generate where p.document_type == Constants.ISS select p).SingleOrDefault();
                            //var refDocumentNo = Constants.ISS + issDoc.running.ToString().PadLeft(10 - Constants.ISS.Length, '0');
                            //var refDocumentType = Constants.ISS;
                            var rmIssuedInfo = new rm_issued_info
                            {
                                production_date = productionDate,
                                product_code    = barcode.product_code,
                                lot_no          = barcode.lot_no,
                                quantity        = barcode.qty,
                                weight          = scaleWeight,
                                barcode_no      = barcode.barcode_no,
                                create_at       = DateTime.Now,
                                create_by       = createBy
                            };
                            db.rm_issued_info.Add(rmIssuedInfo);
                            //var issuedInfo = db.issued_info.Find(productionDate, barcode.product_code, barcode.lot_no);
                            //if (issuedInfo == null)
                            //{
                            //    var newIssued = new issued_info
                            //    {
                            //        issued_date = productionDate,
                            //        product_code = barcode.product_code,
                            //        lot_no = barcode.lot_no,
                            //        issued_qty = barcode.qty,
                            //        issued_wgh = scaleWeight,
                            //        usage_qty = 0,
                            //        usage_wgh = 0,
                            //        active = true,
                            //        create_at = DateTime.Now,
                            //        create_by = createBy
                            //    };
                            //    db.issued_info.Add(newIssued);
                            //}
                            //else
                            //{
                            //    issuedInfo.issued_qty += barcode.qty;
                            //    issuedInfo.issued_wgh += scaleWeight;
                            //    issuedInfo.modified_at = DateTime.Now;
                            //    issuedInfo.modified_by = createBy;
                            //    db.Entry(issuedInfo).State = System.Data.Entity.EntityState.Modified;
                            //}
                            //var stockGenerate = db.document_generate.Find(Constants.STK);
                            ////check stock_item_running
                            //var stockItemRunning = db.stock_item_running.Where(p => p.doc_no.Equals(refDocumentNo)).SingleOrDefault();
                            //if (stockItemRunning == null)
                            //{
                            //    //get new stock doc no
                            //    stockNo = Constants.STK + stockGenerate.running.ToString().PadLeft(10 - Constants.STK.Length, '0');
                            //    stockItem = 1;
                            //}
                            //else
                            //{
                            //    stockNo = stockItemRunning.stock_no;
                            //    stockItem = stockItemRunning.stock_item + 1;
                            //}
                            //insert stock

                            stockNo = Helper.GetDocGenerator(Constants.STK);

                            var stock = new stock
                            {
                                stock_date   = productionDate,
                                stock_no     = stockNo,
                                stock_item   = stockItem,
                                product_code = barcode.product_code,
                                stock_qty    = barcode.qty,
                                stock_wgh    = scaleWeight,
                                //ref_document_no = refDocumentNo,
                                //ref_document_type = refDocumentType,
                                lot_no           = barcode.lot_no,
                                location_code    = 0,
                                barcode_no       = barcode.barcode_no,
                                transaction_type = 2,
                                create_by        = createBy
                            };
                            db.stocks.Add(stock);
                            //if (stockItem == 1)
                            //{
                            //    stockGenerate.running += 1;
                            //    db.Entry(stockGenerate).State = System.Data.Entity.EntityState.Modified;
                            //}
                            //set barcode
                            db.barcodes.Remove(barcode);
                            //barcode.active = false;
                            //db.Entry(barcode).State = System.Data.Entity.EntityState.Modified;
                            db.SaveChanges();
                            transaction.Commit();
                            return(true);
                        }
                        catch (Exception)
                        {
                            transaction.Rollback();
                            throw;
                        }
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }