C# 物件(類別) 深層複製(拷貝) ~ DeepClone()
C# 物件(類別) 深層複製(拷貝) ~ DeepClone()
code
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace VPOS { public class ShopSubList//購物車 配料資料結構 { public bool m_blnSTOCK_PULL;//是否為寄庫商品 public int m_intImgId;//圖示 public int m_intSID;//DB唯一值 public String m_StrName;//名稱 public double m_dblPrice;//價格 public int m_intAmount;//數量 public double m_dblSum;//總和 public String m_Strcondiment_code; public int m_intitem_no; public int m_intparent_item_no; public String m_Strdel_flag; public String m_Strdel_time; public String m_Stritem_type;//類型 public int m_intdiscount_type;// 折扣/折讓 旗標 public String m_Strdiscount_name;// 折扣/折讓 說明文字 public String m_Strdiscount_code; public int m_intdiscount_rate;// 折扣率 public int m_intdiscount_fee;// 折讓金額 public String m_Strdiscount_info; //JSON public int m_inttax_sid; //稅率編號 ; 產品若沒有稅率資料[m_tax_sid=0],就直接從company和tax_data取出預設值 public int m_inttax_rate; //稅率 public String m_Strtax_type;//稅率類型 public int m_inttax_fee; //稅率金額 public String m_Strsubtotal_flag;//小計旗標 public int m_intsubtotal_item_no;//執行小計的編號 public ShopSubList() { m_blnSTOCK_PULL = false; m_intImgId = -1; m_intSID = -1; m_StrName = ""; m_dblPrice = 0.0; m_intAmount = 0; m_dblSum = 0.0; m_Strcondiment_code = ""; m_intitem_no = -1; m_intparent_item_no = -1; m_Strdel_flag = ""; m_Strdel_time = ""; m_Stritem_type = "";//類型 m_intdiscount_type = -1;// 折扣/折讓 旗標 m_Strdiscount_name = "";// 折扣/折讓 說明文字 m_Strdiscount_code = ""; m_intdiscount_rate = 0;// 折扣率 m_intdiscount_fee = 0;// 折讓金額 m_Strdiscount_info = ""; //JSON m_inttax_sid = -1; //稅率編號 m_inttax_rate = 0; //稅率 m_Strtax_type = "";//稅率類型 m_inttax_fee = 0; //稅率金額 m_Strsubtotal_flag = "N";//小計旗標 m_intsubtotal_item_no = 0;//執行小計的編號 } } public class ShopMainList//購物車 產品資料結構 { public bool m_blnSTOCK_PULL;//是否為寄庫商品 public int m_intImgId;//圖示 public int m_intSID;//DB唯一值 public String m_StrName;//名稱 public double m_dblPrice;//價格 public int m_intAmount;//數量 public double m_dblSum;//總和 public String m_Stritem_type;//類型 public String m_Strproduct_code; public int m_intitem_no; public int m_intparent_item_no;//產品的父ID [歸屬在套餐之中] public String m_Strother_info;//套餐的產品紀錄元素資訊 public String m_Strdel_flag; public String m_Strdel_time; public String m_Strdiscount_type;// 折扣/折讓 旗標 public String m_Strdiscount_name;// 折扣/折讓 說明文字 public String m_Strdiscount_code; public int m_intdiscount_rate;// 折扣率 public int m_intdiscount_fee;// 折讓金額 public String m_Strdiscount_info; //JSON public int m_inttax_sid; //稅率編號 ; 產品若沒有稅率資料[m_tax_sid=0],就直接從company和tax_data取出預設值 public int m_inttax_rate; //稅率 public String m_Strtax_type;//稅率類型 public int m_inttax_fee; //稅率金額 public String m_Strsubtotal_flag;//小計旗標 public int m_intsubtotal_item_no;//執行小計的編號 public List<ShopSubList> m_ShopSubList; public ShopMainList() { m_blnSTOCK_PULL = false;//是否為寄庫商品 m_intImgId = -1; m_intSID = -1; m_StrName = ""; m_dblPrice = 0.0; m_intAmount = 0; m_dblSum = 0.0; m_Strproduct_code = ""; m_intitem_no = -1; m_intparent_item_no = 0; m_Strother_info = ""; m_Strdel_flag = ""; m_Strdel_time = ""; m_Stritem_type = "";//類型 m_Strdiscount_type = "N";// 折扣/折讓 旗標 m_Strdiscount_name = "";// 折扣/折讓 說明文字 m_Strdiscount_code = ""; m_intdiscount_rate = 0;// 折扣率 m_intdiscount_fee = 0;// 折讓金額 m_Strdiscount_info = ""; //JSON m_inttax_sid = -1; //稅率編號 m_inttax_rate = 0; //稅率 m_Strtax_type = "";//稅率類型 m_inttax_fee = 0; //稅率金額 m_Strsubtotal_flag = "N";//小計旗標 m_intsubtotal_item_no = 0;//執行小計的編號 m_ShopSubList = new List<ShopSubList>(); } public ShopMainList DeepClone()//深層複製 { ShopMainList ShopMainListBuf = (ShopMainList)this.MemberwiseClone();//表層屬性複製 ShopMainListBuf.m_ShopSubList=new List<ShopSubList>(); ShopMainListBuf.m_ShopSubList.AddRange(this.m_ShopSubList); return ShopMainListBuf; } } public class ShopCart { public String m_StrOrderNumber;//訂單編號 public int m_intOrderType;//訂單類型 public String m_StrOrderTypeName; public String m_StrOrderTypeCode; public String m_promotion_value;//促銷處理資訊 public double m_promotion_fee;//促銷折扣金額 public String m_coupon_value;//優惠券資訊 public double m_coupon_discount;//優惠券金額 public String m_paid_type;//A: 取貨付款 B: Line Pay 付款 public String m_memo;//備註 public List<ShopMainList> m_ShopMainList; public int m_intItemNoCount = 0;//產生對應MainList/SubLst內的m_intitem_no的欄位值 public ShopCart(int OrderType) { //m_StrOrderNumber = String.Format("{0}-{1}", DateTime.Now.ToString("yyyyMMdd"), "001"); m_intItemNoCount++; m_intOrderType = OrderType; m_ShopMainList = new List<ShopMainList>(); m_promotion_value = "";//促銷處理資訊 m_promotion_fee = 0.0;//促銷折扣金額 m_coupon_value = "";//優惠券資訊 m_coupon_discount = 0.0;//優惠券金額 m_paid_type = "A";//A: 取貨付款 B: Line Pay 付款 m_memo = "";//備註 } } }