示例#1
0
        public static List <Saf21> Search(FilterOption filterOption)
        {
            List <Saf21> saf21List = new List <Saf21>();



            using (var conn = new SqlConnection {
                ConnectionString = MyConnStringList.AzureGoodeasy
            })
                using (var sqlCmd = conn.CreateCommand())
                {
                    conn.Open();
                    var idFilter                  = "";
                    var idListFilter              = "";
                    var saf2106OrderDateFilter    = "";
                    var saf21a02PcodeFilter       = "";
                    var saf21a03RelativeNoFilter  = "";
                    var inf2906RefFilter          = "";
                    var saf2108CustomerCodeFilter = "";
                    var saf2101DocnoFilter        = "";
                    var saf2101DocnoDateFilter    = "";
                    var saf2101DocnoOrdernoFilter = "";
                    var saf2101BcodeFilter        = "";
                    var adddateFilter             = "";
                    var QtyFilter                 = "";
                    if (filterOption != null)
                    {
                        if (!String.IsNullOrEmpty(filterOption.keyword))
                        {
                            List <int> idList = new List <int>();
                            sqlCmd.CommandText = "Saf21_FindStringInTable";
                            sqlCmd.CommandType = CommandType.StoredProcedure;

                            sqlCmd.Parameters.AddWithValue("@stringToFind", filterOption.keyword);

                            using (var sqlReader = sqlCmd.ExecuteReader())
                            {
                                if (sqlReader.HasRows)
                                {
                                    while (sqlReader.Read())
                                    {
                                        idList.Add(sqlReader.GetInt32(0));
                                    }
                                }
                            }
                            sqlCmd.CommandType = CommandType.Text;
                            sqlCmd.Parameters.Clear();
                        }
                        if (filterOption.saf2106_order_date_start != null)
                        {
                            saf2106OrderDateFilter = String.Format(@" AND (
                            saf21.[saf2106_order_date] >= @saf2106OrderDateStart 
                            AND saf21.[saf2106_order_date] <= @saf2106_order_date_end 
                            )");
                            sqlCmd.Parameters.AddWithValue("@saf2106OrderDateStart", filterOption.saf2106_order_date_start);
                            sqlCmd.Parameters.AddWithValue("@saf2106_order_date_end", filterOption.saf2106_order_date_end == null ?
                                                           filterOption.saf2106_order_date_start : filterOption.saf2106_order_date_end);
                        }
                        if (!String.IsNullOrEmpty(filterOption.saf21a02_pcode_start))
                        {
                            saf21a02PcodeFilter = String.Format(@" AND (
                            saf21a.[saf21a02_pcode] >= @saf21a02PCodeStart 
                            AND saf21a.[saf21a02_pcode] <= @saf21a02PCodeEnd 
                            )");
                            sqlCmd.Parameters.AddWithValue("@saf21a02PCodeStart", filterOption.saf21a02_pcode_start);
                            sqlCmd.Parameters.AddWithValue("@saf21a02PCodeEnd",
                                                           String.IsNullOrEmpty(filterOption.saf21a02_pcode_end)
                                                           ? filterOption.saf21a02_pcode_start
                                                           : filterOption.saf21a02_pcode_end);
                        }
                        if (filterOption.saf21a03_relative_no_start != null)
                        {
                            saf21a03RelativeNoFilter = String.Format(@" AND (
                            saf21a.[saf21a03_relative_no] >= @saf21a03RelativeNoStart 
                            AND saf21a.[saf21a03_relative_no] <= @saf21a03RelativeNoEnd 
                            )");
                            sqlCmd.Parameters.AddWithValue("@saf21a03RelativeNoStart", filterOption.saf21a03_relative_no_start);
                            sqlCmd.Parameters.AddWithValue("@saf21a03RelativeNoEnd",
                                                           String.IsNullOrEmpty(filterOption.saf21a03_relative_no_end)
                                                           ? filterOption.saf21a02_pcode_start
                                                           : filterOption.saf21a03_relative_no_end);
                        }
                        if (!String.IsNullOrEmpty(filterOption.saf2108_customer_code_start))
                        {
                            saf2108CustomerCodeFilter = String.Format(@" AND (
                            saf21.[saf2108_customer_code] >= @saf2108CustomerCodeStart 
                            AND saf21.[saf2108_customer_code] <= @saf2108CustomerCodeEnd 
                            )");
                            sqlCmd.Parameters.AddWithValue("@saf2108CustomerCodeStart", filterOption.saf2108_customer_code_start);
                            sqlCmd.Parameters.AddWithValue("@saf2108CustomerCodeEnd",
                                                           String.IsNullOrEmpty(filterOption.saf2108_customer_code_end)
                                                           ? filterOption.saf2108_customer_code_start
                                                           : filterOption.saf2108_customer_code_end);
                        }
                        if (!String.IsNullOrEmpty(filterOption.saf2101_docno_start))
                        {
                            saf2101DocnoFilter = String.Format(@" AND (
                            saf21.[saf2101_docno] >= @saf2101DocnoTypeStart 
                            AND saf21.[saf2101_docno] <= @saf2101DocnoTypeEnd
                            )");
                            sqlCmd.Parameters.AddWithValue("@saf2101DocnoTypeStart", filterOption.saf2101_docno_start);
                            sqlCmd.Parameters.AddWithValue("@saf2101DocnoTypeEnd",
                                                           String.IsNullOrEmpty(filterOption.saf2101_docno_end)
                                                           ? filterOption.saf2101_docno_start
                                                           : filterOption.saf2101_docno_end);
                        }

                        if (!String.IsNullOrEmpty(filterOption.saf2101_bcode_start))
                        {
                            saf2101BcodeFilter = String.Format(@" AND (
                            saf21.[saf2101_bcode] >= @saf2101BcodeStart 
                            AND saf21.[saf2101_bcode] <= @saf2101BcodeEnd 
                            )");
                            sqlCmd.Parameters.AddWithValue("@saf2101BcodeStart", filterOption.saf2101_bcode_start);
                            sqlCmd.Parameters.AddWithValue("@saf2101BcodeEnd",
                                                           String.IsNullOrEmpty(filterOption.saf2101_bcode_end)
                                                           ? filterOption.saf2101_bcode_start
                                                           : filterOption.saf2101_bcode_end);
                        }
                        if (filterOption.adddate_start != null)
                        {
                            adddateFilter = String.Format(@" AND (
                            saf21.[adddate] >= @AddDateStart
                            AND saf21.[adddate] <= @AddDateEnd 
                            )");
                            sqlCmd.Parameters.AddWithValue("@AddDateStart", filterOption.adddate_start);
                            sqlCmd.Parameters.AddWithValue("@AddDateEnd",
                                                           filterOption.adddate_end == null
                                                           ? filterOption.adddate_start
                                                           : filterOption.adddate_end);
                        }
                        if (filterOption.Qty > 0)
                        {
                            QtyFilter = String.Format(@" AND (
                            saf21aa.[qty] >= @Qty
                            )");
                            sqlCmd.Parameters.AddWithValue("@Qty", filterOption.Qty);
                        }
                    }

                    sqlCmd.CommandText = String.Format(@"
SELECT saf21.id,
			   saf21.[saf2133_seq2]
              ,saf21.[saf2101_bcode]
			  ,saf21.[saf2101_docno]
              ,saf21.[saf2147_recid]
              ,saf21.[saf2101_docno_type],
			   saf21.[saf2101_docno_date],
			   saf21.[saf2106_order_date],
               saf21.[saf2101_docno_orderno]
              ,saf21.[saf2139_total_price]
              ,saf21.[saf2108_customer_code]
              ,saf21.[saf2128_currency]
              ,saf21.[saf2129_exchange_rate]
              ,cmf01.[cmf0103_bname],
              saf21.[saf2114_payment]
              ,saf21.[saf2110_del_date]
              ,saf21.adduser
              ,saf21.adddate
              ,saf21.[saf2147_recid]
			  ,cmf01a.cmf01a05_fname
              ,cmf01a.cmf01a17_telo1
              ,cmf01a.cmf01a23_cellphone
			  ,saf21aa.qty
              ,saf21.remark

          FROM [dbo].[saf21] 
        LEFT JOIN dbo.cmf01
            ON cmf01.cmf0102_cuscode = saf21.saf2108_customer_code
		LEFT JOIN dbo.cmf01a
			on cmf01a.cmf01a03_recid = saf21.saf2147_recid
		left join (select max(saf21a.saf21a16_total_qty) as qty, saf21a.saf21a01_docno from dbo.saf21a  GROUP  BY  saf21a.saf21a01_docno) as saf21aa
			on saf21aa.saf21a01_docno = saf21.saf2101_docno
        WHERE 1=1
        {0}
        {1}
        {2}
        {3}
        {4}
        {5}
        {6}
        {7}
        {8}
        {9}
        ", idFilter,
                                                       saf2106OrderDateFilter,
                                                       saf21a02PcodeFilter,
                                                       saf21a03RelativeNoFilter,
                                                       inf2906RefFilter,
                                                       saf2108CustomerCodeFilter,
                                                       saf2101DocnoFilter,
                                                       saf2101BcodeFilter,
                                                       adddateFilter,
                                                       QtyFilter,
                                                       idListFilter
                                                       );

                    using (var sqlReader = sqlCmd.ExecuteReader())
                    {
                        if (sqlReader.HasRows)
                        {
                            while (sqlReader.Read())
                            {
                                Saf21 saf21 = new Saf21();
                                saf21.id                    = Convert.ToInt32(sqlReader["id"]);
                                saf21.saf2133_seq2          = Convert.ToInt32(sqlReader["saf2133_seq2"]);
                                saf21.saf2101_docno         = Convert.ToString(sqlReader["saf2101_docno"]);
                                saf21.saf2101_docno_date    = Convert.ToDateTime(sqlReader["saf2101_docno_date"]);
                                saf21.saf2101_bcode         = Convert.ToString(sqlReader["saf2101_bcode"]);
                                saf21.saf2101_docno_orderno = Convert.ToDecimal((sqlReader["saf2101_docno_orderno"]));
                                saf21.saf2101_docno_type    = Convert.ToString(sqlReader["saf2101_docno_type"]);
                                saf21.saf2106_order_date    = Convert.ToDateTime(sqlReader["saf2106_order_date"]);
                                saf21.saf2139_total_price   = Convert.ToInt32(sqlReader["saf2139_total_price"]);
                                saf21.saf2108_customer_code = Convert.ToString(sqlReader["saf2108_customer_code"]);
                                saf21.cmf0103_bname         = Convert.ToString(sqlReader["cmf0103_bname"]);
                                saf21.taf1002_firstname     = Convert.ToString(sqlReader["cmf01a05_fname"]);
                                saf21.taf1019_tel1          = Convert.IsDBNull(sqlReader["cmf01a17_telo1"]) ? "" : Convert.ToString(sqlReader["cmf01a17_telo1"]);
                                saf21.saf2147_recid         = Convert.ToString(sqlReader["saf2147_recid"]);
                                saf21.saf2114_payment       = Convert.ToString(sqlReader["saf2114_payment"]);
                                saf21.taf1031_cellphone     = Convert.IsDBNull(sqlReader["cmf01a23_cellphone"]) ? "" : Convert.ToString(sqlReader["cmf01a23_cellphone"]);
                                saf21.remark                = Convert.ToString(sqlReader["remark"]);
                                saf21.saf2128_currency      = Convert.ToString(sqlReader["saf2128_currency"]);
                                saf21.adduser               = Convert.ToString(sqlReader["adduser"]);
                                saf21.saf2129_exchange_rate = Convert.ToDouble(sqlReader["saf2129_exchange_rate"]);
                                saf21.adddate               = Convert.ToDateTime(sqlReader["adddate"]);
                                saf21.saf2110_del_date      = Convert.ToDateTime(sqlReader["saf2110_del_date"]);



                                saf21List.Add(saf21);
                            }
                        }
                    }
                }
            return(saf21List);
        }
示例#2
0
        public static Saf21 AddItem(Saf21 saf21, bool edit)
        {
            if (edit)
            {
                if (saf21 == null)
                {
                    throw new ArgumentNullException("saf21");
                }
                using (var conn = new SqlConnection {
                    ConnectionString = MyConnStringList.AzureGoodeasy
                })
                    using (var sqlCmd = conn.CreateCommand())
                    {
                        conn.Open();
                        sqlCmd.CommandText = @"UPDATE [dbo].[saf21]
                       SET 
                          [saf2108_customer_code] = @saf2108_customer_code
                          ,[saf2110_del_date] = @saf2110_del_date
                          ,[saf2114_payment] = @saf2114_payment
                          ,[saf2128_currency] = @saf2128_currency
                          ,[saf2129_exchange_rate] = @saf2129_exchange_rate
                          ,[saf2135_rec_customer_code] = @saf2135_rec_customer_code
                          ,[saf2139_total_price] = @saf2139_total_price
                          ,[saf2147_recid] = @saf2147_recid
                          ,[remark] = @remark
                          ,[moduser] = @moduser
                          ,[moddate] = getdate()
                     WHERE [saf2101_docno] = @saf2101_docno";
                        sqlCmd.Parameters.AddWithValue("@saf2108_customer_code", saf21.saf2108_customer_code);
                        sqlCmd.Parameters.AddWithValue("@saf2110_del_date", saf21.saf2110_del_date);
                        sqlCmd.Parameters.AddWithValue("@saf2114_payment", saf21.saf2114_payment);
                        sqlCmd.Parameters.AddWithValue("@saf2128_currency", saf21.saf2128_currency);
                        sqlCmd.Parameters.AddWithValue("@saf2129_exchange_rate", saf21.saf2129_exchange_rate);
                        sqlCmd.Parameters.AddWithValue("@saf2135_rec_customer_code", saf21.saf2108_customer_code);
                        sqlCmd.Parameters.AddWithValue("@saf2139_total_price", saf21.saf2139_total_price);
                        sqlCmd.Parameters.AddWithValue("@saf2147_recid", saf21.saf2147_recid);
                        sqlCmd.Parameters.AddWithValue("@remark", saf21.remark);
                        sqlCmd.Parameters.AddWithValue("@moduser", saf21.moduser);
                        //sqlCmd.Parameters.AddWithValue("@moddate", saf21.moddate);
                        sqlCmd.Parameters.AddWithValue("@saf2101_docno", saf21.saf2101_docno);
                        sqlCmd.ExecuteNonQuery();
                    }
                return(saf21);
            }
            else
            {
                if (saf21 == null)
                {
                    throw new ArgumentNullException("saf21");
                }

                var lastDocSeq = GetLastDocnoSeq(saf21.saf2101_docno_type, saf21.saf2101_docno_date);
                saf21.saf2101_docno_orderno = ++lastDocSeq;

                saf21.saf2101_docno = saf21.saf2101_bcode + saf21.saf2101_docno_type +
                                      saf21.saf2101_docno_date.ToString("yyyyMMdd") +
                                      saf21.saf2101_docno_orderno.ToString("0000");

                using (var conn = new SqlConnection {
                    ConnectionString = MyConnStringList.AzureGoodeasy
                })
                    using (var sqlCmd = conn.CreateCommand())
                    {
                        conn.Open();
                        sqlCmd.CommandText = @"
    INSERT INTO [dbo].[saf21]
           ([saf2101_docno]
           ,[status]
           ,[saf2101_bcode]
           ,[saf2101_docno_type]
           ,[saf2101_docno_date]
           ,[saf2101_docno_orderno]
           ,[saf2106_order_date]
           ,[saf2108_customer_code]
           ,[saf2109_salesid]
           ,[saf2110_del_date]
           ,[saf2114_payment]
           ,[saf2115_period]
           ,[saf2120_ls_po_no]
           ,[saf2121_last_del_date]
           ,[saf2122_agent]
           ,[saf2123_delivery_place_no]
           ,[saf2124_blandid]
           ,[saf2125_po_type]
           ,[saf2126_print_times]
           ,[saf2127_delivery_type]
           ,[saf2128_currency]
           ,[saf2129_exchange_rate]
           ,[saf2131_faxno]
           ,[saf2132_yyyymm]
           ,[saf2133_seq2]
           ,[saf2134_p_po_time]
           ,[saf2135_rec_customer_code]
           ,[saf2136_customer_order_no]
           ,[saf2139_total_price]
           ,[saf2140_bcode]
           ,[saf2140_docno_type]
           ,[saf2140_docno_date]
           ,[saf2140_docno_seq]
           ,[saf2142_delivery_place]
           ,[saf2144_bcode]
           ,[saf2145_open_id]
           ,[saf2145_docno_type]
           ,[saf2145_docno_date]
           ,[saf2145_docno_orderno]
           ,[saf2147_recid]
           ,[saf2148_magazine_no]
           ,[saf2153_delivery_id]
           ,[saf2156_take_no]
           ,[saf2159_way]
           ,[remark]
           ,[adduser]
           ,[adddate]
           ,[moduser]
           ,[moddate]
           ,[verifyuser]
           ,[verifydate])
     OUTPUT INSERTED.ID
     VALUES
           (@saf2101_docno
           ,''
           ,@saf2101_bcode
           ,@saf2101_docno_type
           ,@saf2101_docno_date
           ,@saf2101_docno_orderno
           ,@saf2106_order_date
           ,@saf2108_customer_code
           ,''
           ,@saf2110_del_date
           ,@saf2114_payment
           ,''
           ,''
           ,null
           ,''
           ,''
           ,''
           ,''
           ,''
           ,''
           ,@saf2128_currency
           ,@saf2129_exchange_rate
           ,''
           ,null
           ,0
           ,@saf2134_p_po_time
           ,@saf2108_customer_code
           ,''
           ,@saf2139_total_price
           ,''
           ,''
           ,null
           ,0
           ,''
           ,''
           ,''
           ,''
           ,null
           ,0
           ,@saf2147_recid
           ,''
           ,''
           ,''
           ,''
           ,@remark
           ,@adduser
           ,getdate()
           ,@adduser
           ,getdate()
           ,null
           ,null);";
                        sqlCmd.Parameters.AddWithValue("@saf2101_docno", saf21.saf2101_docno);
                        sqlCmd.Parameters.AddWithValue("@saf2101_bcode", saf21.saf2101_bcode);
                        sqlCmd.Parameters.AddWithValue("@saf2101_docno_type", saf21.saf2101_docno_type);
                        sqlCmd.Parameters.AddWithValue("@saf2101_docno_date", saf21.saf2101_docno_date);
                        sqlCmd.Parameters.AddWithValue("@saf2101_docno_orderno", saf21.saf2101_docno_orderno);
                        sqlCmd.Parameters.AddWithValue("@saf2106_order_date", saf21.saf2106_order_date);
                        sqlCmd.Parameters.AddWithValueSafe("@saf2108_customer_code", saf21.saf2108_customer_code);
                        sqlCmd.Parameters.AddWithValue("@saf2114_payment", saf21.saf2114_payment);
                        sqlCmd.Parameters.AddWithValue("@saf2128_currency", saf21.saf2128_currency);
                        sqlCmd.Parameters.AddWithValue("@saf2129_exchange_rate", saf21.saf2129_exchange_rate);
                        sqlCmd.Parameters.AddWithValue("@saf2139_total_price", saf21.saf2139_total_price);
                        sqlCmd.Parameters.AddWithValue("@saf2147_recid", saf21.saf2147_recid);
                        sqlCmd.Parameters.AddWithValue("@remark", saf21.remark == null ? "" : saf21.remark);
                        sqlCmd.Parameters.AddWithValueSafe("@saf2134_p_po_time", saf21.saf2134_p_po_time);
                        sqlCmd.Parameters.AddWithValueSafe("@saf2110_del_date", saf21.saf2110_del_date);
                        sqlCmd.Parameters.AddWithValueSafe("@adduser", saf21.adduser);
                        //sqlCmd.Parameters.AddWithValueSafe("@adddate", saf21.adddate);


                        /*sqlCmd.Parameters.AddWithValue("@inf2901_docno", inf29.inf2901_docno);
                         * sqlCmd.Parameters.AddWithValue("@inf2901_bcode", inf29.inf2901_bcode);
                         * sqlCmd.Parameters.AddWithValue("@inf2902_docno_type", inf29.inf2902_docno_type);
                         * sqlCmd.Parameters.AddWithValue("@inf2902_docno_date", inf29.inf2902_docno_date);
                         * sqlCmd.Parameters.AddWithValue("@inf2902_docno_seq", inf29.inf2902_docno_seq);
                         * sqlCmd.Parameters.AddWithValueSafe("@inf2903_customer_code", inf29.inf2903_customer_code);
                         * sqlCmd.Parameters.AddWithValueDatetimeSafe("@inf2904_pro_date", inf29.inf2904_pro_date);
                         * sqlCmd.Parameters.AddWithValueSafe("@inf2906_wherehouse", inf29.inf2906_wherehouse);
                         * sqlCmd.Parameters.AddWithValueSafe("@inf2906_ref_no_type", inf29.inf2906_ref_no_type);
                         * sqlCmd.Parameters.AddWithValueSafe("@inf2906_ref_no_date", inf29.inf2906_ref_no_date);
                         * sqlCmd.Parameters.AddWithValueSafe("@inf2906_ref_no_seq", inf29.inf2906_ref_no_seq);
                         * sqlCmd.Parameters.AddWithValueSafe("@inf2910_in_reason", inf29.inf2910_in_reason);
                         * sqlCmd.Parameters.AddWithValueSafe("@inf2911_sub_amt", inf29.Inf29aList.Sum(o => o.inf29a38_one_amt));
                         * sqlCmd.Parameters.AddWithValueSafe("@inf2914_inv_eff", inf29.inf2914_inv_eff);
                         * sqlCmd.Parameters.AddWithValueSafe("@inf2916_apr_empid", inf29.inf2916_apr_empid);
                         * sqlCmd.Parameters.AddWithValueSafe("@inf2952_project_no", inf29.inf2952_project_no);
                         * sqlCmd.Parameters.AddWithValue("@inf2928_currency", inf29.inf2928_currency);
                         * sqlCmd.Parameters.AddWithValue("@inf2929_exchange_rate", inf29.inf2929_exchange_rate);
                         * sqlCmd.Parameters.AddWithValueSafe("@remark", inf29.remark);
                         * sqlCmd.Parameters.AddWithValue("@adduser", inf29.adduser);
                         * sqlCmd.Parameters.AddWithValue("@adddate", inf29.adddate);
                         */
                        var id = (int)sqlCmd.ExecuteScalar();
                        saf21.id = id;
                    }

                return(saf21);
            }
        }
示例#3
0
        public static List <Saf21a> AddItem(Saf21 saf21, List <Saf21a> saf21aList, bool isEdit)
        {
            if (isEdit)
            {
                List <Saf21a> lsSaf21a       = Saf21a.GetList(saf21.saf2101_docno);
                List <Saf21a> needDeleteItem = new List <Saf21a>();
                foreach (Saf21a s in lsSaf21a)
                {
                    if (saf21aList.FindAll(x => x.id == s.id).Count == 0)
                    {
                        needDeleteItem.Add(s);
                    }
                }
                List <Saf21a> needAddItem    = saf21aList.Where(x => x.id == 0).ToList();
                List <Saf21a> needUpdateItem = saf21aList.Where(x => x.beenMod).ToList();
                foreach (var s in needUpdateItem)
                {
                    Saf21a.Update(s);
                }
                saf21.id = Saf21.getId(saf21.saf2101_docno);
                if (needAddItem.Count > 0)
                {
                    Saf21a.AddItem(saf21, needAddItem, false);
                }
                if (needDeleteItem.Count > 0)
                {
                    foreach (var s in needDeleteItem)
                    {
                        Saf21a.Delete(s.id.ToString(), "id");
                    }
                }
            }
            else
            {
                if (saf21aList == null || saf21aList.Count == 0)
                {
                    throw new ArgumentNullException("saf21aList");
                }

                using (var conn = new SqlConnection {
                    ConnectionString = MyConnStringList.AzureGoodeasy
                })
                    using (var sqlCmd = conn.CreateCommand())
                    {
                        conn.Open();
                        sqlCmd.CommandText = @"
    INSERT INTO [dbo].[saf21a]
           ([saf21a00_saf21id]
           ,[status]
           ,[saf21a01_docno]
           ,[saf21a02_seq]
           ,[saf21a02_pcode]
           ,[saf21a03_relative_no]
           ,[saf21a07_colorno]
           ,[saf21a11_unit_price]
           ,[saf21a12_tax_type]
           ,[saf21a13_tax]
           ,[saf21a16_total_qty]
           ,[saf21a17_add_qty]
           ,[saf21a18_adj_qty]
           ,[saf21a30_sug_price]
           ,[saf21a37_utax_price]
           ,[saf21a38_discount]
           ,[saf21a39_total_price]
           ,[saf21a41_product_name]
           ,[saf21a43_runit]
           ,[saf21a46_nrec_qty]
           ,[saf21a49_odds_amt]
           ,[saf21a50_one_amt]
           ,[saf21a51_gift_qty]
           ,[saf21a52_byself_qty]
           ,[saf21a54_graphy]
           ,[saf21a55_cost]
           ,[saf21a56_box_qty]
           ,[saf21a57_qty]
           ,[saf21a58_note]
           ,[saf21a59_halfway_qty]
           ,[saf21a60_flag1]
           ,[saf21a61_chng_price]
           ,[saf21a62_chg_sub]
           ,[saf21a63_chg_tax]
           ,[saf21a64_chg_sum]
           ,[remark]
           ,[adduser]
           ,[adddate]
           ,[moduser]
           ,[moddate])
OUTPUT INSERTED.ID
     VALUES
           (@saf21a00_saf21id
           ,''
           ,@saf21a01_docno
           ,@saf21a02_seq
           ,@saf21a02_pcode
           ,@saf21a03_relative_no
           ,''
           ,@saf21a11_unit_price
           ,@saf21a12_tax_type
           ,@saf21a13_tax
           ,@saf21a16_total_qty
           ,0
           ,0
           ,0
           ,@saf21a37_utax_price
           ,100
           ,@saf21a39_total_price
           ,@saf21a41_product_name
           ,@saf21a43_runit
           ,0
           ,0
           ,@saf21a50_one_amt
           ,0
           ,0
           ,''
           ,@saf21a55_cost
           ,@saf21a56_box_qty
           ,@saf21a57_qty
           ,''
           ,0
           ,''
           ,@saf21a61_chng_price
           ,@saf21a62_chg_sub
           ,@saf21a63_chg_tax
           ,@saf21a64_chg_sum
           ,@remark
           ,@adduser
           ,@adddate
           ,''
           ,null)";

                        foreach (var saf21a in saf21aList)
                        {
                            sqlCmd.Parameters.Clear();
                            sqlCmd.Parameters.AddWithValue("@saf21a00_saf21id", saf21.id);
                            sqlCmd.Parameters.AddWithValue("@saf21a01_docno", saf21.saf2101_docno);
                            sqlCmd.Parameters.AddWithValue("@saf21a02_seq", saf21a.saf21a02_seq);
                            sqlCmd.Parameters.AddWithValue("@saf21a02_pcode", saf21a.saf21a02_pcode);
                            sqlCmd.Parameters.AddWithValue("@saf21a03_relative_no", saf21a.saf21a03_relative_no);
                            sqlCmd.Parameters.AddWithValue("@saf21a11_unit_price", saf21a.saf21a11_unit_price);
                            sqlCmd.Parameters.AddWithValue("@saf21a12_tax_type", saf21a.saf21a12_tax_type);
                            sqlCmd.Parameters.AddWithValue("@saf21a13_tax", saf21a.saf21a13_tax);
                            sqlCmd.Parameters.AddWithValue("@saf21a16_total_qty", saf21a.saf21a16_total_qty);
                            sqlCmd.Parameters.AddWithValue("@saf21a37_utax_price", saf21a.saf21a37_utax_price);
                            sqlCmd.Parameters.AddWithValue("@saf21a39_total_price", saf21a.saf21a39_total_price);
                            sqlCmd.Parameters.AddWithValue("@saf21a41_product_name", saf21a.saf21a41_product_name);
                            sqlCmd.Parameters.AddWithValue("@saf21a43_runit", saf21a.saf21a43_runit);
                            sqlCmd.Parameters.AddWithValue("@saf21a50_one_amt", saf21a.saf21a50_one_amt);
                            sqlCmd.Parameters.AddWithValue("@saf21a55_cost", saf21a.saf21a55_cost);
                            sqlCmd.Parameters.AddWithValue("@saf21a56_box_qty", saf21a.saf21a56_box_qty);
                            sqlCmd.Parameters.AddWithValue("@saf21a57_qty", saf21a.saf21a57_qty);
                            sqlCmd.Parameters.AddWithValue("@saf21a61_chng_price", saf21a.saf21a61_chng_price);
                            sqlCmd.Parameters.AddWithValue("@saf21a62_chg_sub", saf21a.saf21a62_chg_sub);
                            sqlCmd.Parameters.AddWithValue("@saf21a63_chg_tax", saf21a.saf21a63_chg_tax);
                            sqlCmd.Parameters.AddWithValue("@saf21a64_chg_sum", saf21a.saf21a64_chg_sum);
                            sqlCmd.Parameters.AddWithValue("@remark", saf21a.remark == null ? "" : saf21a.remark);
                            sqlCmd.Parameters.AddWithValue("@adduser", saf21a.adduser);
                            sqlCmd.Parameters.AddWithValue("@adddate", saf21a.adddate);

                            /*sqlCmd.Parameters.AddWithValue("@inf29a00_inf29id", inf29.id);
                             * sqlCmd.Parameters.AddWithValue("@inf29a01_docno", inf29.inf2901_docno);
                             * sqlCmd.Parameters.AddWithValue("@inf29a02_seq", inf29a.inf29a02_seq);
                             * sqlCmd.Parameters.AddWithValueSafe("@inf29a04_sizeno", inf29a.inf29a04_sizeno);
                             * sqlCmd.Parameters.AddWithValueSafe("@inf29a05_pcode", inf29a.inf29a05_pcode);
                             * sqlCmd.Parameters.AddWithValueSafe("@inf29a05_shoes_code", inf29a.inf29a05_shoes_code);
                             * sqlCmd.Parameters.AddWithValueSafe("@inf29a09_retail_one", inf29a.inf29a09_retail_one);
                             * sqlCmd.Parameters.AddWithValueSafe("@inf29a09_oretail_one", inf29a.inf29a09_oretail_one);
                             * sqlCmd.Parameters.AddWithValueSafe("@inf29a10_ocost_one", inf29a.inf29a10_ocost_one);
                             * sqlCmd.Parameters.AddWithValueSafe("@inf29a10_cost_one", inf29a.inf29a10_cost_one);
                             * sqlCmd.Parameters.AddWithValueSafe("@inf29a11_dis_rate", inf29a.inf29a11_dis_rate);
                             * sqlCmd.Parameters.AddWithValueSafe("@inf29a12_sub_amt", inf29a.inf29a12_sub_amt);
                             * sqlCmd.Parameters.AddWithValueSafe("@inf29a13_sold_qty", inf29a.inf29a13_sold_qty);
                             * sqlCmd.Parameters.AddWithValueSafe("@inf29a14_trn_type", inf29a.inf29a14_trn_type);
                             * sqlCmd.Parameters.AddWithValueSafe("@inf29a17_runit", inf29a.inf29a17_runit);
                             * sqlCmd.Parameters.AddWithValueSafe("@inf29a26_box_qty", inf29a.inf29a26_box_qty);
                             * //                    sqlCmd.Parameters.AddWithValueSafe("@inf29a31_currency", inf29a.inf29a31_currency);
                             * //                    sqlCmd.Parameters.AddWithValueSafe("@inf29a32_exchange_rate", inf29a.inf29a32_exchange_rate);
                             * sqlCmd.Parameters.AddWithValueSafe("@inf29a33_product_name", inf29a.inf29a33_product_name);
                             * sqlCmd.Parameters.AddWithValueSafe("@inf29a36_odds_amt", inf29a.inf29a36_odds_amt);
                             * sqlCmd.Parameters.AddWithValueSafe("@inf29a38_one_amt", inf29a.inf29a38_one_amt);
                             * sqlCmd.Parameters.AddWithValueSafe("@inf29a39_price", inf29a.inf29a39_price);
                             * sqlCmd.Parameters.AddWithValueSafe("@inf29a40_tax", inf29a.inf29a40_tax);
                             * sqlCmd.Parameters.AddWithValueSafe("@inf29a41_pcat", inf29a.inf29a41_pcat);
                             * sqlCmd.Parameters.AddWithValue("@adduser", inf29a.adduser);
                             * sqlCmd.Parameters.AddWithValue("@adddate", inf29a.adddate);
                             */
                            int id = (int)sqlCmd.ExecuteScalar();
                            saf21a.id = id;
                        }
                    }
            }


            return(saf21aList);
        }