using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LYFZ.PhotoSelectSystem;

namespace LYFZ.Software.MainBusiness.CameraControlBook
{
    public class frmSelectProductionList : LYFZ.Software.UI.CameraControlBook.frmChooseScenicToPrint
    {
        public frmSelectProductionList()
        {
            this.MaximizeBox = false;
            this.IsUserControlsSize = false;
            this.Load += FrmSelectProductionList_Load;
            btn_ok.Click += Btn_ok_Click;
            btn_cancle.Click += Btn_cancle_Click;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Btn_cancle_Click(object sender, EventArgs e)
        {
            this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Btn_ok_Click(object sender, EventArgs e)
        {
            this.SelectPhoto.SelectPrintList.Clear();
            foreach (LYFZ.ComponentLibrary.CheckBoxEx cbox in CheckBoxList)
            {
                if (cbox.Checked)
                {
                    this.SelectPhoto.SelectPrintList.Add((SelectPrintProduction)cbox.Tag);
                }
            }
            if (this.SelectPhoto.SelectPrintList.Count > 0)
            {
                this.DialogResult = System.Windows.Forms.DialogResult.OK;
            }
            else {
                MessageBoxCustom.Show("请选择你要打印的成长阶段");
            }

        }

        PhotoSelectSystem.EventSelectPhotoPrint _SelectPhoto;
        LYFZ.EnumPublic.OrderType _OrdType = EnumPublic.OrderType.写真订单;
        /// <summary>
        /// 订单类型
        /// </summary>
        public LYFZ.EnumPublic.OrderType OrderType
        {
            get
            {
                return _OrdType;
            }
            set
            {
                _OrdType = value;
            }
        }
        public EventSelectPhotoPrint SelectPhoto { get => _SelectPhoto; set => _SelectPhoto = value; }

        LYFZ.BLL.BLL_ErpOrderDigital orderDigitalBll = new BLL.BLL_ErpOrderDigital();
        LYFZ.BLL.BLL_ErpOrdersPhotography photographyBll = new BLL.BLL_ErpOrdersPhotography();
        List<LYFZ.ComponentLibrary.CheckBoxEx> CheckBoxList = new List<ComponentLibrary.CheckBoxEx>();
        private void FrmSelectProductionList_Load(object sender, EventArgs e)
        {
            if (SelectPhoto != null)
            {
                LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate (object obj, System.ComponentModel.BackgroundWorker backgroundWorker)
                {
                    backgroundWorker.ReportProgress(0, "正在获取信息....");

                    this.SelectPhoto.OrderDigitalList = orderDigitalBll.GetModelList(String.Format("Ordv_Number='{0}'", SelectPhoto.CurrentModel.Ord_Number), "Ordv_DigitalNumber asc");

                    this.SelectPhoto.PhotographyList = photographyBll.GetModelList(String.Format("Ordpg_Number='{0}'", SelectPhoto.CurrentModel.Ord_Number));
                });

                if (this.OrderType == EnumPublic.OrderType.儿童订单)
                {
                    #region 生成控件;
                    int nCtrlCount = this.SelectPhoto.OrderDigitalList.Count;
                    int nHeight = 65/*上下边框总高*/ + nCtrlCount * 27 + 28 + 25 * 2/*上下边距*/;
                    base.Size = new System.Drawing.Size(435, nHeight);
                    int i = 0;
                    foreach (LYFZ.Model.Model_ErpOrderDigital digital in this.SelectPhoto.OrderDigitalList)
                    {
                        LYFZ.Model.Model_ErpOrdersPhotography photography = this.SelectPhoto.PhotographyList.Find(p => p.Ordpg_ViceNumber.ToLower() == digital.Ordv_ViceNumber.ToLower());
                        if (photography != null)
                        {
                            LYFZ.ComponentLibrary.CheckBoxEx check = new ComponentLibrary.CheckBoxEx();
                            this.plExMainContainer.Controls.Add(check);

                            check.Tag = new SelectPrintProduction(digital, photography); 
                            check.AutoSize = true;
                            check.BackColor = System.Drawing.Color.Transparent;
                            check.CurrentCheckState = LYFZ.ComponentLibrary.CheckStateEx.Unchecked;
                            check.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel, ((byte)(134)));
                            check.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(119)))), ((int)(((byte)(113)))), ((int)(((byte)(113)))));
                            check.Fourstates = false;
                            check.IsGreenTick = false;
                            check.Location = new System.Drawing.Point(115, 25 + 27 * i);
                            check.Name = string.Format("checkBoxEx{0}", i);
                            check.Size = new System.Drawing.Size(200, 21);
                            check.TabIndex = 0;
                            check.Text = string.Format("{0} {1}", photography.Ordpg_Sights, photography.GetPhotographyStatus() == "OK" ? "√" : "");
                            
                            check.CheckState = System.Windows.Forms.CheckState.Checked;
                            check.UseVisualStyleBackColor = false;

                            CheckBoxList.Add(check);
                            i++;
                        }
                    }

                    // ok按钮;
                    btn_ok.Location = new System.Drawing.Point(115, 35 + 27 * nCtrlCount);

                    // cancle按钮;
                    btn_cancle.Location = new System.Drawing.Point(115 + 85 + 45, 35 + 27 * nCtrlCount);
                    #endregion
                }
            }
            else {
                MessageBoxCustom.Show("参数不能为空");
                this.Close();
            }
        }


    }
}