C# DataTable change value [(SQLite) DataTable 已存在資料內容再手動修改]

C# DataTable change value [(SQLite) DataTable 已存在資料內容再手動修改]

C# DataTable change value [(SQLite) DataTable 已存在資料內容再手動修改]


資料來源: https://stackoverflow.com/questions/1666087/c-sharp-how-to-change-data-in-datatable


code

        public void AttributeLoad()//找出 套餐內的元素 資料
        {
            /*
            //找出 套餐內的元素 資料
            SELECT *,SID as attribute_sid FROM set_attribute_data WHERE set_sid='{0}' ORDER BY sort,SID; 
            */
            String SQL = $"SELECT *,SID as attribute_sid FROM set_attribute_data WHERE set_sid='{m_intSID}' ORDER BY sort,SID;";
            
            m_AttributeDataTable = SQLDataTableModel.GetDataTable(SQL);

        }

        public void ProductLoad()//找出 套餐有用到的產品資訊
        {
            /*
            //找出 套餐有用到的產品資訊
            SELECT DISTINCT a.set_sid,a.attribute_sid,a.category_sid,a.product_sid,a.main_flag,a.default_flag,b.* FROM product_set_relation a 

            JOIN product_data b ON b.SID=a.product_sid 

            WHERE b.stop_flag='N' AND b.del_flag='N' AND a.set_sid='{0}' ORDER BY a.attribute_sid,b.sort;
            */
            String SQL = "SELECT DISTINCT a.set_sid,a.attribute_sid,a.category_sid,a.product_sid,a.main_flag,a.default_flag,b.* FROM product_set_relation a "
                       + "JOIN product_data b ON b.SID = a.product_sid "
                       + $"WHERE b.stop_flag = 'N' AND b.del_flag = 'N' AND a.set_sid = '{m_intSID}' ORDER BY a.attribute_sid,b.sort";

            m_ProductDataTable = SQLDataTableModel.GetDataTable(SQL);

            //---
            //修改套餐內產品金額
            for(int i=0; i < m_AttributeDataTable.Rows.Count; i++)
            {
                int SID = Convert.ToInt32(m_AttributeDataTable.Rows[i][0].ToString());
                String main_price_type = m_AttributeDataTable.Rows[i][3].ToString();
                double main_price = Convert.ToDouble(m_AttributeDataTable.Rows[i][4].ToString());
                double main_max_price = Convert.ToDouble(m_AttributeDataTable.Rows[i][5].ToString());
                String sub_price_type = m_AttributeDataTable.Rows[i][6].ToString();
                double sub_price = Convert.ToDouble(m_AttributeDataTable.Rows[i][7].ToString());
                double sub_max_price = Convert.ToDouble(m_AttributeDataTable.Rows[i][8].ToString());
                for (int j=0;j< m_ProductDataTable.Rows.Count;j++)
                {
                    if(SID == Convert.ToInt32(m_ProductDataTable.Rows[j][1].ToString()))//找到相同元素下的商品
                    {
                        if (m_ProductDataTable.Rows[j][4].ToString() == "Y")//主要商品
                        {
                            if (main_price_type == "C")//不加價
                            {
                                m_ProductDataTable.Rows[j][14] = 0;
                            }
                            else if (main_price_type == "A")//差價計算
                            {
                                m_ProductDataTable.Rows[j][14] = Convert.ToDouble(m_ProductDataTable.Rows[j][14].ToString()) - main_price;
                            }
                            else//B固定金額
                            {
                                m_ProductDataTable.Rows[j][14] = main_price;
                            }
                        }
                        else//可更換商品
                        {
                            if (sub_price_type == "C")//不加價
                            {
                                m_ProductDataTable.Rows[j][14] = 0;
                            }
                            else if (sub_price_type == "A")//差價計算
                            {
                                m_ProductDataTable.Rows[j][14] = Convert.ToDouble(m_ProductDataTable.Rows[j][14].ToString()) - sub_price;
                            }
                            else//B固定金額
                            {
                                m_ProductDataTable.Rows[j][14] = sub_price;
                            }
                        }
                    }//if(SID == Convert.ToInt32(m_ProductDataTable.Rows[j][0].ToString()))
                }//for (int j=0;i< m_ProductDataTable.Rows.Count;j++)
            }//for(int i=0; i < m_AttributeDataTable.Rows.Count; i++)
            //---修改套餐內產品金額
        }

發表迴響

你的電子郵件位址並不會被公開。 必要欄位標記為 *