Пример #1
0
 public string BuildContent(string batch, string tblName, string pk_Value, string formatContent, ref bool isAdd)
 {
     _tableHistoryItemMgr = new TableHistoryItemMgr(connectionString);
     List<TableHistoryItem> items = _tableHistoryItemMgr.Query4Batch(new TableHistoryItemQuery { batchno = batch.ToString(), table_name = tblName, pk_value = pk_Value });
     StringBuilder strHtml = new StringBuilder();
     if (items != null && items.Count > 0)
     {
         Array cols = items.GroupBy(m => m.col_name).Select(m => m.Key).ToArray();
         foreach (var col in cols)
         {
             var tmp = items.FindAll(m => m.col_name == col.ToString());
             if (tmp.Count == 1 && string.IsNullOrEmpty(tmp.FirstOrDefault().old_value))
             { continue; }
             else
             {
                 tmp.Remove(tmp.Find(m => string.IsNullOrEmpty(m.old_value)));
                 var first = tmp.FirstOrDefault();
                 var last = tmp.LastOrDefault();
                 if (first == last)
                 {
                     GetParamCon(last, true);
                 }
                 else
                 {
                     GetParamCon(first, true);
                 }
                 GetParamCon(last, false);
                 strHtml.Append(string.Format(formatContent, first.col_chsname, first == last ? last.old_value : first.old_value, last.col_value));
                 isAdd = true;
             }
         }
     }
     return strHtml.ToString();
 }
        public HttpResponseBase QueryLastModifyRecord()
        {
            string result = string.Empty;
            try
            {
                if (!string.IsNullOrEmpty(Request.Form["Product_Id"]))
                {
                    StringBuilder html = new StringBuilder();
                    int productId = Convert.ToInt32(Request.Form["Product_Id"]);
                    bool isPro = (Request.Form["Type"] ?? "") == "product";
                    _tableHistoryMgr = new TableHistoryMgr(connectionString);
                    _tableHistoryItemMgr = new TableHistoryItemMgr(connectionString);
                    TableHistory query = new TableHistory { pk_value = productId.ToString() };
                    if (isPro)
                    {
                        query.table_name = "product";
                    }
                    TableHistory lastRec = _tableHistoryMgr.QueryLastModifyByProductId(query);
                    if (lastRec != null)
                    {
                        List<TableHistory> histories = _tableHistoryMgr.Query(new TableHistory { batchno = lastRec.batchno });
                        if (histories != null && histories.Count > 0)
                        {
                            List<string> tbls = histories.GroupBy(m => m.table_name).Select(m => m.Key).ToList();
                            uint site = 0, level = 0, userid = 0;
                            string[] priceTable = { "price_master", "item_price" };
                            if (isPro)
                            {
                                tbls.RemoveAll(m => priceTable.Contains(m));
                            }
                            else
                            {
                                uint.TryParse(Request.Form["Site_id"], out site);
                                uint.TryParse(Request.Form["User_Level"], out level);
                                uint.TryParse(Request.Form["User_id"], out userid);
                                tbls.RemoveAll(m => !priceTable.Contains(m));
                            }
                            List<TableHistoryItem> items;
                            #region 初始化
                            StringBuilder pro = new StringBuilder();
                            StringBuilder spec = new StringBuilder();
                            StringBuilder category = new StringBuilder();
                            StringBuilder item = new StringBuilder();
                            StringBuilder master = new StringBuilder();
                            StringBuilder price = new StringBuilder();
                            NotificationController notification = new NotificationController();
                            #endregion
                            foreach (var tbl in tbls)
                            {
                                string tblName = tbl.ToString().ToLower();
                                bool isAdd = false;
                                #region 針對不同表的處理
                                switch (tblName)
                                {
                                    case "product":
                                        #region PRODUCT
                                        items = _tableHistoryItemMgr.Query4Batch(new TableHistoryItemQuery { batchno = lastRec.batchno, table_name = tblName });
                                        if (items != null && items.Count > 0)
                                        {
                                            StringBuilder column_1 = new StringBuilder("<tr><td style=\"border:1px solid #99bce8;\">欄位名稱</td>");
                                            StringBuilder column_2 = new StringBuilder("<tr><td style=\"border:1px solid #99bce8;\">修改前</td>");
                                            StringBuilder column_3 = new StringBuilder("<tr><td style=\"border:1px solid #99bce8;\">修改後</td>");
                                            Array cols = items.GroupBy(m => m.col_name).Select(m => m.Key).ToArray();
                                            foreach (var col in cols)
                                            {
                                                var tmp = items.FindAll(m => m.col_name == col.ToString());
                                                if (tmp.Count == 1 && string.IsNullOrEmpty(tmp.FirstOrDefault().old_value))
                                                { continue; }
                                                else
                                                {
                                                    tmp.Remove(tmp.Find(m => string.IsNullOrEmpty(m.old_value)));
                                                    var first = tmp.FirstOrDefault();
                                                    var last = tmp.LastOrDefault();
                                                    if (first == last)
                                                    {
                                                        notification.GetParamCon(last, true);
                                                    }
                                                    else
                                                    {
                                                        notification.GetParamCon(first, true);
                                                    }
                                                    notification.GetParamCon(last, false);
                                                    column_1.AppendFormat("<td style=\"border:1px solid #99bce8;\">{0}</td>", first.col_chsname);
                                                    column_2.AppendFormat("<td style=\"border:1px solid #99bce8;color:Red;\">{0}</td>", first == last ? last.old_value : first.old_value);//class=\"red\" 
                                                    column_3.AppendFormat("<td style=\"border:1px solid #99bce8;color:green;\">{0}</td>", last.col_value);//class=\"green\"
                                                    isAdd = true;
                                                }
                                            }
                                            if (isAdd)
                                            {
                                                pro.AppendFormat("<table style=\"width:180px;text-align:center;font-size: 13px;border:1px solid #99bce8;\">{0}</tr>{1}</tr>{2}</tr></table>", column_1, column_2, column_3);//class=\"tbptstyle\"
                                            }
                                        }
                                        #endregion
                                        break;
                                    case "product_spec":
                                        #region SPEC
                                        StringBuilder spec_1 = new StringBuilder("<tr><td style=\"border:1px solid #99bce8;\">修改前</td>");
                                        StringBuilder spec_2 = new StringBuilder("<tr><td style=\"border:1px solid #99bce8;\">修改後</td>");
                                        Array specIds = histories.FindAll(m => m.table_name.ToLower() == tblName).GroupBy(m => m.pk_value).Select(m => m.Key).ToArray();
                                        foreach (var id in specIds)
                                        {
                                            items = _tableHistoryItemMgr.Query4Batch(new TableHistoryItemQuery { batchno = lastRec.batchno, table_name = tblName, pk_value = id.ToString() });
                                            if (items.Count == 1 && string.IsNullOrEmpty(items.FirstOrDefault().old_value))
                                            { continue; }
                                            else
                                            {
                                                items.Remove(items.Find(m => string.IsNullOrEmpty(m.old_value)));
                                                var first = items.FirstOrDefault();
                                                var last = items.LastOrDefault();
                                                spec_1.AppendFormat("<td class=\"red\" style=\"border:1px solid #99bce8;color:Red;\">{0}</td>", first == last ? last.old_value : first.old_value);
                                                spec_2.AppendFormat("<td class=\"green\" style=\"border:1px solid #99bce8;color:green;\">{0}</td>", last.col_value);
                                                isAdd = true;
                                            }
                                        }
                                        if (isAdd)
                                        {
                                            spec.AppendFormat("<table style=\"width:180px;text-align:center;font-size: 13px;border:1px solid #99bce8;\">{0}</tr>{1}</tr></table>", spec_1, spec_2);//class=\"tbptstyle\"
                                        }
                                        #endregion
                                        break;
                                    case "product_category_set":
                                        #region CATEGORY
                                        items = _tableHistoryItemMgr.Query4Batch(new TableHistoryItemQuery { batchno = lastRec.batchno, table_name = tblName, pk_value = productId.ToString() });
                                        if (items.Count > 0)
                                        {
                                            var first = items.FirstOrDefault();
                                            var last = items.LastOrDefault();
                                            category.Append("<table style=\"width:180px;text-align:center;font-size: 13px;border:1px solid #99bce8;\"><tr><td style=\"border:1px solid #99bce8;\">修改前</td><td style=\"border:1px solid #99bce8;\">修改後</td></tr>");// class=\"tbptstyle\"
                                            category.AppendFormat("<tr><td class=\"red\" style=\"border:1px solid #99bce8;color:Red;\">{0}</td>", first == last ? last.old_value : first.old_value);
                                            category.AppendFormat("<td class=\"green\" style=\"border:1px solid #99bce8;color:green;\">{0}</td></td></table>", last.col_value);
                                        }
                                        #endregion
                                        break;
                                    case "product_item":
                                        #region ITEM
                                        ProductItem pItem;
                                        _productItemMgr = new ProductItemMgr(connectionString);
                                        Array itemIds = histories.FindAll(m => m.table_name.ToLower() == tblName).GroupBy(m => m.pk_value).Select(m => m.Key).ToArray();
                                        foreach (var id in itemIds)
                                        {
                                            isAdd = false;
                                            pItem = _productItemMgr.Query(new ProductItem { Item_Id = uint.Parse(id.ToString()) }).FirstOrDefault();
                                            if (pItem != null)
                                            {
                                                string title = pItem.GetSpecName();
                                                string top = "<div style=\"float:left\"><table style=\"width:180px;text-align:center;font-size: 13px;border:1px solid #99bce8;\"><caption style=\"text-align:center;border:1px solid #99bce8;\">" + title + "</caption><tr><td style=\"border:1px solid #99bce8;\">欄位名稱</td><td style=\"border:1px solid #99bce8;\">修改前</td><td style=\"border:1px solid #99bce8;\">修改后</td></tr>";//class=\"tbstyle\"
                                                string bottom = "</table></div>";
                                                string strContent = "<tr><td style=\"border:1px solid #99bce8;\">{0}</td><td class=\"red\" style=\"border:1px solid #99bce8;color:Red;\">{1}</td><td class=\"green\" style=\"border:1px solid #99bce8;color:green;\">{2}</td></tr>";
                                                string content = notification.BuildContent(lastRec.batchno, tblName, id.ToString(), strContent, ref isAdd);
                                                if (isAdd)
                                                {
                                                    item.Append(top);
                                                    item.Append(content);
                                                    item.Append(bottom);
                                                }
                                            }
                                        }
                                        #endregion
                                        break;
                                    case "price_master":
                                        #region PRICE_MASTER
                                        PriceMaster pMaster;
                                        _pMaster = new PriceMasterMgr(connectionString);
                                        Array masterIds = histories.FindAll(m => m.table_name.ToLower() == tblName).GroupBy(m => m.pk_value).Select(m => m.Key).ToArray();
                                        foreach (var id in masterIds)
                                        {
                                            isAdd = false;
                                            pMaster = _pMaster.Query(new PriceMaster { price_master_id = uint.Parse(id.ToString()) }).FirstOrDefault();
                                            if (pMaster != null && pMaster.site_id == site && pMaster.user_level == level && pMaster.user_id == userid)
                                            {
                                                string siteName = notification.QuerySiteName(pMaster.site_id.ToString());
                                                string userLevel = notification.QueryParaName(pMaster.user_level.ToString(), "UserLevel");
                                                string userMail = pMaster.user_id == 0 ? "" : notification.QueryMail(pMaster.user_id.ToString());
                                                string childName = string.Empty;
                                                if (pMaster.child_id != 0 && pMaster.product_id != pMaster.child_id)
                                                {
                                                    _productMgr = new ProductMgr(connectionString);
                                                    Product tmpPro = _productMgr.Query(new Product { Product_Id = Convert.ToUInt32(pMaster.child_id) }).FirstOrDefault();
                                                    if (tmpPro != null)
                                                    {
                                                        childName = tmpPro.Product_Name;
                                                    }
                                                }
                                                string title = siteName + " + " + userLevel + (string.IsNullOrEmpty(userMail) ? "" : (" + " + userMail))
                                                                + (string.IsNullOrEmpty(childName) ? "<br/>" : "<br/>子商品: " + childName);
                                                if (!title.Contains("子商品"))
                                                {
                                                    title += "<br/>";
                                                }
                                                string top = "<div style=\"float:left\"><table style=\"width:180px;text-align:center;font-size: 13px;border:1px solid #99bce8;\"><caption style=\"text-align:center;border:1px solid #99bce8;\">" + title + "</caption><tr><td style=\"border:1px solid #99bce8;\">欄位名稱</td><td style=\"border:1px solid #99bce8;\">修改前</td><td style=\"border:1px solid #99bce8;\">修改后</td></tr>";// class=\"tbstyle\" 
                                                string bottom = "</table></div>";
                                                string strContent = "<tr><td style=\"border:1px solid #99bce8;\">{0}</td><td class=\"red\" style=\"border:1px solid #99bce8;color:Red;\">{1}</td><td class=\"green\" style=\"border:1px solid #99bce8;color:green;\">{2}</td></tr>";
                                                string content = notification.BuildContent(lastRec.batchno, tblName, id.ToString(), strContent, ref isAdd);
                                                if (isAdd)
                                                {
                                                    master.Append(top);
                                                    master.Append(content);
                                                    master.Append(bottom);
                                                }
                                            }
                                        }
                                        #endregion
                                        break;
                                    case "item_price":
                                        #region ITEM_PRICE

                                        ItemPriceCustom itemPrice;
                                        PriceMaster tmpMaster;
                                        _itemPriceMgr = new ItemPriceMgr(connectionString);
                                        _pMaster = new PriceMasterMgr(connectionString);
                                        Array priceIds = histories.FindAll(m => m.table_name.ToLower() == tblName).GroupBy(m => m.pk_value).Select(m => m.Key).ToArray();
                                        foreach (var id in priceIds)
                                        {
                                            isAdd = false;
                                            itemPrice = _itemPriceMgr.Query(new ItemPrice { item_price_id = uint.Parse(id.ToString()) }).FirstOrDefault();
                                            if (itemPrice != null)
                                            {
                                                tmpMaster = _pMaster.Query(new PriceMaster { price_master_id = itemPrice.price_master_id }).FirstOrDefault();
                                                if (tmpMaster != null && tmpMaster.site_id == site && tmpMaster.user_level == level && tmpMaster.user_id == userid)
                                                {
                                                    string siteName = notification.QuerySiteName(tmpMaster.site_id.ToString());
                                                    string userLevel = notification.QueryParaName(tmpMaster.user_level.ToString(), "UserLevel");
                                                    string userMail = tmpMaster.user_id == 0 ? "" : notification.QueryMail(tmpMaster.user_id.ToString());
                                                    string childName = string.Empty;
                                                    if (tmpMaster.child_id != 0 && tmpMaster.product_id != tmpMaster.child_id)
                                                    {
                                                        _productMgr = new ProductMgr(connectionString);
                                                        Product tmpPro = _productMgr.Query(new Product { Product_Id = Convert.ToUInt32(tmpMaster.child_id) }).FirstOrDefault();
                                                        if (tmpPro != null)
                                                        {
                                                            childName = tmpPro.Product_Name;
                                                        }
                                                    }
                                                    string strSpec = itemPrice.spec_name_1 + (string.IsNullOrEmpty(itemPrice.spec_name_2) ? "" : (" + " + itemPrice.spec_name_2));

                                                    string title = siteName + " + " + userLevel + (string.IsNullOrEmpty(userMail) ? "" : (" + " + userMail))
                                                        + (string.IsNullOrEmpty(childName) ? "<br/>" : "<br/>子商品: " + childName)
                                                        + "<br/>" + strSpec;
                                                    if (strSpec == "")
                                                    {
                                                        title += "<br/>";
                                                    }
                                                    string top = "<div style=\"float:left\"><table style=\"width:180px;text-align:center;font-size: 13px;border:1px solid #99bce8;\"><caption style=\"text-align:center;border:1px solid #99bce8;\">" + title + "</caption><tr><td style=\"border:1px solid #99bce8;\">欄位名稱</td><td style=\"border:1px solid #99bce8;\">修改前</td><td style=\"border:1px solid #99bce8;\">修改后</td></tr>";//class=\"tbstyle\"
                                                    string bottom = "</table></div>";
                                                    string strContent = "<tr><td style=\"border:1px solid #99bce8;\">{0}</td><td class=\"red\" style=\"border:1px solid #99bce8;color:Red;\">{1}</td><td class=\"green\" style=\"border:1px solid #99bce8;color:green;\">{2}</td></tr>";
                                                    string content = notification.BuildContent(lastRec.batchno, tblName, id.ToString(), strContent, ref isAdd);
                                                    if (isAdd)
                                                    {
                                                        price.Append(top);
                                                        price.Append(content);
                                                        price.Append(bottom);
                                                    }
                                                }
                                            }
                                        }
                                        #endregion
                                        break;
                                    default:
                                        break;
                                }
                                #endregion
                            }
                            #region 批次拼接
                            StringBuilder batchHtml = new StringBuilder();
                            if (pro.Length > 0)
                            {
                                batchHtml.AppendFormat("<tr><td style=\"border:1px solid #99bce8;\">商品信息</td><td style=\"border:1px solid #99bce8;\">{0}</td></tr>", pro);
                            }
                            if (spec.Length > 0)
                            {
                                batchHtml.AppendFormat("<tr><td style=\"border:1px solid #99bce8;\">規格信息</td><td style=\"border:1px solid #99bce8;\">{0}</td></tr>", spec);
                            }
                            if (category.Length > 0)
                            {
                                batchHtml.AppendFormat("<tr><td style=\"border:1px solid #99bce8;\">前臺分類信息</td><td style=\"border:1px solid #99bce8;\">{0}</td></tr>", category);
                            }
                            if (item.Length > 0)
                            {
                                batchHtml.AppendFormat("<tr><td style=\"border:1px solid #99bce8;\">商品細項信息</td><td style=\"border:1px solid #99bce8;\">{0}</td></tr>", item);
                            }
                            if (master.Length > 0)
                            {
                                batchHtml.AppendFormat("<tr><td style=\"border:1px solid #99bce8;\">站臺商品信息</td><td style=\"border:1px solid #99bce8;\">{0}</td></tr>", master);
                            }
                            if (price.Length > 0)
                            {
                                batchHtml.AppendFormat("<tr><td style=\"border:1px solid #99bce8;\">站臺價格信息</td><td style=\"border:1px solid #99bce8;\">{0}</td></tr>", price);
                            };
                            if (batchHtml.Length > 0)
                            {
                                _productMgr = new ProductMgr(connectionString);
                                Product product = _productMgr.Query(new Product { Product_Id = Convert.ToUInt32(productId) }).FirstOrDefault();
                                if (product != null)
                                {
                                    string brand = string.Empty;
                                    vbMgr = new VendorBrandMgr(connectionString);
                                    VendorBrand vendorBrand = vbMgr.GetProductBrand(new VendorBrand { Brand_Id = product.Brand_Id });
                                    if (vendorBrand != null)
                                    {
                                        brand = vendorBrand.Brand_Name;
                                    }
                                    _historyBatchMgr = new HistoryBatchMgr(connectionString);
                                    HistoryBatch batch = _historyBatchMgr.Query(new HistoryBatch { batchno = lastRec.batchno });
                                    html.Append("<html><head><style type=\"text/css\">table{ font-size: 13px;border:1px solid #99bce8}td{border:1px solid #99bce8} .tbstyle{width:180px;text-align:center;} .red{color:Red;}.green{color:green;} caption{text-align:center;border:1px solid #99bce8}</style></head><body>");
                                    html.AppendFormat("<table style=\"font-size: 13px;border:1px solid #99bce8;\"><tr><td colspan='2' style=\"border:1px solid #99bce8;\">商品編號:<b>{0}</b>   品牌:<b>{1}</b></td></tr>", productId, brand);
                                    html.AppendFormat("<tr><td colspan='2' style=\"border:1px solid #99bce8;\"><b>{0}</b>  (修改人:{1}", product.Product_Name, batch.kuser);
                                    html.AppendFormat(",修改時間:{0})</td></tr>", batch.kdate.ToString("yyyy/MM/dd HH:mm:ss"));
                                    html.Append(batchHtml);
                                    html.Append("</table>");
                                    html.Append("</body></html>");
                                }
                            }
                            #endregion
                        }
                        result = "{success:true,html:'" + HttpUtility.HtmlEncode(html.ToString()) + "'}";
                    }
                    else
                    {
                        result = "{success:true,html:''}";
                    }
                }
            }
            catch (Exception ex)
            {
                Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
                logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message);
                logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                log.Error(logMessage);
                result = "{success:true,html:''}";
            }
            this.Response.Clear();
            this.Response.Write(result);
            this.Response.End();
            return this.Response;
        }
Пример #3
0
        private string QueryHistory(int itemType)
        {
            StringBuilder html = new StringBuilder();
            try
            {
                _historyBatchMgr = new HistoryBatchMgr(connectionString);
                List<HistoryBatch> batches = _historyBatchMgr.QueryToday(itemType);

                //edit by hufeng0813w 2014/06/13
                batches.Sort(CompareToRowid);//進行一個排序
                //end edit by hufeng0813w 2014/06/13 

                if (batches != null & batches.Count > 0)
                {
                    html.Append("<html><head><style type=\"text/css\">table{text-align:center; font-size: 13px;border:1px solid #99bce8}caption{text-align:center;border:1px solid #99bce8;} td{border:1px solid #99bce8}.red{color:red;}.green{color:green;}.tstyle{width:250px;}</style></head><body>");
                    _tableHistoryMgr = new TableHistoryMgr(connectionString);
                    _tableHistoryItemMgr = new TableHistoryItemMgr(connectionString);
                    html.Append("<ul style=\"list-style:none\">");
                    string channelInfo = "";
                    int batchIndex = -1;
                    foreach (var batch in batches)
                    {
                        //edit by hufeng0813w Reason:如果是商品對照異動通知
                        batchIndex++;
                        if (itemType == 1)
                        {
                            channelInfo += "<b>" + batch.channel_name_full + "</b> (外站商品編號:" + batch.channel_detail_id + ")<br/>";
                            if (batchIndex == 0 || (batches[batchIndex].channel_detail_id == batches[batchIndex - 1].channel_detail_id && batches[batchIndex].channel_name_full == batches[batchIndex].channel_name_full && batches[batchIndex].kdate == batches[batchIndex - 1].kdate) || batchIndex < batches.Count - 1)
                            {
                                continue;
                            }
                        }
                        List<TableHistory> histories = _tableHistoryMgr.Query(new TableHistory { batchno = batch.batchno.ToString() });
                        if (histories != null && histories.Count > 0)
                        {
                            Array tbls = histories.GroupBy(m => m.table_name).Select(m => m.Key).ToArray();
                            List<TableHistoryItem> items;
                            uint productId = 0;

                            #region 初始化

                            StringBuilder pro = new StringBuilder();
                            StringBuilder spec = new StringBuilder();
                            StringBuilder category = new StringBuilder();
                            StringBuilder item = new StringBuilder();
                            StringBuilder master = new StringBuilder();
                            StringBuilder price = new StringBuilder();
                            #endregion

                            foreach (var tbl in tbls)
                            {
                                string tblName = tbl.ToString().ToLower();
                                bool isAdd = false;

                                #region 針對不同表的處理

                                switch (tblName)
                                {
                                    case "product":
                                        #region PRODUCT

                                        items = _tableHistoryItemMgr.Query4Batch(new TableHistoryItemQuery { batchno = batch.batchno.ToString(), table_name = tblName });
                                        if (items != null && items.Count > 0)
                                        {
                                            StringBuilder column_1 = new StringBuilder("<tr><td>欄位名稱</td>");
                                            StringBuilder column_2 = new StringBuilder("<tr><td>修改前</td>");
                                            StringBuilder column_3 = new StringBuilder("<tr><td>修改後</td>");
                                            Array cols = items.GroupBy(m => m.col_name).Select(m => m.Key).ToArray();
                                            foreach (var col in cols)
                                            {
                                                var tmp = items.FindAll(m => m.col_name == col.ToString());
                                                if (tmp.Count == 1 && string.IsNullOrEmpty(tmp.FirstOrDefault().old_value))
                                                { continue; }
                                                else
                                                {
                                                    tmp.Remove(tmp.Find(m => string.IsNullOrEmpty(m.old_value)));
                                                    var first = tmp.FirstOrDefault();
                                                    var last = tmp.LastOrDefault();
                                                    if (first == last)
                                                    {
                                                        GetParamCon(last, true);
                                                    }
                                                    else
                                                    {
                                                        GetParamCon(first, true);
                                                    }
                                                    GetParamCon(last, false);
                                                    column_1.AppendFormat("<td>{0}</td>", first.col_chsname);
                                                    column_2.AppendFormat("<td class=\"red\">{0}</td>", first == last ? last.old_value : first.old_value);
                                                    column_3.AppendFormat("<td class=\"green\">{0}</td>", last.col_value);
                                                    isAdd = true;
                                                }
                                            }
                                            if (isAdd)
                                            {
                                                pro.AppendFormat("<table class=\"tstyle\">{0}</tr>{1}</tr>{2}</tr></table>", column_1, column_2, column_3);
                                            }
                                            if (productId == 0)
                                            {
                                                productId = uint.Parse(histories.Find(m => m.table_name == tblName).pk_value);
                                            }
                                        }
                                        #endregion
                                        break;
                                    case "product_spec":
                                        #region SPEC

                                        StringBuilder spec_1 = new StringBuilder("<tr><td>修改前</td>");
                                        StringBuilder spec_2 = new StringBuilder("<tr><td>修改後</td>");
                                        Array specIds = histories.FindAll(m => m.table_name.ToLower() == tblName).GroupBy(m => m.pk_value).Select(m => m.Key).ToArray();
                                        foreach (var id in specIds)
                                        {
                                            items = _tableHistoryItemMgr.Query4Batch(new TableHistoryItemQuery { batchno = batch.batchno.ToString(), table_name = tblName, pk_value = id.ToString() });
                                            if (items.Count == 1 && string.IsNullOrEmpty(items.FirstOrDefault().old_value))
                                            { continue; }
                                            else
                                            {
                                                items.Remove(items.Find(m => string.IsNullOrEmpty(m.old_value)));
                                                var first = items.FirstOrDefault();
                                                var last = items.LastOrDefault();
                                                spec_1.AppendFormat("<td class=\"red\">{0}</td>", first == last ? last.old_value : first.old_value);
                                                spec_2.AppendFormat("<td class=\"green\">{0}</td>", last.col_value);
                                                isAdd = true;
                                            }
                                        }
                                        if (isAdd)
                                        {
                                            spec.AppendFormat("<table class=\"tstyle\">{0}</tr>{1}</tr></table>", spec_1, spec_2);
                                        }
                                        if (productId == 0)
                                        {
                                            _productSpecMgr = new ProductSpecMgr(connectionString);
                                            ProductSpec pSpec = _productSpecMgr.Query(new ProductSpec { spec_id = uint.Parse(histories.Find(m => m.table_name == tblName).pk_value) }).FirstOrDefault();
                                            if (pSpec != null)
                                            {
                                                productId = pSpec.product_id;
                                            }
                                        }
                                        #endregion
                                        break;
                                    case "product_category_set":
                                        #region CATEGORY

                                        if (productId == 0)
                                        {
                                            productId = uint.Parse(histories.Find(m => m.table_name.ToLower() == tblName).pk_value);
                                        }
                                        items = _tableHistoryItemMgr.Query4Batch(new TableHistoryItemQuery { batchno = batch.batchno.ToString(), table_name = tblName, pk_value = productId.ToString() });
                                        if (items.Count > 0)
                                        {
                                            var first = items.FirstOrDefault();
                                            var last = items.LastOrDefault();
                                            category.Append("<table class=\"tstyle\"><tr><td>修改前</td><td>修改後</td></tr>");
                                            category.AppendFormat("<tr><td class=\"red\">{0}</td>", first == last ? last.old_value : first.old_value);
                                            category.AppendFormat("<td class=\"green\">{0}</td></td></table>", last.col_value);
                                        }
                                        #endregion
                                        break;
                                    case "product_item":
                                        #region ITEM

                                        ProductItem pItem;
                                        _productItemMgr = new ProductItemMgr(connectionString);
                                        Array itemIds = histories.FindAll(m => m.table_name.ToLower() == tblName).GroupBy(m => m.pk_value).Select(m => m.Key).ToArray();
                                        foreach (var id in itemIds)
                                        {
                                            isAdd = false;
                                            pItem = _productItemMgr.Query(new ProductItem { Item_Id = uint.Parse(id.ToString()) }).FirstOrDefault();
                                            if (pItem != null)
                                            {
                                                if (productId == 0)
                                                {
                                                    productId = pItem.Product_Id;
                                                }
                                                string title = pItem.GetSpecName();
                                                string top = "<div style=\"float:left\"><table class=\"tstyle\"><caption>" + title + "</caption><tr><td>欄位名稱</td><td>修改前</td><td>修改后</td></tr>";
                                                string bottom = "</table></div>";
                                                string strContent = "<tr><td>{0}</td><td class=\"red\">{1}</td><td class=\"green\">{2}</td></tr>";
                                                string content = BuildContent(batch.batchno.ToString(), tblName, id.ToString(), strContent, ref isAdd);
                                                if (isAdd)
                                                {
                                                    item.Append(top);
                                                    item.Append(content);
                                                    item.Append(bottom);
                                                }
                                            }
                                        }
                                        #endregion
                                        break;
                                    case "price_master":
                                        #region PRICE_MASTER

                                        PriceMaster pMaster;
                                        _priceMasterMgr = new PriceMasterMgr(connectionString);
                                        Array masterIds = histories.FindAll(m => m.table_name.ToLower() == tblName).GroupBy(m => m.pk_value).Select(m => m.Key).ToArray();
                                        foreach (var id in masterIds)
                                        {
                                            isAdd = false;
                                            pMaster = _priceMasterMgr.Query(new PriceMaster { price_master_id = uint.Parse(id.ToString()) }).FirstOrDefault();
                                            if (pMaster != null)
                                            {
                                                if (productId == 0)
                                                {
                                                    productId = pMaster.product_id;
                                                }
                                                string siteName = QuerySiteName(pMaster.site_id.ToString());
                                                string userLevel = QueryParaName(pMaster.user_level.ToString(), "UserLevel");
                                                string userMail = pMaster.user_id == 0 ? "" : QueryMail(pMaster.user_id.ToString());
                                                string childName = string.Empty;
                                                if (pMaster.child_id != 0 && pMaster.product_id != pMaster.child_id)
                                                {
                                                    _productMgr = new ProductMgr(connectionString);
                                                    Product tmpPro = _productMgr.Query(new Product { Product_Id = Convert.ToUInt32(pMaster.child_id) }).FirstOrDefault();
                                                    if (tmpPro != null)
                                                    {
                                                        childName = tmpPro.Product_Name;
                                                    }
                                                }
                                                string title = siteName + " + " + userLevel + (string.IsNullOrEmpty(userMail) ? "" : (" + " + userMail))
                                                                + (string.IsNullOrEmpty(childName) ? "<br/>" : "<br/>子商品: " + childName);
                                                if (!title.Contains("子商品"))
                                                {
                                                    title += "<br/>";
                                                }
                                                string top = "<div style=\"float:left\"><table class=\"tstyle\"><caption>" + title + "</caption><tr><td>欄位名稱</td><td>修改前</td><td>修改后</td></tr>";
                                                string bottom = "</table></div>";
                                                string strContent = "<tr><td>{0}</td><td class=\"red\">{1}</td><td class=\"green\">{2}</td></tr>";
                                                string content = BuildContent(batch.batchno.ToString(), tblName, id.ToString(), strContent, ref isAdd);
                                                if (isAdd)
                                                {
                                                    master.Append(top);
                                                    master.Append(content);
                                                    master.Append(bottom);
                                                }
                                            }
                                        }
                                        #endregion
                                        break;
                                    case "item_price":
                                        #region ITEM_PRICE

                                        ItemPriceCustom itemPrice;
                                        PriceMaster tmpMaster;
                                        _itemPriceMgr = new ItemPriceMgr(connectionString);
                                        _priceMasterMgr = new PriceMasterMgr(connectionString);
                                        Array priceIds = histories.FindAll(m => m.table_name.ToLower() == tblName).GroupBy(m => m.pk_value).Select(m => m.Key).ToArray();
                                        foreach (var id in priceIds)
                                        {
                                            isAdd = false;
                                            itemPrice = _itemPriceMgr.Query(new ItemPrice { item_price_id = uint.Parse(id.ToString()) }).FirstOrDefault();
                                            if (itemPrice != null)
                                            {
                                                tmpMaster = _priceMasterMgr.Query(new PriceMaster { price_master_id = itemPrice.price_master_id }).FirstOrDefault();
                                                if (tmpMaster != null)
                                                {
                                                    if (productId == 0)
                                                    {
                                                        productId = tmpMaster.product_id;
                                                    }
                                                    string siteName = QuerySiteName(tmpMaster.site_id.ToString());
                                                    string userLevel = QueryParaName(tmpMaster.user_level.ToString(), "UserLevel");
                                                    string userMail = tmpMaster.user_id == 0 ? "" : QueryMail(tmpMaster.user_id.ToString());
                                                    string childName = string.Empty;
                                                    if (tmpMaster.child_id != 0 && tmpMaster.product_id != tmpMaster.child_id)
                                                    {
                                                        _productMgr = new ProductMgr(connectionString);
                                                        Product tmpPro = _productMgr.Query(new Product { Product_Id = Convert.ToUInt32(tmpMaster.child_id) }).FirstOrDefault();
                                                        if (tmpPro != null)
                                                        {
                                                            childName = tmpPro.Product_Name;
                                                        }
                                                    }
                                                    string strSpec = itemPrice.spec_name_1 + (string.IsNullOrEmpty(itemPrice.spec_name_2) ? "" : (" + " + itemPrice.spec_name_2));

                                                    string title = siteName + " + " + userLevel + (string.IsNullOrEmpty(userMail) ? "" : (" + " + userMail))
                                                        + (string.IsNullOrEmpty(childName) ? "<br/>" : "<br/>子商品: " + childName)
                                                        + "<br/>" + strSpec;
                                                    if (strSpec == "")
                                                    {
                                                        title += "<br/>";
                                                    }
                                                    string top = "<div style=\"float:left\"><table class=\"tstyle\"><caption>" + title + "</caption><tr><td>欄位名稱</td><td>修改前</td><td>修改后</td></tr>";
                                                    string bottom = "</table></div>";
                                                    string strContent = "<tr><td>{0}</td><td class=\"red\">{1}</td><td class=\"green\">{2}</td></tr>";
                                                    string content = BuildContent(batch.batchno.ToString(), tblName, id.ToString(), strContent, ref isAdd);
                                                    if (isAdd)
                                                    {
                                                        price.Append(top);
                                                        price.Append(content);
                                                        price.Append(bottom);
                                                    }
                                                }
                                            }
                                        }
                                        #endregion
                                        break;
                                    default:
                                        break;
                                }
                                #endregion
                            }
                            #region 單批次拼接

                            StringBuilder batchHtml = new StringBuilder();
                            if (pro.Length > 0)
                            {
                                batchHtml.AppendFormat("<tr><td>商品信息</td><td>{0}</td></tr>", pro);
                            }
                            if (spec.Length > 0)
                            {
                                batchHtml.AppendFormat("<tr><td>規格信息</td><td>{0}</td></tr>", spec);
                            }
                            if (category.Length > 0)
                            {
                                batchHtml.AppendFormat("<tr><td>前臺分類信息</td><td>{0}</td></tr>", category);
                            }
                            if (item.Length > 0)
                            {
                                batchHtml.AppendFormat("<tr><td>商品細項信息</td><td>{0}</td></tr>", item);
                            }
                            if (master.Length > 0)
                            {
                                batchHtml.AppendFormat("<tr><td>站臺商品信息</td><td>{0}</td></tr>", master);
                            }
                            if (price.Length > 0)
                            {
                                batchHtml.AppendFormat("<tr><td>站臺價格信息</td><td>{0}</td></tr>", price);
                            };
                            if (batchHtml.Length > 0)
                            {
                                _productMgr = new ProductMgr(connectionString);
                                Product product = _productMgr.Query(new Product { Product_Id = productId }).FirstOrDefault();
                                if (product != null)
                                {
                                    string brand = string.Empty;
                                    _vendorBrandMgr = new VendorBrandMgr(connectionString);
                                    VendorBrand vendorBrand = _vendorBrandMgr.GetProductBrand(new VendorBrand { Brand_Id = product.Brand_Id });
                                    if (vendorBrand != null)
                                    {
                                        brand = vendorBrand.Brand_Name;
                                    }
                                    html.AppendFormat("<li><table><tr><td colspan='2'>商品編號:<b>{0}</b>   品牌:<b>{1}</b></td></tr>", productId, brand);
                                    html.AppendFormat("<tr><td colspan='2'><b>{0}</b>  (修改人:{1}", product.Product_Name, batch.kuser);
                                    html.AppendFormat(",修改時間:{0})</td></tr>", batch.kdate.ToString("yyyy/MM/dd HH:mm:ss"));
                                    html.Append(batchHtml);
                                    if (itemType == 1)
                                    {
                                        html.AppendFormat("<tr><td colspan='2'>{0}</td></tr>", channelInfo);
                                    }
                                    html.Append("</table></li>");
                                }
                            }
                            #endregion
                        }
                    }
                    html.Append("</ul>");
                    html.Append("</body></html>");
                }
            }
            catch (Exception)
            {
                throw;
            }
            return html.ToString();
        }
        /// <summary>
        /// 歷史記錄詳情
        /// </summary>
        /// <param name="batchno"></param>
        /// <returns></returns>
        public ActionResult HistoryDetails(string batchno)
        {
            _tableHistoryItemMgr = new TableHistoryItemMgr(connectionString);
            var items = _tableHistoryItemMgr.GetHistoryInfoByConditon(new TableHistory { batchno = batchno });
            /*匹配十位整數正則表達式          
            判斷是否是時間戳格式,是的話轉換為時間格式
            不是的話不按原先值返回 add by wwei0216w 2015/7/8*/
            Regex reg = new Regex("^\\d{10}$");
            foreach (var a in items)
            {
                foreach (var b in a.historyItem)
                {
                    if (reg.IsMatch(b.col_value) && reg.IsMatch(b.old_value))
                    {
                        try
                        {
                            b.col_value = CommonFunction.GetNetTime(Convert.ToInt64(b.col_value)).ToString("yyyy/MM/dd HH:mm:ss");
                            b.old_value = CommonFunction.GetNetTime(Convert.ToInt64(b.old_value)).ToString("yyyy/MM/dd HH:mm:ss");
                        }
                        catch { }
                    }
                }

            }
            return Json(items);
        }