using System.Data;
using System.Data.SqlClient;
using DataLinkMesWork;
using System.Security.Cryptography;
//using SystemFramework;
using System.Text;
using System;

namespace bizFacade
{
   public class ando_machine_2
    {
        /// <summary>
        /// 创建质量ando
        /// </summary>
        /// <param name="opname"></param>
        /// <param name="AndoTypeCode"></param>
        /// <returns></returns>
        public static string CreateAndo_Machine(string opname, string AndoTypeCode)
        {
            System.Data.DataTable dt_list;
            //查询ando明细
            ando_matertial.andoListSelect(opname, AndoTypeCode, out dt_list);


            StringBuilder sb = new StringBuilder();

            sb.Append("<div id=\"div_ando_third_main\" class=\"div_ando_third_main\">");
            sb.Append("<div id=\"div_ando_third\" class=\"div_ando_third\">");
            sb.Append("<div style=\"width:96%;height:82%;margin-left:10px;margin-top:12px;\">");

            #region 大图片的div
            sb.Append("<div style=\"width:8%;height:100%;float:left;\">");
            sb.Append("<img alt=\"loading....\" src=\"../images/ando_machine.png\" width=\"92%\" height=\"100%\" />");
            sb.Append("</div>");
            #endregion

            #region 整个ANDON选项DIV
            sb.Append("<div style=\"width:67%;height:100%;float:left;\">");

            #region 左按钮DIV
            sb.Append("<div style=\"width:10%;height:100%;float:left;\">");
            sb.Append("<input type=\"button\" style=\"width:100%;height:100%;text-align:center;font-size:30px;\" value=\"<<\" onclick=\"machine_RightMove()\" />");
            sb.Append("</div>");
            #endregion


            #region 中间内容DIV
            sb.Append("<div style=\"width:80%;height:100%;float:left;\">");

            #region 可支持移动的div

            sb.Append("<div style=\"width:100%;height:100%; overflow:hidden;position:relative;\">");

            sb.Append("<div id=\"div_machine_Scroll\" style=\"width:100%;height:100%; position:relative;\">");


            //附加tabel
            string tabelString = CreatAndo_machine_table(opname, AndoTypeCode);
            sb.Append(tabelString);

            sb.Append("</div>");
            sb.Append("</div>");
            #endregion

            sb.Append("</div>");
            #endregion

            #region 右按钮div

            sb.Append("<div style=\"width:10%;height:100%;float:left;\">");

            sb.Append("<input type=\"button\" style=\"width:100%;height:100%;text-align:center;font-size:30px;\" value=\">>\"  onclick=\"machine_leftMove()\" />");
            sb.Append("</div>");

            #endregion

            sb.Append("</div>");
            #endregion
            #region ando按钮div

            sb.Append("<div style=\"width:25%;height:100%;float:left;\">");

            sb.Append("<div style=\"width: 100%; height:80%; margin: 20px 0px 0px 5px;\">");

            sb.Append("<table style=\"width: 100%;\">");
            sb.Append("<tr>");
            sb.Append("<td align=\"left\">");
            sb.Append("<img onclick=\"andon_machine_call_down('m_machine_call')\" alt=\"loading...\"  id='m_machine_call' src=\"../images/call.png\" style=\"width: 100px; height: 80px\"/>");
            sb.Append("</td>");
            sb.Append("<td align=\"right\">");
            sb.Append("<img onclick=\"andon_machine_reset_down('m_machine_reset')\" alt=\"loading...\"  id='m_machine_reset' src=\"../images/reset.png\" style=\"width: 100px;height: 80px\" />");
            sb.Append("</td>");
            sb.Append("</tr>");
            sb.Append("<tr>");
            sb.Append("<td style=\"padding-top: 20px\" align=\"center\">");
            sb.Append("<label style=\"padding-top: 20px;font-size:18px;\">呼 叫</label>");
            sb.Append("</td>");
            sb.Append("<td style=\"padding-top: 20px\" align=\"center\">");
            sb.Append("<label style=\"padding-top: 20px;font-size:18px;\">复 位</label>");
            sb.Append("</td>");
            sb.Append("</tr>");
            sb.Append("</table>");

            sb.Append("</div>");

            sb.Append("</div>");

            #endregion

            sb.Append("</div></div></div>");


            return sb.ToString();
            //string text = "";
            //int count = dt_list.Rows.Count/2*120;
            //return text = "{\"InnerHtml\":\"" + sb.ToString() + "\",\"Count\":\"" + count + "\"}";
        }
        /// <summary>
        /// 创建物料ando的table
        /// </summary>
        /// <param name="opname"></param>
        /// <param name="AndoTypeCode"></param>
        /// <returns></returns>
        public static string CreatAndo_machine_table(string opname, string AndoTypeCode)
        {
            System.Data.DataTable dt_list;
            //查询ando明细
            ando_matertial.andoListSelect(opname, AndoTypeCode, out dt_list);
            StringBuilder sb = new StringBuilder();
            int tableCount = dt_list.Rows.Count;
            int td_count = (tableCount / 2) + (tableCount % 2);//获取每个tr中应该创建多少个td
            int tablewidth = 145 * td_count;
            if (tablewidth == 0)
            {
                tablewidth = 10;
            }
            string tablewidth2 = Convert.ToString(tablewidth) + "px";

            #region table

            sb.Append("<table id=\"table_machine_Scroll\" style=\"width:" + tablewidth2 + ";height:100%;left:0px;\">");

            //创建第一行
            sb.Append("<tr>");
            for (int i = 0; i < td_count; i++)
            {
                #region 第一行按钮
                sb.Append("<td style=\"height:50%;width:145px;\">");
                //标签id
                string id = "button_ando_machine_" + dt_list.Rows[i]["编号"].ToString();

                #region 颜色代码
                //标签值
                string value = dt_list.Rows[i]["编号描述2"].ToString();
                string color = dt_list.Rows[i]["颜色代码"].ToString();
                //string inputColor = "background-color:" + color + "";
                if (color == "0")
                {
                    sb.Append("<input type=\"button\" onclick=\"andon_machine(id)\" id=\"" + id + "\" value=\"" + value + "\" style=\"width: 140px; height:100%;\"/>");
                }
                if (color == "1")
                {
                    sb.Append("<input type=\"button\" onclick=\"andon_machine(id)\" id=\"" + id + "\" value=\"" + value + "\" style=\"width: 140px; height:100%;background-color:pink;\"/>");
                }
                if (color == "2")
                {
                    sb.Append("<input type=\"button\" onclick=\"andon_machine(id)\" id=\"" + id + "\" value=\"" + value + "\" style=\"width: 140px; height:100%;background-color:yellow;\"/>");
                }
                #endregion

                sb.Append("</td>");

                #endregion
            }
            sb.Append("</tr>");


            //创建第二行
            sb.Append("<tr>");
            for (int i = td_count; i < tableCount; i++)
            {
                #region 第二行按钮
                sb.Append("<td style=\"height:50%;width:145px;\">");
                //标签id
                string id = "button_ando_machine_" + dt_list.Rows[i]["编号"].ToString();

                #region 颜色代码
                //标签值
                string value = dt_list.Rows[i]["编号描述2"].ToString();
                string color = dt_list.Rows[i]["颜色代码"].ToString();
                if (color == "0")
                {
                    sb.Append("<input type=\"button\" onclick=\"andon_machine(id)\" id=\"" + id + "\" value=\"" + value + "\" style=\"width: 140px; height:100%;\"/>");
                }
                if (color == "1")
                {
                    sb.Append("<input type=\"button\" onclick=\"andon_machine(id)\" id=\"" + id + "\" value=\"" + value + "\" style=\"width: 140px; height:100%;background-color:pink;\"/>");
                }
                if (color == "2")
                {
                    sb.Append("<input type=\"button\" onclick=\"andon_machine(id)\" id=\"" + id + "\" value=\"" + value + "\" style=\"width: 140px; height:100%;background-color:yellow;\"/>");
                }
                #endregion

                sb.Append("</td>");

                #endregion
            }

            //补充第二行的信息
            if ((tableCount % 2) > 0 && (tableCount > 0))
            {
                sb.Append("<td style=\"height:50%\">");
                sb.Append("</td>");
            }
            sb.Append("</tr>");

            //最后组合成table
            sb.Append("</table>");
            return sb.ToString();
            #endregion
        }
    }
}
