public ActionResult Create(prueba prueba)
        {
            barcode barcode = new barcode();

            //prueba.pru_codigo = GetCodigo(prueba.pru_registro, prueba.pru_examen);
            //prueba.pru_imagen = barcode.GenerarCodigo(prueba.pru_codigo);

            if (ModelState.IsValid && ExistPrueba(prueba.pru_examen, prueba.pru_registro))
            {
                db.prueba.Add(prueba);
                db.SaveChanges();
                set_codigo(prueba.pru_registro, prueba.pru_examen);
                if (prueba.examen.exa_tipo == "PLANTILLA")
                {
                    CreatePrueba(prueba.pru_examen, prueba.pru_registro);
                }
                else
                {
                    CreateObservacion(prueba.pru_registro, prueba.pru_examen);
                }
            }
            //ModelState.AddModelError("","La información ingresada no es la correcta");
            //return RedirectToAction("Index", new { id = prueba.pru_registro });

            var list_prueba = db.prueba.Include(p => p.registro).Include(p => p.examen).Where(p => p.pru_registro == prueba.pru_registro && p.examen.exa_estado == "ACTIVO");

            return(PartialView("Index", list_prueba.ToList()));
        }
Exemple #2
0
        private void Window_KeyDown_Document(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Tab)
            {
                e.Handled = true;
                return;
            }

            if (e.Key == Key.Enter)
            {
//----------------------------
                barcode dc_bc = new barcode(textBox00.Text, textBox01.Text, textBox02.Text, textBox03.Text, textBox04.Text, textBox05.Text, textBox06.Text, textBox07.Text);
                string  dc_rework_file;

                string dc_partnumber_file;

                dc_bc.field01 = dc_bc.field01.Replace("/", string.Empty);

                if (dc_bc.field01.Length > 3)
                {
                    if (dc_bc.field01.Substring(dc_bc.field01.Length - 3, 3).ToUpper() == "_XX")
                    {
                        dc_bc.field01 = dc_bc.field01.Substring(0, dc_bc.field01.Length - 3);
                    }
                }

                dc_rework_file = dc_getfilename(@"C:\Profiles\Alan\Programming\C# 6.0 and the .NET 4.6 Framework, Seventh Edition\DocumentControl\DocCtlRewks", dc_bc.field00 + "-" + dc_bc.field01);

                if (dc_rework_file != null)
                {
//-------------------                    Console.WriteLine("Found file {0}", dc_rework_file);
                    System.Diagnostics.Process.Start(dc_rework_file);
                }
                else
                {
                    dc_partnumber_file = dc_getfilename(@"C:\Profiles\Alan\Programming\C# 6.0 and the .NET 4.6 Framework, Seventh Edition\DocumentControl\DocCtlParts", dc_bc.field01);
                    if (dc_partnumber_file != null)
                    {
//-------------------                        Console.WriteLine("Found file {0}", dc_partnumber_file);
                        System.Diagnostics.Process.Start(dc_partnumber_file);
                    }

                    else
                    {
//-------------------                        Console.WriteLine("File not found");
                    }
                }
//----------------------------
                TraversalRequest tRequest      = new TraversalRequest(FocusNavigationDirection.Next);
                UIElement        keyboardFocus = Keyboard.FocusedElement as UIElement;

                if (keyboardFocus != null)
                {
                    keyboardFocus.MoveFocus(tRequest);
                }

                e.Handled = true;
            }
        }
 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;
     }
 }
        public static string genBarcode(string taxid, string suffix, string ref1, string ref2, float amount)
        {
            string  ramount = amount.ToString("0.00").Replace(".", "");
            barcode m       = new barcode(_Prefix, taxid, suffix, ref1, ref2, ramount);
            string  code    = m.Prefix + m.TaxID + m.Reference1 + m.Reference2 + m.Amount;

            return(code);
        }
Exemple #5
0
        public ActionResult Perfil(int reg_paciente, int con_perfil)
        {
            try
            {
                DateTime dd       = DateTime.Today;
                string   fecha    = dd.Date.ToString("d");
                var      consulta = db.registro.Where(r => r.reg_fecha == fecha && r.reg_paciente == reg_paciente && r.reg_estado == true);
                if (consulta.Any())
                {
                    return(RedirectToAction("Message", "Home", new { mensaje = "El registro ya existe, por favor seleccione la opción editar" }));
                }

                barcode        barcode      = new barcode();
                List <control> list_control = db.control.Where(c => c.con_perfil == con_perfil).ToList();

                registro registro = new registro();
                registro.reg_paciente      = reg_paciente;
                registro.reg_fecha         = fecha;
                registro.reg_orden         = GetOrden(fecha);
                registro.reg_estado        = true;
                registro.reg_laboratorista = get_user();
                if (registro.reg_laboratorista == 0)
                {
                    return(RedirectToAction("Message", "Home", new { mensaje = "Su perfil de usuario no permite realizar esta acción " }));
                }
                db.registro.Add(registro);
                db.SaveChanges();
                //return RedirectToAction("Message", "Home", new { mensaje = registro.reg_id.ToString()});
                int reg_id = registro.reg_id;
                foreach (var item in list_control)
                {
                    prueba prueba = new prueba();
                    prueba.pru_examen   = item.con_examen;
                    prueba.pru_registro = reg_id;
                    //prueba.pru_codigo = GetCodigo(reg_id, item.con_examen);
                    //prueba.pru_imagen = barcode.GenerarCodigo(prueba.pru_codigo);
                    set_codigo(prueba.pru_registro, prueba.pru_examen);
                    db.prueba.Add(prueba);
                    db.SaveChanges();
                }
                return(RedirectToAction("Index", "Prueba", new { id = registro.reg_id }));
            }
            catch (Exception ex) {
                return(RedirectToAction("Message", "Home", new { mensaje = ex.Message }));
            }

            //return View();
        }
Exemple #6
0
        private void set_codigo(int reg_id, int exa_id)
        {
            barcode barcode  = new barcode();
            examen  examen   = db.examen.Find(exa_id);
            var     consulta = db.codigo.Where(c => c.cod_registro == reg_id && c.cod_area == examen.exa_area);

            if (!consulta.Any())
            {
                codigo codigo = new codigo();
                codigo.cod_codigo   = GetCodigo(reg_id, examen.exa_area);
                codigo.cod_imagen   = barcode.GenerarCodigo(codigo.cod_codigo);
                codigo.cod_registro = reg_id;
                codigo.cod_area     = examen.exa_area;
                db.codigo.Add(codigo);
                db.SaveChanges();
            }
        }
        public ActionResult Barcode(session session)
        {
            string  text    = RandomSerialGenerator.generator().ToString();
            barcode barcode = new barcode();

            session.session_content         = text;
            barcode.barcode_content         = text;
            session.session_onset_time      = DateTime.Now;
            session.session_expiration_time = DateTime.Now.AddMinutes(5);
            lesson lesson = db.lesson.Where(x => x.lesson_id == session.lesson_id).FirstOrDefault();

            session.lesson = lesson;
            db.barcode.Add(barcode);
            session.barcode = barcode;
            db.session.Add(session);
            db.SaveChanges();
            return(RedirectToAction("index", "home", new { @text = text }));
        }
Exemple #8
0
        public string lookUpItem(string strBarCode)
        {
            string  strItemId = null;
            barcode bcode     = barcode.findBarcode(strBarCode);

            if (bcode != null)
            {
                inventoryItem itm = bcode.getItem();
                txtItemID.Text = itm.ItemID;
                strItemId      = itm.ItemID;
            }
            else
            {
                txtBarcodeData.ForeColor = Color.Red;
                btnSelectItem.Enabled    = true;
                MessageBox.Show("Barcode not found, please select an item for this barcode.");
            }
            return(strItemId);
        }
        static void Main(string[] args)
        {
            barcode dc_bc = new barcode();
            string  dc_rework_file;

            string dc_partnumber_file;

            dc_bc.field2 = dc_bc.field2.Replace("/", string.Empty);

            if (dc_bc.field2.Length > 3)
            {
                if (dc_bc.field2.Substring(dc_bc.field2.Length - 3, 3) == "_XX")
                {
                    dc_bc.field2 = dc_bc.field2.Substring(0, dc_bc.field2.Length - 3);
                }
            }

            dc_rework_file = dc_getfilename(@"C:\Profiles\Alan\Programming\C# 6.0 and the .NET 4.6 Framework, Seventh Edition\DocumentControl\DocCtlRewks", dc_bc.field1 + "-" + dc_bc.field2);

            if (dc_rework_file != null)
            {
                Console.WriteLine("Found file {0}", dc_rework_file);
                System.Diagnostics.Process.Start(dc_rework_file);
            }
            else
            {
                dc_partnumber_file = dc_getfilename(@"C:\Profiles\Alan\Programming\C# 6.0 and the .NET 4.6 Framework, Seventh Edition\DocumentControl\DocCtlParts", dc_bc.field2);
                if (dc_partnumber_file != null)
                {
                    Console.WriteLine("Found file {0}", dc_partnumber_file);
                    System.Diagnostics.Process.Start(dc_partnumber_file);
                }

                else
                {
                    Console.WriteLine("File not found");
                }
            }



            Console.ReadLine();
        }
        private void LoadBarcode()
        {
            try
            {
                using (var db = new SlaughterhouseEntities())
                {
                    lblProduct.Text       = "";
                    lblLotNo.Text         = "";
                    lblBarcodeWeight.Text = "";
                    lblMinWeight.Text     = "0.00";
                    lblMaxWeight.Text     = "0.00";

                    var barcodeNo = txtBarcodeNo.Text.ToLong();
                    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("รหัสบาร์โค็ดนี้ ยังไม่ได้รับเข้าคลัง!");
                    }
                    lblProduct.Text       = barcode.product.product_name;
                    lblLotNo.Text         = barcode.lot_no;
                    lblBarcodeWeight.Text = barcode.wgh.ToFormat2Decimal();
                    lblMinWeight.Text     = barcode.product.min_weight.ToString();
                    lblMaxWeight.Text     = barcode.product.max_weight.ToString();
                    btnStart.Enabled      = true;
                    btnStop.Enabled       = false;
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemple #11
0
        private void CreatePrueba(int exa_id, int reg_id)
        {
            examen        examen   = db.examen.Find(exa_id);
            int           are_id   = db.area.Where(a => a.are_nombre == examen.exa_nombre).First().are_id;
            List <examen> list_exa = new List <examen>();
            barcode       barcode  = new barcode();

            list_exa = db.examen.Where(e => e.exa_area == are_id).ToList();
            foreach (var item in list_exa)
            {
                prueba prueba = new prueba();
                prueba.pru_examen    = item.exa_id;
                prueba.pru_registro  = reg_id;
                prueba.pru_resultado = item.exa_inicial;
                //prueba.pru_codigo = GetCodigo(reg_id, item.exa_id);
                //prueba.pru_imagen = barcode.GenerarCodigo(prueba.pru_codigo);
                set_codigo(prueba.pru_registro, prueba.pru_examen);
                db.prueba.Add(prueba);
                //db.SaveChanges();
            }
            db.SaveChanges();
        }
        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;
            }
        }
Exemple #13
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;
     }
 }
Exemple #14
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;
            }
        }
        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;
            }
        }