public static bool Insert(Order order)
        {
            MySqlTransaction tr = null;

            try
            {
                using (var conn = new MySqlConnection(Globals.CONN_STR))
                {
                    order.OrderNo = DocumentGenerate.GetDocumentRunning("SO");
                    conn.Open();
                    tr = conn.BeginTransaction();
                    var sql = @"INSERT INTO orders
								(order_no,
								order_date,
								customer_code,
								order_flag,
								comments,
								active,
								create_by)
								VALUES(@order_no,
								@order_date,
								@customer_code,
								@order_flag,
								@comments,
								@active,
								@create_by)"                                ;
                    var cmd = new MySqlCommand(sql, conn)
                    {
                        Transaction = tr
                    };
                    cmd.Parameters.AddWithValue("order_no", order.OrderNo);
                    cmd.Parameters.AddWithValue("order_date", order.RequestDate);
                    cmd.Parameters.AddWithValue("customer_code", order.Customer.CustomerCode);
                    cmd.Parameters.AddWithValue("order_flag", order.OrderFlag);
                    cmd.Parameters.AddWithValue("comments", order.Comments);
                    cmd.Parameters.AddWithValue("active", order.Active);
                    cmd.Parameters.AddWithValue("create_by", order.CreateBy);
                    cmd.ExecuteNonQuery();

                    sql = @"INSERT INTO orders_item
								(order_no,
								product_code,
								seq,
								order_qty,
								order_wgh,
								bom_code,
								order_set_qty,
								order_set_wgh,
								create_by)
								VALUES(
								@order_no,
								@product_code,
								@seq,
								@order_qty,
								@order_wgh,
								@bom_code,
								@order_set_qty,
								@order_set_wgh,
								@create_by)"                                ;

                    foreach (var item in order.OrderItems)
                    {
                        cmd = new MySqlCommand(sql, conn)
                        {
                            Transaction = tr
                        };
                        cmd.Parameters.AddWithValue("order_no", order.OrderNo);
                        cmd.Parameters.AddWithValue("product_code", item.Product.ProductCode);
                        cmd.Parameters.AddWithValue("seq", item.Seq);
                        cmd.Parameters.AddWithValue("order_qty", item.OrderQty);
                        cmd.Parameters.AddWithValue("order_wgh", item.OrderWgh);
                        cmd.Parameters.AddWithValue("bom_code", item.BomCode);
                        cmd.Parameters.AddWithValue("order_set_qty", item.OrderSetQty);
                        cmd.Parameters.AddWithValue("order_set_wgh", item.OrderSetWgh);
                        cmd.Parameters.AddWithValue("active", order.Active);
                        cmd.Parameters.AddWithValue("create_by", order.CreateBy);
                        cmd.ExecuteNonQuery();
                    }
                    tr.Commit();
                }
                return(true);
            }
            catch (Exception ex)
            {
                tr.Rollback();
                throw;
            }
        }
        public static string Insert(ProductSlip productSlip)
        {
            MySqlTransaction tr = null;

            try
            {
                using (var conn = new MySqlConnection(Globals.CONN_STR))
                {
                    productSlip.ProductSlipNo = DocumentGenerate.GetDocumentRunning("PDS");
                    conn.Open();
                    tr = conn.BeginTransaction();
                    var sql = @"INSERT INTO product_slip
									(product_slip_no,
									product_slip_date,
									ref_document_no,
									product_slip_flag,
									active,
									create_by)
								VALUES
									(@product_slip_no,
									 @product_slip_date,
									 @ref_document_no,
									 @product_slip_flag,
									 @active,
									 @create_by ) 
							   "                            ;
                    var cmd = new MySqlCommand(sql, conn)
                    {
                        Transaction = tr
                    };
                    cmd.Parameters.AddWithValue("product_slip_no", productSlip.ProductSlipNo);
                    cmd.Parameters.AddWithValue("product_slip_date", productSlip.ProductSlipDate.ToString("yyyy-MM-dd"));
                    cmd.Parameters.AddWithValue("ref_document_no", productSlip.RefDocumentNo);
                    cmd.Parameters.AddWithValue("product_slip_flag", productSlip.ProductSlipFlag);
                    cmd.Parameters.AddWithValue("active", productSlip.Active);
                    cmd.Parameters.AddWithValue("create_by", productSlip.CreateBy);
                    cmd.ExecuteNonQuery();

                    sql = @"INSERT INTO slaughterhouse.product_slip_item
							   (product_slip_no,
								product_code,
								location_code,
								lot_no,
								seq, qty, wgh,
								create_by )
							VALUES
							   (@product_slip_no ,
								@product_code ,
								@location_code ,
								@lot_no ,
								@seq , @qty , @wgh , 
								@create_by )
							"                            ;

                    foreach (var item in productSlip.ProductSlipItem)
                    {
                        cmd = new MySqlCommand(sql, conn)
                        {
                            Transaction = tr
                        };
                        cmd.Parameters.AddWithValue("product_slip_no", productSlip.ProductSlipNo);
                        cmd.Parameters.AddWithValue("product_code", item.Product.ProductCode);
                        cmd.Parameters.AddWithValue("location_code", item.Location.LocationCode);
                        cmd.Parameters.AddWithValue("lot_no", item.LotNo);
                        cmd.Parameters.AddWithValue("seq", item.Seq);
                        cmd.Parameters.AddWithValue("qty", item.Qty);
                        cmd.Parameters.AddWithValue("wgh", item.Wgh);
                        cmd.Parameters.AddWithValue("create_by", productSlip.CreateBy);
                        cmd.ExecuteNonQuery();
                    }
                    tr.Commit();
                }
                return(productSlip.ProductSlipNo);
            }
            catch (Exception)
            {
                tr.Rollback();
                throw;
            }
        }
        public static bool Insert(ProductionOrder po)
        {
            MySqlTransaction tr = null;

            try
            {
                using (var conn = new MySqlConnection(Globals.CONN_STR))
                {
                    po.PoNo = DocumentGenerate.GetDocumentRunning("PO");
                    conn.Open();
                    tr = conn.BeginTransaction();
                    var sql = @"INSERT INTO production_order 
                                (po_no,
                                po_date, 
                                po_flag,
                                active,  
                                comments,
                                create_by)
                                VALUES(
                                @po_no,
                                @po_date, 
                                @po_flag,
                                @active,
                                @comments,
                                @create_by)";
                    var cmd = new MySqlCommand(sql, conn)
                    {
                        Transaction = tr
                    };
                    cmd.Parameters.AddWithValue("po_no", po.PoNo);
                    cmd.Parameters.AddWithValue("po_date", po.PoDate.ToString("yyyy-MM-dd"));
                    cmd.Parameters.AddWithValue("po_flag", po.PoFlag);
                    cmd.Parameters.AddWithValue("active", po.Active);
                    cmd.Parameters.AddWithValue("comments", po.Comments);
                    cmd.Parameters.AddWithValue("create_by", po.CreateBy);
                    cmd.ExecuteNonQuery();

                    sql = @"INSERT INTO production_order_item
                                (po_no,
                                product_code,
                                seq,
                                po_qty,
                                po_wgh,
                                create_by)
                                VALUES(
                                @po_no,
                                @product_code,
                                @seq,
                                @po_qty,
                                @po_wgh,
                                @create_by)";

                    foreach (var item in po.ProductionOrderItem)
                    {
                        cmd = new MySqlCommand(sql, conn)
                        {
                            Transaction = tr
                        };
                        cmd.Parameters.AddWithValue("po_no", po.PoNo);
                        cmd.Parameters.AddWithValue("product_code", item.Product.ProductCode);
                        cmd.Parameters.AddWithValue("seq", item.Seq);
                        cmd.Parameters.AddWithValue("po_qty", item.PoQty);
                        cmd.Parameters.AddWithValue("po_wgh", item.PoWgh);
                        cmd.Parameters.AddWithValue("create_by", po.CreateBy);
                        cmd.ExecuteNonQuery();
                    }
                    tr.Commit();
                }
                return(true);
            }
            catch (Exception)
            {
                tr.Rollback();
                throw;
            }
        }