public DataSet GetTicketLine(int TaskID, int PWIID, int TaskDepID, int DPWID)
        {
            DataSet ds = new DataSet();

            Hownet.BLL.ProductWorkingInfo   bllPWI = new ProductWorkingInfo();
            Hownet.Model.ProductWorkingInfo modPWI = new Hownet.Model.ProductWorkingInfo();
            if (TaskDepID == 0)
            {
                modPWI = bllPWI.GetModel(PWIID);
            }
            else
            {
                modPWI = bllPWI.GetModel(DPWID);
            }
            if (!modPWI.IsSpecial)//不是特殊工序
            {
                return(dal.GetTicketLine(TaskID, PWIID, TaskDepID, DPWID));
            }
            else
            {
                return(dal.GetSpecialTicketLine(TaskID, PWIID, TaskDepID, DPWID));
            }
            if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
            {
                ds.Tables.Clear();
                ds = dal.GetSpecialTicketLine(TaskID, PWIID, TaskDepID, DPWID);
            }
            return(ds);
        }
        public bool CheckWorking(int TaskID, int PWIID, int CompanyID)
        {
            Hownet.BLL.ProductWorkingInfo   bllPWI = new ProductWorkingInfo();
            Hownet.BLL.Working              bllW   = new Working();
            Hownet.BLL.WorkTicket           bllWT  = new WorkTicket();
            Hownet.Model.ProductWorkingInfo modPWI = new Hownet.Model.ProductWorkingInfo();
            modPWI = bllPWI.GetModel(PWIID);
            if (!modPWI.IsSpecial)                                      //不是特殊工序
            {
                if (!dal.CheckWorking(TaskID, PWIID, modPWI.OneAmount)) //已生成工票中没有这道工序
                {
                    Hownet.Model.WorkTicketInfo modWTI;
                    DataTable dtWT = new DataTable();
                    dtWT = bllWT.GetList("(TaskID=" + TaskID + ") And (OneAmount=" + modPWI.OneAmount + ")").Tables[0];
                    for (int i = 0; i < dtWT.Rows.Count; i++)
                    {
                        modWTI            = new Hownet.Model.WorkTicketInfo();
                        modWTI.NotAmount  = modWTI.Amount = int.Parse(dtWT.Rows[i]["Amount"].ToString());
                        modWTI.BackID     = 0;
                        modWTI.DateTime   = null;
                        modWTI.EmployeeID = 0;
                        modWTI.IsDel      = false;
                        modWTI.MainID     = int.Parse(dtWT.Rows[i]["ID"].ToString());

                        if (TaskID > 0)
                        {
                            modWTI.TaskID         = TaskID;
                            modWTI.PWorkingInfoID = PWIID;
                        }
                        modWTI.WorkingID = modPWI.WorkingID;
                        Add(modWTI);
                    }
                }
                return(true);
            }
            else
            {
                DataTable dtTem = bllPWI.GetList("(PWIID=" + modPWI.ID + ")").Tables[0];
                List <Hownet.Model.ProductWorkingInfo> li = bllPWI.DataTableToList(dtTem);//是特殊工序时,查找其构成的普通工序
                if (li.Count == 0)
                {
                    return(false);
                }
                for (int i = 0; i < li.Count; i++)
                {
                    if (dal.CheckWorking(TaskID, li[i].ID, li[i].OneAmount))
                    {
                        return(true);
                    }
                }
                Hownet.Model.WorkTicketInfo modWTI;
                DataTable dtWT = new DataTable();
                dtWT = bllWT.GetList("(TaskID=" + TaskID + ") And (OneAmount=" + li[0].OneAmount + ")").Tables[0];
                DataRow[] drs;
                bool      t = false;
                for (int i = 0; i < dtWT.Rows.Count; i++)
                {
                    t                 = false;
                    modWTI            = new Hownet.Model.WorkTicketInfo();
                    modWTI.NotAmount  = modWTI.Amount = int.Parse(dtWT.Rows[i]["Amount"].ToString());
                    modWTI.BackID     = 0;
                    modWTI.DateTime   = null;
                    modWTI.EmployeeID = 0;
                    modWTI.IsDel      = false;
                    modWTI.MainID     = int.Parse(dtWT.Rows[i]["ID"].ToString());
                    if (TaskID > 0)
                    {
                        modWTI.TaskID = TaskID;
                    }
                    //if (CompanyID > 0)
                    //{
                    drs = dtTem.Select("(CompanyID=" + CompanyID + ") And (ColorID=" + dtWT.Rows[i]["ColorID"] + ") And (MaterielID=" + dtWT.Rows[i]["SizeID"] + ")");//同客户同颜色同尺码
                    if (drs.Length == 0)
                    {
                        drs = dtTem.Select("(CompanyID=" + CompanyID + ") And (ColorID=0) And (MaterielID=" + dtWT.Rows[i]["SizeID"] + ")");    //同客户同尺码无颜色
                    }
                    if (drs.Length == 0)
                    {
                        drs = dtTem.Select("(CompanyID=" + CompanyID + ") And (ColorID=" + dtWT.Rows[i]["ColorID"] + ") And (MaterielID=0)");    //同客户同颜色无尺码
                    }
                    if (drs.Length == 0)
                    {
                        drs = dtTem.Select("(CompanyID=0) And (ColorID=" + dtWT.Rows[i]["ColorID"] + ") And  (MaterielID=" + dtWT.Rows[i]["SizeID"] + ")");    //无客户同颜色同尺码
                    }
                    if (drs.Length == 0)
                    {
                        drs = dtTem.Select("(CompanyID=" + CompanyID + ") And (ColorID=0) And (MaterielID=0)");    //仅客户
                    }
                    if (drs.Length == 0)
                    {
                        drs = dtTem.Select("(CompanyID=0) And (ColorID=" + dtWT.Rows[i]["ColorID"] + ") And (MaterielID=0)");    //仅颜色
                    }
                    if (drs.Length == 0)
                    {
                        drs = dtTem.Select("(CompanyID=0) And (ColorID=0) And (MaterielID=" + dtWT.Rows[i]["SizeID"] + ")");    //仅尺码
                    }
                    if (drs.Length == 0)
                    {
                        drs = dtTem.Select("(CompanyID=0) And (ColorID=0) And (MaterielID=0)");    //无客户无颜色无尺码
                    }
                    if (drs.Length > 0)
                    {
                        modWTI.WorkingID      = int.Parse(drs[0]["WorkingID"].ToString());
                        modWTI.PWorkingInfoID = int.Parse(drs[0]["ID"].ToString());
                    }
                    else
                    {
                        t = true;
                    }
                    //}
                    //else
                    //{
                    //    drs = dtTem.Select("(CompanyID=0) And (ColorID=" + dtWT.Rows[i]["ColorID"] + ")");
                    //    if (drs.Length == 0)
                    //    {
                    //        drs = dtTem.Select("(CompanyID=0) And (ColorID=0)");
                    //    }
                    //    if (drs.Length > 0)
                    //    {
                    //        modWTI.WorkingID = int.Parse(drs[0]["WorkingID"].ToString());
                    //        modWTI.PWorkingInfoID = int.Parse(drs[0]["ID"].ToString());
                    //    }
                    //    else
                    //    {
                    //        t = true;
                    //    }
                    //}

                    if (!t)
                    {
                        Add(modWTI);
                    }
                }
            }

            return(true);
        }