Esempio n. 1
0
        public FrmAddYpJg(int employee_id, int deptid, int cjid, RelationalDatabase DataBase)
        {
            InitializeComponent();

            _cjid     = cjid;
            _DataBase = DataBase;
            Ypcj cj = new Ypcj(cjid, DataBase);

            lblpm.Text   = cj.S_YPPM;
            lblspm.Text  = cj.S_YPSPM;
            lblgg.Text   = cj.S_YPGG;
            txtsccj.Text = cj.S_SCCJ;
            txtsccj.Tag  = cj.SCCJ;
            lbldw.Text   = cj.S_YPDW;

            _employee_id = employee_id;
            _deptid      = deptid;

            FillYP(cj.SCCJ, cj.GGID);

            SystemCfg cfg = new SystemCfg(8028);

            if (cfg.Config == "0")
            {
                txtpfj.Enabled  = false;
                txtlsj.Enabled  = false;
                txtsccj.Enabled = false;
                butsave.Enabled = false;
            }
            if (cfg.Config == "1")
            {
                txtsccj.Enabled = false;
            }
        }
Esempio n. 2
0
        private void txtsccj_KeyUp(object sender, KeyEventArgs e)
        {
            int     nkey    = Convert.ToInt32(e.KeyCode);
            Control control = (Control)sender;

            if (control.Text.Trim() == "")
            {
                control.Text = "";
                control.Tag  = "0";
            }

            if ((nkey >= 65 && nkey <= 90) || (nkey >= 48 && nkey <= 57) || (nkey >= 96 && nkey <= 105) || nkey == 8 || nkey == 32 || nkey == 46 || (nkey == 13 && (Convertor.IsNull(control.Tag, "0") == "0" || Convertor.IsNull(control.Tag, "0") == "")))
            {
            }
            else
            {
                return;
            }

            Point  point = new Point(this.Location.X + control.Location.X, this.Location.Y + control.Location.Y + control.Height * 2);
            string ssql  = "";

            if (nkey == 13 && (control.Tag.ToString() != "" && control.Tag.ToString() != "0"))
            {
                return;
            }
            Yp.frmShowCard(sender, ShowCardType.厂家, 0, point, _deptid, _DataBase);
            if (Convertor.IsNull(control.Tag, "0") != "0")
            {
                this.SelectNextControl((Control)sender, true, false, true, true);
            }

            Ypcj cj = new Ypcj(_cjid, _DataBase);

            FillYP(0, cj.GGID);

            txtpfj.Focus();
            txtpfj.SelectAll();
        }
Esempio n. 3
0
        /// <summary>
        /// 判断明细汇总中库存是否足够
        /// </summary>
        /// <param name="lstSumYpmx">明细汇总</param>
        /// <param name="errText">错误文本</param>
        /// <param name="db">DataBase</param>
        /// <returns></returns>
        public static bool OutKcmx(List <MZ_SumYpmx> lstSumYpmx, out string errText, RelationalDatabase db)
        {
            bool value = true;

            errText = string.Empty;
            foreach (MZ_SumYpmx sumypmx in lstSumYpmx)
            {
                string  ssql_kcmx = string.Format(@" select cast( sum(kcl*dwbl/{2}) as decimal) kcl from yf_kcmx 
                    where bdelete<>1   and 
                cjid={0} and deptid ={1} ", sumypmx.cjid, sumypmx.deptid, sumypmx.dwbl);
                decimal kcl       = Convert.ToDecimal(Convertor.IsNull(db.GetDataResult(ssql_kcmx, 30), "0"));
                if (kcl < sumypmx.sumcount)
                {
                    YpClass.Ypcj c_ypcj = new Ypcj(sumypmx.cjid, db);
                    value   = false;
                    errText = c_ypcj.S_YPPM + " " + c_ypcj.S_YPGG + " 明细库存量不足!";
                }

                //批号库存
                string  ssql_kcph = string.Format(@" select cast( sum(kcl*dwbl/{2}) as decimal) kcl from yf_kcph 
                    where bdelete<>1 and ykbdelete<>1   and 
                cjid={0} and deptid ={1} ", sumypmx.cjid, sumypmx.deptid, sumypmx.dwbl);
                decimal kcl_ph    = Convert.ToDecimal(Convertor.IsNull(db.GetDataResult(ssql_kcph, 30), "0"));

                if (kcl_ph < sumypmx.sumcount)
                {
                    YpClass.Ypcj c_ypcj = new Ypcj(sumypmx.cjid, db);
                    value   = false;
                    errText = c_ypcj.S_YPPM + " " + c_ypcj.S_YPGG + " 批号库存量不足!";
                }
                if (!value)
                {
                    break;
                }
            }

            return(value);
        }
Esempio n. 4
0
        /// <summary>
        /// 门诊发药批次分配(分开拉批号库存)
        /// </summary>
        /// <param name="sumYpmx"></param>
        /// <param name="mxlx">明细类型</param>
        /// <returns></returns>
        public static List <MZ_Kcph> GetMZFYLstKcph(List <MZ_SumYpmx> _lstSumYpmx, List <MZ_Ypmx> _lstYpmx, RelationalDatabase db)
        {
            List <MZ_Kcph>    lstKcph    = new List <MZ_Kcph>();
            List <MZ_SumYpmx> lstSumYpmx = ZY_PCCF.CloneBySerialize <List <MZ_SumYpmx> >(_lstSumYpmx);
            List <MZ_Ypmx>    lstYpmx    = ZY_PCCF.CloneBySerialize <List <MZ_Ypmx> >(_lstYpmx);

            //判断库存是否足够
            string errtext = "";

            if (!OutKcmx(lstSumYpmx, out errtext, db))
            {
                throw new Exception(errtext);
            }

            #region 明细中正负数先进行抵消 被抵消的明细分配最近的批次库存,如果负数不能完全抵消,则报错
            foreach (MZ_Ypmx ypmx_fs in lstYpmx)
            {
                if (ypmx_fs.ypsl < 0)
                {
                    foreach (MZ_Ypmx ypmx_zs in lstYpmx)
                    {
                        if (ypmx_zs.ypsl > 0 && ypmx_zs.mxid == ypmx_fs.tyid)
                        {
                            decimal temp = ypmx_fs.ypsl + ypmx_zs.ypsl;
                            if (temp >= 0)//能够完全抵消
                            {
                                MZ_Kcph kcph_zs = new MZ_Kcph();
                                kcph_zs.cks  = ypmx_fs.ypsl * (-1);
                                kcph_zs.mxid = ypmx_zs.mxid;
                                kcph_zs.cjid = ypmx_zs.cjid;

                                MZ_Kcph kcph_fs = new MZ_Kcph();
                                kcph_fs.cks  = ypmx_fs.ypsl;
                                kcph_fs.mxid = ypmx_fs.mxid;
                                kcph_fs.tyid = ypmx_fs.tyid;
                                kcph_fs.cjid = ypmx_fs.cjid;

                                ypmx_fs.ypsl = 0;
                                ypmx_zs.ypsl = temp;

                                lstKcph.Add(kcph_fs);
                                lstKcph.Add(kcph_zs);
                            }
                            else
                            {
                                if (ypmx_fs.ypsl < 0)
                                {
                                    throw new Exception("存在未能抵消的负处方记录!");
                                }
                            }
                        }
                    }
                }
            }

            #endregion

            //分配批号库存
            foreach (MZ_SumYpmx sum in lstSumYpmx)  //对明细汇总进行迭代
            {
                #region 取批次库存
                string ssql_kcph = string.Format(@" select 
                                              id,jgbm,ggid,cjid,kwid,ypph,ypxq,yppch,id kcid,
                                              jhj,kcl,djsj,bdelete,deptid,ykbdelete,zxdw,dwbl  
                                              from yf_kcph where  cjid={0} and deptid={1} and bdelete<>1 and ykbdelete<>1 and kcl>0 ",
                                                 sum.cjid, sum.deptid); //要考虑单位比例之间的换算这里用的汇总中的dwbl
                DataTable tb_kcph = db.GetDataTable(ssql_kcph, 30);     //取出当前药品批号库存量>0的批号库存

                if (tb_kcph.Rows.Count <= 0)                            //如果库存量为0
                {
                    ssql_kcph = string.Format(@" select top 1 
                                              id,jgbm,ggid,cjid,kwid,ypph,ypxq,yppch,id kcid,
                                              jhj,kcl,djsj,bdelete,deptid,ykbdelete,zxdw,dwbl   
                                              from yf_kcph where  cjid={0} and deptid={1} and bdelete<>1 and ykbdelete<>1 ",
                                              sum.cjid, sum.deptid);//要考虑单位比例之间的换算这里用的汇总中的dwbl
                    tb_kcph = db.GetDataTable(ssql_kcph, 30);
                    if (tb_kcph.Rows.Count <= 0)
                    {
                        Ypcj ypcj = new Ypcj(sum.cjid, db);
                        throw new Exception(string.Format("{0} {1} 没有批次库存记录!", ypcj.S_YPPM, ypcj.S_YPGG));
                    }
                }

                if (Convert.ToInt32(tb_kcph.Rows[0]["dwbl"]) != sum.dwbl)
                {
                    throw new Exception("库存拆零单位发生变化,请刷新数据后重试!");
                }

                #endregion

                #region 给抵消的kcph分配批次
                foreach (MZ_Kcph kcph in lstKcph)
                {
                    if (kcph.cjid == sum.cjid)
                    {
                        DataRow row = tb_kcph.Rows[0];
                        kcph.jhj   = Convert.ToDecimal(row["jhj"]);
                        kcph.dwbl  = sum.dwbl;
                        kcph.zxdw  = Convert.ToInt32(row["zxdw"]);
                        kcph.ggid  = Convert.ToInt32(row["ggid"]);
                        kcph.ypph  = row["ypph"].ToString();
                        kcph.ypxq  = row["ypxq"].ToString();
                        kcph.yppch = Convertor.IsNull(row["yppch"].ToString(), "");
                        kcph.kcid  = Convertor.IsNull(row["kcid"], Guid.Empty.ToString());
                    }
                }
                #endregion

                #region 给未抵消的ypmx分配批号库存
                foreach (MZ_Ypmx ypmx in lstYpmx)
                {
                    if (ypmx.cjid == sum.cjid)
                    {
                        decimal temp = ypmx.ypsl;//当前明细要出库的数量
                        if (temp == 0)
                        {
                            continue;            //如果当前申请明细要出库的数量为0,则申请明细迭代进入下一条
                        }
                        if (temp > 0)
                        {
                            for (int j = 0; j < tb_kcph.Rows.Count; j++) //对当前药品的批号库存进行迭代
                            {
                                DataRow tempRow = tb_kcph.Rows[j];
                                decimal kcl_ph  = Convert.ToDecimal(tempRow["kcl"]); //当前批号库存数量

                                if (temp == 0)
                                {
                                    break;                      //如果申请明细数量为0,则跳出批号库存迭代
                                }
                                if (temp > kcl_ph)              //如果当前批号行库存量小于当前申请明细要出库的数量,该批号库存全部出库
                                {
                                    #region 填充kcph
                                    string  id_kcph       = tempRow["id"].ToString();
                                    int     jgbm_kcph     = Convert.ToInt32(tempRow["jgbm"]);
                                    int     ggid_kcph     = Convert.ToInt32(tempRow["ggid"]);
                                    int     cjid_kcph     = Convert.ToInt32(tempRow["cjid"]);
                                    int     kwid_kcph     = Convert.ToInt32(tempRow["kwid"]);
                                    string  ypph_kcph     = tempRow["ypph"].ToString();
                                    string  ypxq_kcph     = tempRow["ypxq"].ToString();
                                    string  yppch_kcph    = tempRow["yppch"].ToString(); //批次号
                                    string  kcid_kcph     = (tempRow["kcid"] is DBNull) ? Guid.Empty.ToString() : tempRow["kcid"].ToString();
                                    decimal jhj_kcph      = Convert.ToDecimal(tempRow["jhj"]);
                                    decimal kcl_kcph      = Convert.ToDecimal(tempRow["kcl"]);
                                    int     zxdw_kcph     = Convert.ToInt32(tempRow["zxdw"]);
                                    int     dwbl_kcph     = sum.dwbl;
                                    int     bdelete_kcph  = Convert.ToInt32(tempRow["bdelete"]);
                                    int     ykdelete_kcph = Convert.ToInt32(tempRow["ykbdelete"]);
                                    decimal cks_kcph      = kcl_ph;    //出当前批号库存数量
                                    string  mxid_kcph     = ypmx.mxid; //mxid
                                    string  tid_kcph      = ypmx.tid;  //头id
                                    string  tyid_kcph     = ypmx.tyid; //tyid
                                    temp      = temp - cks_kcph;       //当前申请明细要出库的数量-当前批号库存数量
                                    ypmx.ypsl = ypmx.ypsl - cks_kcph;  //当前申请明细要出库的数量-当前批号库存数量
                                    MZ_Kcph kcph = new MZ_Kcph(id_kcph, jgbm_kcph, ggid_kcph, cjid_kcph, kwid_kcph,
                                                               ypph_kcph, ypxq_kcph, yppch_kcph, kcid_kcph, jhj_kcph, kcl_kcph, zxdw_kcph,
                                                               dwbl_kcph, bdelete_kcph, ykdelete_kcph, cks_kcph, mxid_kcph, tid_kcph, cks_kcph
                                                               , tyid_kcph);
                                    lstKcph.Add(kcph);
                                    #endregion
                                    tb_kcph.Rows[j]["kcl"] = 0; //将当前批号库存行 中kcl更新为 0
                                }
                                else                            //如果该批号库存量大于要出库的数量,则出要出库的数量
                                {
                                    #region 填充kcph
                                    string  id_kcph       = tempRow["id"].ToString();
                                    int     jgbm_kcph     = Convert.ToInt32(tempRow["jgbm"]);
                                    int     ggid_kcph     = Convert.ToInt32(tempRow["ggid"]);
                                    int     cjid_kcph     = Convert.ToInt32(tempRow["cjid"]);
                                    int     kwid_kcph     = Convert.ToInt32(tempRow["kwid"]);
                                    string  ypph_kcph     = tempRow["ypph"].ToString();
                                    string  ypxq_kcph     = tempRow["ypxq"].ToString();
                                    string  yppch_kcph    = tempRow["yppch"].ToString(); //批次号
                                    string  kcid_kcph     = (tempRow["kcid"] is DBNull) ? Guid.Empty.ToString() : tempRow["kcid"].ToString();
                                    decimal jhj_kcph      = Convert.ToDecimal(tempRow["jhj"]);
                                    decimal kcl_kcph      = Convert.ToDecimal(tempRow["kcl"]);
                                    int     zxdw_kcph     = Convert.ToInt32(tempRow["zxdw"]);
                                    int     dwbl_kcph     = sum.dwbl;
                                    int     bdelete_kcph  = Convert.ToInt32(tempRow["bdelete"]);
                                    int     ykdelete_kcph = Convert.ToInt32(tempRow["ykbdelete"]);
                                    decimal cks_kcph      = temp;      //ypmx中要出库的数量
                                    string  mxid_kcph     = ypmx.mxid; //明细id
                                    string  tid_kcph      = ypmx.tid;  //头id
                                    string  tyid_kcph     = ypmx.tyid; //tyid
                                    ypmx.ypsl = ypmx.ypsl - cks_kcph;  // 0
                                    temp      = temp - cks_kcph;       //当前申请明细要出库的数量-当前批号库存数量
                                    MZ_Kcph kcph = new MZ_Kcph(id_kcph, jgbm_kcph, ggid_kcph, cjid_kcph, kwid_kcph,
                                                               ypph_kcph, ypxq_kcph, yppch_kcph, kcid_kcph, jhj_kcph, kcl_kcph, zxdw_kcph,
                                                               dwbl_kcph, bdelete_kcph, ykdelete_kcph, cks_kcph, mxid_kcph, tid_kcph, cks_kcph
                                                               , tyid_kcph);
                                    lstKcph.Add(kcph);
                                    #endregion
                                    tb_kcph.Rows[j]["kcl"] = kcl_kcph - cks_kcph; //当前批号库存行中的kcl-出库的数量
                                    break;                                        //跳出批号库存迭代
                                }
                            }
                            if (temp < 0)
                            {
                                throw new Exception("分配批次库存发生错误!");
                            }
                        }
                    }
                }
                #endregion
            }

            //汇总
            List <MZ_Kcph> lstTemp = new List <MZ_Kcph>();
            foreach (MZ_Kcph kcph in lstKcph)
            {
                bool bContain = false;
                foreach (MZ_Kcph kcph_temp in lstTemp)
                {
                    if (kcph.mxid == kcph_temp.mxid && kcph.kcid == kcph_temp.kcid)
                    {
                        bContain      = true;
                        kcph_temp.cks = kcph_temp.cks + kcph.cks;
                        break;
                    }
                    else
                    {
                        bContain = false;
                    }
                }
                if (!bContain)
                {
                    lstTemp.Add(ZY_PCCF.CloneBySerialize <MZ_Kcph>(kcph));
                }
            }


            //return lstKcph;
            return(lstTemp);
        }
Esempio n. 5
0
        /// <summary>
        /// 创建生产计划
        /// </summary>
        /// <param name="scjh"></param>
        public static void CreatScJh(YK_ZJJG_JH jh, List <Jhmx_lstYlmx> lst, RelationalDatabase db, string ywlx, int jgbm)
        {
            //插入计划表数据
            //插入计划明细表数据-插入原料消耗明细-办理原料消耗出库

            try
            {
                //db.BeginTransaction();

                #region 插入原料消耗出库单据头
                Guid    ck_djid;
                int     ck_err_code = 0;  //保存单据头存储过程错误代码
                string  ck_err_text = ""; //保存单据头存储过程错误文本
                long    ck_djh      = Yp.SeekNewDjh(ywlx, jh.deptid, db);
                long    ck_sdjh     = Yp.SeekNewDjh(ywlx, jh.deptid, db);
                decimal ck_sumjhje  = 0;
                decimal ck_sumpfje  = 0;
                decimal ck_sumlsje  = 0;
                int     deptid      = jh.deptid;
                int     uid         = jh.djy;
                string  sDate       = db.GetDataResult(db.GetServerTimeString()).ToString();//当前服务器时间

                foreach (Jhmx_lstYlmx jhmx_lstYlmx in lst)
                {
                    foreach (YK_ZJJG_YLMX ylmx in jhmx_lstYlmx.lstYlmx)
                    {
                        ck_sumjhje += ylmx.jhj * ylmx.sl;
                        ck_sumpfje += ylmx.pfj * ylmx.sl;
                        ck_sumlsje += ylmx.lsj * ylmx.sl;
                    }
                }

                Yk_dj_djmx.SaveDJ(new Guid(Guid.Empty.ToString()),
                                  ck_djh,   //单据号
                                  deptid,   //仓库id
                                  ywlx,     //业务类型
                                  deptid, + //往来单位
                                  0,        //经手人
                                  DateTime.Now.ToShortDateString(),
                                  uid,
                                  Convert.ToDateTime(sDate).ToShortDateString(),
                                  Convert.ToDateTime(sDate).ToLongTimeString(),
                                  "", //发票号
                                  "", //发票日期
                                  "", //备注
                                  "", //送货单号
                                  0,  //原因代码
                                  0,  //申请单号
                                  ck_sumjhje,
                                  ck_sumpfje,
                                  ck_sumlsje,
                                  ck_sdjh.ToString(),
                                  out ck_djid, out ck_err_code, out ck_err_text, jgbm, db);
                #endregion

                #region 插入生产计划
                jh.ckdjid = ck_djid;//回填计划表中 消耗出库单据id
                jh.djh    = YK_ZJJG_JH.SeekNewJhDjh(db, jh.ywlx, deptid);
                YK_ZJJG_JH.SaveJh(db, jh, 0);
                #endregion

                foreach (Jhmx_lstYlmx jhmx_lstYlmx in lst)
                {
                    #region 插入计划明细
                    YK_ZJJG_JHMX jhmx = jhmx_lstYlmx.jhmx;
                    jhmx.djid = jh.id;                   //计划id
                    jhmx.djh  = Convert.ToInt32(jh.djh); //计划号
                    Guid jhmxid = jhmx.id;
                    YK_ZJJG_JHMX.SaveJhmx(jhmx, db, 0);
                    #endregion

                    int pxxh = 0;
                    foreach (YK_ZJJG_YLMX ylmx in jhmx_lstYlmx.lstYlmx)
                    {
                        pxxh += 1;

                        #region 构造原料消耗出库单据明细
                        //int ck_djmx_err_code = 0;
                        //string ck_djmx_err_text = "";
                        Guid ck_djmxid = Guid.NewGuid();
                        Ypcj YPCJ      = new Ypcj(ylmx.cjid, db);
                        Ypgg YPGG      = new Ypgg(YPCJ.GGID, db);

                        ////此方法不再使用 统一方法
                        //InsertDjmx(db,
                        //    ck_djmxid, ck_djid, ylmx.cjid,0,"",
                        //    ylmx.yppm, ylmx.yppm, ylmx.ypgg, ylmx.sccj,  ylmx.ph,
                        //    ylmx.xq.ToShortDateString(), 0, 0, ylmx.sl,  ylmx.ypdw,
                        //    YPGG.YPDW,1,YPCJ.ZBJ, YPCJ.PFJ, YPCJ.LSJ,
                        //    YPCJ.ZBJ * ylmx.sl,YPCJ.PFJ * ylmx.sl, YPCJ.LSJ * ylmx.sl, ck_djh,
                        //    deptid, ywlx, "","", pxxh, 1);

                        int    err_code = 0;
                        string err_text = "";
                        Yk_dj_djmx.SaveDJMX_ID(Guid.Empty, ck_djid, ylmx.cjid, 0, "",
                                               ylmx.yppm, ylmx.yppm, ylmx.ypgg, ylmx.sccj, ylmx.ph,
                                               ylmx.xq.ToShortDateString(), 0, 0, ylmx.sl, ylmx.ypdw,
                                               YPGG.YPDW, 1,
                                               0,                               //YPCJ.MRJJ, //ypcjd中默认进价
                                               YPCJ.PFJ,                        //批发价
                                               YPCJ.LSJ,                        //零售价
                                               0,                               //YPCJ.MRJJ * ylmx.sl/jhmx.ydwbl, //ypcjd中默认进价*原料数量
                                               YPCJ.PFJ * ylmx.sl / jhmx.ydwbl, //批发金额
                                               YPCJ.LSJ * ylmx.sl / jhmx.ydwbl, //零售金额
                                               ck_djh,
                                               deptid, ywlx, "", "", out err_code, out err_text, db, pxxh, out ck_djmxid, "", Guid.Empty);
                        if (err_code != 0)
                        {
                            throw new Exception(err_text);
                        }

                        #endregion

                        #region   插入原料消耗明细
                        ylmx.ckmxid = ck_djmxid;               //原料消耗出库单据明细id
                        ylmx.djid   = jh.id;                   //原料出库单据id
                        ylmx.jhmxid = jhmxid;                  //计划明细id
                        ylmx.djh    = Convert.ToInt32(jh.djh); //计划号
                        YK_ZJJG_YLMX.SaveYlmx(ylmx, db);
                        #endregion
                    }
                }

                #region 审核消耗出库单据
                Yk_dj_djmx.Shdj(ck_djid, db.GetDataResult(db.GetServerTimeString()).ToString(), db);
                #endregion

                #region 更新库存
                int    upt_err_code = 0;
                string upt_err_text = "";
                Yk_dj_djmx.AddUpdateKcmx(ck_djid, out upt_err_code, out upt_err_text, Convert.ToInt64(jgbm), db);
                if (upt_err_code != 0)
                {
                    throw new Exception(upt_err_text.ToString());
                }
                #endregion

                //db.CommitTransaction();
            }
            catch (Exception err)
            {
                //db.RollbackTransaction();
                throw err;
            }
        }
Esempio n. 6
0
        /// <summary>
        /// 审核生产计划
        /// </summary>
        /// <param name="scjh"></param>
        public static void ShScJh(YK_ZJJG_JH jh, List <YK_ZJJG_JHMX> lstjhmx, RelationalDatabase db, string ywlx, int jgbm)
        {
            //更新计划明细-更新原料消耗明细-更新计划表
            //办理加工入库
            try
            {
                List <YK_ZJJG_JH> lstjh_check = YK_ZJJG_JH.GetJhList(string.Format(" and a.id='{0}' ", jh.id), "", db);
                if (lstjh_check.Count <= 0)
                {
                    throw new Exception("审核失败!找不到该计划,请刷新数据后重试!");
                }
                else
                {
                    YK_ZJJG_JH jh_check = lstjh_check[0];
                    if (jh_check.bshbz == 1)
                    {
                        throw new Exception("审核失败!请刷新数据后重试!");
                    }
                    if (jh_check.bscbz == 1)
                    {
                        throw new Exception("审核失败!该计划已经被删除,请刷新数据!");
                    }
                }

                #region  插入加工入库单据头
                Guid    rk_djid;
                int     rk_err_code = 0;  //保存单据头存储过程错误代码
                string  rk_err_text = ""; //保存单据头存储过程错误文本
                long    rk_djh      = Yp.SeekNewDjh(ywlx, jh.deptid, db);
                long    rk_sdjh     = Yp.SeekNewDjh(ywlx, jh.deptid, db);
                decimal rk_sumjhje  = 0;
                decimal rk_sumpfje  = 0;
                decimal rk_sumlsje  = 0;
                int     deptid      = jh.deptid;
                int     uid         = jh.djy;
                string  sDate       = (db.GetDataResult(db.GetServerTimeString())).ToString();//当前服务器时间

                foreach (YK_ZJJG_JHMX jhmx in lstjhmx)
                {
                    rk_sumjhje += jhmx.jhj * jhmx.cpsl;
                    rk_sumpfje += jhmx.pfj * jhmx.cpsl;
                    rk_sumlsje += jhmx.lsj * jhmx.cpsl;
                }

                Yk_dj_djmx.SaveDJ(new Guid(Guid.Empty.ToString()),
                                  rk_djh, //单据号
                                  deptid, //仓库id
                                  ywlx,   //业务类型
                                  deptid, //往来单位
                                  0,      //经手人
                                  DateTime.Now.ToShortDateString(),
                                  uid,
                                  Convert.ToDateTime(sDate).ToShortDateString(),
                                  Convert.ToDateTime(sDate).ToLongTimeString(),
                                  "",
                                  "",
                                  "",
                                  "",
                                  0,
                                  0,
                                  rk_sumjhje,
                                  rk_sumpfje,
                                  rk_sumlsje,
                                  rk_sdjh.ToString(),
                                  out rk_djid, out rk_err_code, out rk_err_text, jgbm, db);
                #endregion

                #region 更新计划
                //if (jh.bshbz == 1) throw new Exception("该计划已经审核!");
                jh.bshbz  = 1;
                jh.rkdjid = rk_djid;
                jh.shrq   = Convert.ToDateTime(db.GetDataResult(db.GetServerTimeString()));
                YK_ZJJG_JH.SaveJh(db, jh, 1);
                #endregion

                #region 更新计划明细
                int pxxh = 0;
                foreach (YK_ZJJG_JHMX jhmx in lstjhmx)
                {
                    pxxh += 1;

                    //计算成本价
                    List <YK_ZJJG_YLMX> lstYlmx   = YK_ZJJG_YLMX.GetYlmxList(string.Format(" and b.id='{0}'", jhmx.id), "", db);
                    decimal             sumYlpfje = 0;
                    foreach (YK_ZJJG_YLMX ylmx in lstYlmx)
                    {
                        sumYlpfje += ylmx.pfj * ylmx.sl;
                    }
                    if (jhmx.cpsl == 0)
                    {
                        throw new Exception("成品数量不能为0");
                    }
                    jhmx.cbj = Convert.ToDecimal(sumYlpfje / jhmx.cpsl); //成本价

                    #region 插入加工入库单据明细
                    //int rk_djmx_err_code = 0;
                    //string rk_djmx_err_text = "";
                    Guid rk_djmxid = Guid.Empty;
                    Ypcj YPCJ      = new Ypcj(jhmx.cjid, db);
                    Ypgg YPGG      = new Ypgg(YPCJ.GGID, db);

                    //此方法不再使用 统一方法
                    //InsertDjmx(db, rk_djmxid, rk_djid, jhmx.cjid,
                    //    0, "", jhmx.yppm, jhmx.yppm, jhmx.ypgg,
                    //    jhmx.sccj, jhmx.ph,
                    //    jhmx.xq.ToShortDateString(), 0, 0, jhmx.cpsl, jhmx.ypdw, YPGG.YPDW, 1,
                    //    YPCJ.ZBJ, YPCJ.PFJ, YPCJ.LSJ, YPCJ.ZBJ * jhmx.cpsl,
                    //    YPCJ.PFJ * jhmx.cpsl, YPCJ.LSJ * jhmx.cpsl, rk_djh, deptid, ywlx, "", rk_sdjh.ToString(),
                    //    pxxh, 1);

                    int    err_code = 0;
                    string err_text = "";
                    //20140211 ncq 将成品入库批发价 设定为成本价 系统对账将会出现批发金额不对问题
                    Yk_dj_djmx.SaveDJMX_ID(Guid.Empty, rk_djid, jhmx.cjid, 0, "",
                                           jhmx.yppm, jhmx.yppm, jhmx.ypgg, jhmx.sccj, jhmx.ph,
                                           jhmx.xq.ToShortDateString(), 0, 0, jhmx.cpsl, jhmx.ypdw, YPGG.YPDW, 1,
                                           0,                                 //YPCJ.MRJJ, //ypcjd中默认进价
                                           YPCJ.PFJ,                          //批发价            //jhmx.cbj,  //成本价
                                           YPCJ.LSJ,                          //零售价
                                                                              //jhmx.cpsl*YPCJ.MRJJ,//ypcjd中默认进价*成品数量
                                           0,                                 //YPCJ.MRJJ * jhmx.cpsl/jhmx.ydwbl,//进货金额
                                           jhmx.cpsl * YPCJ.PFJ / jhmx.ydwbl, //批发金额      //jhmx.cbj * jhmx.cpsl/jhmx.ydwbl, //采用成本价计算批发金额
                                           YPCJ.LSJ * jhmx.cpsl / jhmx.ydwbl, //零售金额
                                           rk_djh, deptid, ywlx, "", rk_sdjh.ToString(),
                                           out err_code, out err_text, db, pxxh, out rk_djmxid, "", Guid.Empty);
                    if (err_code != 0)
                    {
                        throw new Exception(err_text);
                    }

                    #endregion

                    #region 更新计划明细
                    jhmx.cpl      = Convert.ToDecimal(jhmx.cpsl / jhmx.jhsl); //成本率
                    jhmx.rkdjmxid = rk_djmxid;                                //更新计划明细中 入库单据明细id
                    jhmx.djid     = jh.id;
                    jhmx.djh      = Convert.ToInt32(jh.djh);
                    YK_ZJJG_JHMX.SaveJhmx(jhmx, db, 1);
                    #endregion
                }
                #endregion

                #region 审核加工入库单据
                Yk_dj_djmx.Shdj(rk_djid, db.GetDataResult(db.GetServerTimeString()).ToString(), db);
                #endregion

                #region 更新库存
                int    upt_err_code = 0;
                string upt_err_text = "";
                //MessageBox.Show(rk_djid.ToString());
                Yk_dj_djmx.AddUpdateKcmx(rk_djid, out upt_err_code, out upt_err_text, Convert.ToInt64(jgbm), db);
                if (upt_err_code != 0)
                {
                    throw new Exception(upt_err_text.ToString());
                }
                //MessageBox.Show(upt_err_text);
                #endregion
            }
            catch (Exception err)
            {
                throw err;
            }
        }
Esempio n. 7
0
        private void butsave_Click(object sender, EventArgs e)
        {
            if (Convertor.IsNumeric(txtpfj.Text) == false)
            {
                MessageBox.Show("请输入批发价", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (Convertor.IsNumeric(txtlsj.Text) == false)
            {
                MessageBox.Show("请输入零售价", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (Convert.ToDecimal(txtpfj.Text) == 0)
            {
                if (MessageBox.Show("批发价为零您确认吗 ?", "询问窗", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.No)
                {
                    return;
                }
            }
            if (Convert.ToDecimal(txtlsj.Text) == 0)
            {
                if (MessageBox.Show("零售价为零您确认吗 ?", "询问窗", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.No)
                {
                    return;
                }
            }

            //药品所在服务器的链接
            string    ssql    = "select * from pub_menu where function_name='Fun_ts_yp_ypcd'";
            DataTable tbcd    = _DataBase.GetDataTable(ssql);
            int       cd_jgbm = Convert.ToInt32(tbcd.Rows[0]["jgbm"]);

            if (cd_jgbm == -1)
            {
                cd_jgbm = TrasenFrame.Forms.FrmMdiMain.Jgbm;
            }
            RelationalDatabase database = TrasenFrame.Classes.WorkStaticFun.GetJgbmDb(cd_jgbm);

            int    Newcjid  = 0;
            int    err_code = 0;
            string err_text = "";

            Ypcj cj = new Ypcj(_cjid, database);

            ssql = "select * from yp_ypcjd where ggid=" + cj.GGID + " and sccj=" + Convertor.IsNull(txtsccj.Tag, "0") + " and lsj=" + Math.Round(Convert.ToDecimal(txtlsj.Text), 2) + " ";
            DataTable tb = database.GetDataTable(ssql);

            if (tb.Rows.Count >= 1)
            {
                if (Convert.ToInt16(tb.Rows[0]["bdelete"]).ToString() == "1")
                {
                    if (MessageBox.Show("该价格的药品在词典中已存在,但已停用,您要启用吗 ?", "询问窗", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.No)
                    {
                        return;
                    }

                    Guid log_djid_x = Guid.Empty;
                    ts_HospData_Share.ts_update_log ts_x = new ts_HospData_Share.ts_update_log();

                    try
                    {
                        database.BeginTransaction();
                        ssql = "update yp_ypcjd set bdelete=0 where cjid=" + tb.Rows[0]["cjid"].ToString() + " ";
                        database.DoCommand(ssql);

                        ssql = "update yp_ypggd set bdelete=0 where ggid=" + tb.Rows[0]["ggid"].ToString() + " ";
                        database.DoCommand(ssql);

                        //三院数据处理
                        ts_x.Save_log(ts_HospData_Share.czlx.yp_药品字典修改, TrasenFrame.Forms.FrmMdiMain.CurrentUser.Name + "对药品【" + cj.S_YPPM + " " + cj.S_YPGG + "  " + cj.S_SCCJ + " 】 进行修改", "yp_ypcjd", "cjid", cj.CJID.ToString(), cd_jgbm, 0, "", out log_djid_x, database);
                        database.CommitTransaction();
                    }
                    catch (System.Exception err)
                    {
                        database.RollbackTransaction();
                        MessageBox.Show("启用时出错" + err.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    if (log_djid_x != Guid.Empty)
                    {
                        ts_x.Pexec_log(log_djid_x, database, out err_text);
                    }

                    ReturnCjid = Convert.ToInt32(tb.Rows[0]["cjid"]);
                    this.Close();
                }
                else
                {
                    MessageBox.Show("词典中已存在相同厂家和价格的药品,不能重复添加", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }


            Guid log_djid = Guid.Empty;

            ts_HospData_Share.ts_update_log ts = new ts_HospData_Share.ts_update_log();

            try
            {
                database.BeginTransaction();

                Ypcj newcj = new Ypcj();
                newcj           = cj;
                newcj.CJID      = 0;
                newcj.PFJ       = Convert.ToDecimal(txtpfj.Text);
                newcj.LSJ       = Convert.ToDecimal(txtlsj.Text);
                newcj.SCCJ      = Convert.ToInt32(Convertor.IsNull(txtsccj.Tag, "0"));
                newcj.S_SCCJ    = txtsccj.Text.Trim();
                newcj.MRJJ      = 0;
                newcj.CJBDELETE = false;
                newcj.CJDJSJ    = DateManager.ServerDateTimeByDBType(database).ToString();



                newcj.SaveCJ(out Newcjid, out err_code, out err_text, database);
                if (err_code != 0)
                {
                    throw new Exception(err_text);
                }


                //更新药品货号
                newcj.Update_shh(newcj.GGID, out err_code, out err_text, database);
                if (err_code != 0)
                {
                    throw new Exception(err_text);
                }

                //三院数据处理
                ts.Save_log(ts_HospData_Share.czlx.yp_药品字典修改, TrasenFrame.Forms.FrmMdiMain.CurrentUser.Name + "新增【" + newcj.S_YPPM + " " + newcj.S_YPGG + "  " + newcj.S_SCCJ + " 】 价格:" + txtlsj.Text.Trim() + "", "yp_ypcjd", "cjid", Newcjid.ToString(), cd_jgbm, 0, "", out log_djid, database);


                database.CommitTransaction();
            }
            catch (System.Exception err)
            {
                database.RollbackTransaction();
                MessageBox.Show(err.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (log_djid != Guid.Empty)
            {
                ts.Pexec_log(log_djid, database, out err_text);

                this.Cursor = TrasenClasses.GeneralClasses.PubStaticFun.WaitCursor();
                System.Threading.Thread.Sleep(2 * 5000);
            }



            ReturnCjid = Newcjid;
            this.Close();
        }