public List <Prescription.Controls.Entity.Prescription> GetPresTemplateRow(int type, int[] tpldetailIds)
        {
            if (tpldetailIds.Length == 0)
            {
                return(new List <Prescription.Controls.Entity.Prescription>());
            }

            string strsql = "";

            strsql = @"SELECT TOP 100 A.GroupID,
	                                A.FeeID,A.FeeName,A.FeeClass, 
	                                A.Dosage,A.DosageUnit,
	                                A.Amount,A.Unit,
	                                A.FrequencyID,C.FrequencyName AS FrequencyName,C.ExecuteCode,
	                                A.ChannelID,B.CName AS ChannelName,
	                                A.Days Num, A.Days,A.Memo
	                                ,D.ClinPrice,D.Spec,D.Dosage DoseConvertNum,D.MatClass,D.SkinMethod IsAst
	                                FROM Clinic_SetMealDetail A
		                                LEFT JOIN Clinic_Channel B ON A.ChannelID = B.ID
		                                LEFT JOIN Clinic_Frequency C ON A.FrequencyID = C.ID 
		                                LEFT JOIN ViewBaseData_Med D ON A.FeeID=D.StockID 
	                                 WHERE A.ID in ({0})
	                                 ORDER BY A.GroupID,A.OrderNum"    ;
            strsql = string.Format(strsql,
                                   string.Join(",", Array.ConvertAll <int, string>(tpldetailIds, delegate(int v)
            {
                return(v.ToString());
            })));


            DataTable dt = oleDb.GetDataTable(strsql);
            List <Prescription.Controls.Entity.Prescription> list_Prescription = new List <Prescription.Controls.Entity.Prescription>();

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                Prescription.Controls.Entity.Prescription mPres = new Prescription.Controls.Entity.Prescription();

                mPres.PresListId = 0;
                mPres.PresHeadId = 0;
                //mPres.OrderNo = i + 1;//行号
                mPres.Item_Id       = Convert.ToInt32(dt.Rows[i]["FeeID"]);
                mPres.Item_Name     = dt.Rows[i]["FeeName"].ToString();
                mPres.Item_Type     = type;//1西药 2中药 3项目材料
                mPres.StatItem_Code = "";
                mPres.Sell_Price    = ConvertDataExtend.ToDecimal(dt.Rows[i]["ClinPrice"], 0);
                mPres.Buy_Price     = ConvertDataExtend.ToDecimal(dt.Rows[i]["ClinPrice"], 0);
                mPres.Item_Price    = ConvertDataExtend.ToDecimal(dt.Rows[i]["ClinPrice"], 0);
                mPres.Standard      = dt.Rows[i]["Spec"].ToString();
                mPres.Usage_Amount  = Convert.ToDecimal(dt.Rows[i]["Dosage"]);                      //剂量
                mPres.Usage_Unit    = dt.Rows[i]["DosageUnit"].ToString();                          //剂量单位
                mPres.Usage_Rate    = ConvertDataExtend.ToDecimal(dt.Rows[i]["DoseConvertNum"], 1); //剂量系数
                mPres.Dosage        = Convert.ToInt32(dt.Rows[i]["Num"]);                           //付数
                mPres.Usage_Id      = Convert.ToInt32(dt.Rows[i]["ChannelID"]);
                mPres.Frequency_Id  = Convert.ToInt32(dt.Rows[i]["FrequencyID"]);
                mPres.Days          = Convert.ToInt32(dt.Rows[i]["Days"]);

                mPres.Amount = Convert.ToDecimal(dt.Rows[i]["Amount"].ToString());            //发药数量
                mPres.Unit   = dt.Rows[i]["Unit"].ToString();                                 //发药单位

                mPres.Item_Amount = Convert.ToInt32(Convert.ToDecimal(dt.Rows[i]["Amount"])); //开药数量
                mPres.Item_Unit   = dt.Rows[i]["Unit"].ToString();                            //开药单位
                mPres.Item_Rate   = 1;                                                        //系数

                mPres.Group_Id      = Convert.ToInt32(dt.Rows[i]["GroupID"]);                 //分组组号
                mPres.SkinTest_Flag = ConvertDataExtend.ToInt32(dt.Rows[i]["IsAst"], 0);      //皮试
                mPres.SelfDrug_Flag = 0;                                                      //自备
                mPres.Entrust       = dt.Rows[i]["Memo"].ToString();                          //嘱托

                mPres.FootNote = "";
                mPres.Tc_Flag  = 0;                                               //套餐

                mPres.Usage_Name        = dt.Rows[i]["ChannelName"].ToString();   //用法名称
                mPres.Frequency_Name    = dt.Rows[i]["FrequencyName"].ToString(); //频次名称
                mPres.Frequency_Caption = dt.Rows[i]["ExecuteCode"].ToString();   //频次名称

                int _execNum, _cycleDay;
                CardDataSourceFrequency.Calculate(dt.Rows[i]["ExecuteCode"].ToString(), out _execNum, out _cycleDay);
                mPres.Frequency_ExecNum  = _execNum;  //执行次数
                mPres.Frequency_CycleDay = _cycleDay; //执行周期


                mPres.CalculateAmount(null);

                list_Prescription.Add(mPres);
            }

            return(list_Prescription);
            //throw new NotImplementedException();
        }
        public Prescription.Controls.Entity.Prescription GetPresTemplateRow(int type, int itemId)
        {
            CardDataSourceDrugItem durgItem = GetDrugItem(itemId);

            if (durgItem == null)
            {
                throw new Exception("该项目已停用,不能开出!");
            }
            Prescription.Controls.Entity.Prescription mPres = new Prescription.Controls.Entity.Prescription();
            mPres.Item_Id       = ConvertDataExtend.ToInt32(durgItem.ItemId, -1);
            mPres.Item_Name     = ConvertDataExtend.ToString(durgItem.ItemName, "");
            mPres.Item_Type     = type;//Convert.ToInt32(durgItem.ItemType);//1西药 2中药 3项目材料
            mPres.StatItem_Code = ConvertDataExtend.ToString(durgItem.StatItemCode, "");;
            mPres.Sell_Price    = durgItem.SellPrice;
            mPres.Buy_Price     = durgItem.BuyPrice;
            mPres.Item_Price    = durgItem.SellPrice;
            mPres.Standard      = durgItem.Standard;
            mPres.Usage_Amount  = durgItem.default_Usage_Id; //剂量
            mPres.Usage_Unit    = durgItem.DoseUnitName;     //剂量单位
            mPres.Usage_Rate    = durgItem.DoseConvertNum;   //剂量系数
            if (mPres.IsHerb)
            {
                mPres.Dosage = 1;//付数
            }
            else
            {
                mPres.Dosage = 0;
            }
            mPres.Usage_Id     = durgItem.default_Usage_Id;
            mPres.Frequency_Id = durgItem.default_Frequency_Id;
            mPres.Days         = Convert.ToInt32(1);

            //mPres.Amount = 0;//发药数量
            mPres.Unit = durgItem.UnPickUnit;            //发药单位

            mPres.Item_Amount = Convert.ToInt32(1);      //开药数量
            mPres.Item_Unit   = durgItem.UnPickUnit;     //开药单位
            mPres.Item_Rate   = Convert.ToInt32(1);      //系数

            mPres.SkinTest_Flag = durgItem.SkinTestFlag; //皮试
            mPres.SelfDrug_Flag = Convert.ToInt32(0);    //自备
            mPres.Entrust       = "";                    //嘱托

            mPres.FootNote = "";
            mPres.Tc_Flag  = 0;//套餐

            mPres.Pres_Date = Convert.ToDateTime(DateTime.Now);

            mPres.Usage_Name     = durgItem.default_Usage_Name;     //用法名称
            mPres.Frequency_Name = durgItem.default_Frequency_Name; //频次名称

            string _caption = "";
            CardDataSourceFrequency freq = GetFrequency().Find(x => x.FrequencyId == mPres.Usage_Id);

            if (freq != null)
            {
                _caption = freq.Caption;
            }

            //string _caption = CardDataSource.Tables["frequencydic"].Select("FrequencyId=" + mPres.Usage_Id)[0]["Caption"].ToString();
            mPres.Frequency_Caption = _caption;//频次名称

            int _execNum, _cycleDay;

            CardDataSourceFrequency.Calculate(_caption, out _execNum, out _cycleDay);
            mPres.Frequency_ExecNum  = _execNum;  //执行次数
            mPres.Frequency_CycleDay = _cycleDay; //执行周期

            mPres.IsFloat = true;                 //row["RoundingMode"]

            mPres.Usage_Amount = mPres.Usage_Amount <= 0 ? 1 : mPres.Usage_Amount;
            mPres.CalculateAmount(durgItem.UnPickUnit);//计算数量 和 金额

            return(mPres);
            //throw new NotImplementedException();
        }