コード例 #1
0
        [Route("StockAnimalInfoList_Quantity")]   ///หาโควต้า TMR / สด / หมัก
        public HttpResponseMessage StockAnimalInfoList_Quantity()
        {
            ManageQuantity item = new ManageQuantity();

            try
            {
                string scc    = ConfigurationManager.ConnectionStrings["scc"].ConnectionString.ToString();
                string orgOid = HttpContext.Current.Request.Form["orgoid"].ToString();
                //   string quotatypeoid = HttpContext.Current.Request.Form["quotatypeoid"].ToString();
                string budgetsourceoid       = HttpContext.Current.Request.Form["budgetsourceoid"].ToString();
                string animalsupplieroid     = HttpContext.Current.Request.Form["animalsupplieroid"].ToString();
                string animalsuppliertypeoid = HttpContext.Current.Request.Form["animalsuppliertypeoid"].ToString();

                XpoTypesInfoHelper.GetXpoTypeInfoSource();
                XPObjectSpaceProvider          directProvider = new XPObjectSpaceProvider(scc, null);
                IObjectSpace                   ObjectSpace    = directProvider.CreateObjectSpace();
                Get_listAnimalDetailController getlist        = new Get_listAnimalDetailController();
                var    stockused   = 0.0;
                var    stocklimit  = 0.0;
                string seedtypeoid = null;

                if (HttpContext.Current.Request.Form["seedtypeoid"].ToString() != null && HttpContext.Current.Request.Form["seedtypeoid"].ToString() != "")
                {
                    seedtypeoid = HttpContext.Current.Request.Form["seedtypeoid"].ToString();
                    DataSet Ds = SqlHelper.ExecuteDataset(scc, CommandType.StoredProcedure, "sp_StockAnimalInfo"
                                                          , new SqlParameter("@OrganizationOid", orgOid)
                                                          , new SqlParameter("@AnimalSupplieTypeOid", animalsuppliertypeoid)
                                                          , new SqlParameter("@BudgetSourceOid", budgetsourceoid)
                                                          , new SqlParameter("@AnimalSupplieOid", animalsupplieroid)
                                                          , new SqlParameter("@SeedTypeOid", seedtypeoid));
                    if (Ds.Tables[0].Rows.Count > 0)
                    {
                        stockused = (double)Ds.Tables[0].Rows[0]["Total_StockAnimalInfo"];
                    }
                    else
                    {
                        stockused = 0;
                    }

                    Ds = SqlHelper.ExecuteDataset(scc, CommandType.StoredProcedure, "sp_StockAnimalInfo_TMR"
                                                  , new SqlParameter("@OrganizationOid", orgOid)
                                                  , new SqlParameter("@AnimalSupplieTypeOid", animalsuppliertypeoid)
                                                  , new SqlParameter("@BudgetSourceOid", budgetsourceoid)
                                                  , new SqlParameter("@AnimalSupplieOid", animalsupplieroid)
                                                  , new SqlParameter("@SeedTypeOid", seedtypeoid));
                    if (Ds.Tables[0].Rows.Count > 0)
                    {
                        stocklimit = (double)Ds.Tables[0].Rows[0]["Total_Current"];
                    }
                    else
                    {
                        stocklimit = 0;
                    }
                }
                else
                {
                    DataSet Ds = SqlHelper.ExecuteDataset(scc, CommandType.StoredProcedure, "sp_StockAnimalInfo"
                                                          , new SqlParameter("@OrganizationOid", orgOid)
                                                          , new SqlParameter("@AnimalSupplieTypeOid", animalsuppliertypeoid)
                                                          , new SqlParameter("@BudgetSourceOid", budgetsourceoid)
                                                          , new SqlParameter("@AnimalSupplieOid", animalsupplieroid)
                                                          , new SqlParameter("@SeedTypeOid", null));
                    if (Ds.Tables[0].Rows.Count > 0)
                    {
                        stockused = (double)Ds.Tables[0].Rows[0]["Total_StockAnimalInfo"];
                    }
                    else
                    {
                        stockused = 0;
                    }

                    Ds = SqlHelper.ExecuteDataset(scc, CommandType.StoredProcedure, "sp_StockAnimalInfo_TMR"
                                                  , new SqlParameter("@OrganizationOid", orgOid)
                                                  , new SqlParameter("@AnimalSupplieTypeOid", animalsuppliertypeoid)
                                                  , new SqlParameter("@BudgetSourceOid", budgetsourceoid)
                                                  , new SqlParameter("@AnimalSupplieOid", animalsupplieroid)
                                                  , new SqlParameter("@SeedTypeOid", null));
                    if (Ds.Tables[0].Rows.Count > 0)
                    {
                        stocklimit = (double)Ds.Tables[0].Rows[0]["Total_Current"];
                    }
                    else
                    {
                        stocklimit = 0;
                    }
                }

                //item.ProvinceQTY = 0;
                //item.Current_ProvinceQTY = stockused;
                //item.StockLimit = stocklimit;

                UserError err = new UserError();
                err.code    = ""; // error จากสาเหตุอื่นๆ จะมีรายละเอียดจาก system แจ้งกลับ
                err.message = "OK";
                return(Request.CreateResponse(HttpStatusCode.OK, item));
            }
            catch (Exception ex)
            {
                UserError err = new UserError();
                err.code    = "6"; // error จากสาเหตุอื่นๆ จะมีรายละเอียดจาก system แจ้งกลับ
                err.message = ex.Message;
                return(Request.CreateResponse(HttpStatusCode.BadRequest, err));
            }
        }
コード例 #2
0
        [Route("ManageSubAnimalSupplierList_Quantity")]   ///เรียกโควต้า แห้ง   หมัก สด tmr
        public HttpResponseMessage ManageAnimalSupplierList_Quantity()
        {
            ManageQuantity item                  = new ManageQuantity();
            string         orgOid                = null;
            string         ProvinceOid           = null;
            string         managesuboid          = null;
            string         quotatypeoid          = null;
            string         animalsuppliertypeoid = null;
            string         seedtypeoid           = null;

            try
            {
                string scc = ConfigurationManager.ConnectionStrings["scc"].ConnectionString.ToString();
                if (HttpContext.Current.Request.Form["orgoid"] != null)
                {
                    orgOid = HttpContext.Current.Request.Form["orgoid"].ToString();
                }
                string ManageSubAnimalSupplierOid = null;
                if (HttpContext.Current.Request.Form["provinceOid"] != null)
                {
                    ProvinceOid = HttpContext.Current.Request.Form["provinceOid"].ToString();
                }
                if (HttpContext.Current.Request.Form["managesuboid"] != null)
                {
                    managesuboid = HttpContext.Current.Request.Form["managesuboid"].ToString();
                }
                if (HttpContext.Current.Request.Form["quotatypeoid"] != null)
                {
                    quotatypeoid = HttpContext.Current.Request.Form["quotatypeoid"].ToString();
                }


                string budgetsourceoid   = HttpContext.Current.Request.Form["budgetsourceoid"].ToString();
                string animalsupplieroid = HttpContext.Current.Request.Form["animalsupplieroid"].ToString();
                if (HttpContext.Current.Request.Form["animalsuppliertypeoid"] != null)
                {
                    animalsuppliertypeoid = HttpContext.Current.Request.Form["animalsuppliertypeoid"].ToString();
                }
                if (HttpContext.Current.Request.Form["seedtypeoid"] != null)
                {
                    seedtypeoid = HttpContext.Current.Request.Form["seedtypeoid"].ToString();
                }
                else
                {
                    seedtypeoid = null;
                }


                ///โควตา
                //ManageSubAnimalSupplierOid, string QuotaTypeOid, string BudgetSourceOid
                XpoTypesInfoHelper.GetXpoTypeInfoSource();
                XafTypesInfo.Instance.RegisterEntity(typeof(ManageSubAnimalSupplier));
                XafTypesInfo.Instance.RegisterEntity(typeof(QuotaType));
                XafTypesInfo.Instance.RegisterEntity(typeof(ManageAnimalSupplier));
                XafTypesInfo.Instance.RegisterEntity(typeof(SeedType));
                XafTypesInfo.Instance.RegisterEntity(typeof(AnimalSupplieType));
                XafTypesInfo.Instance.RegisterEntity(typeof(AnimalSupplie));
                List <ManageAnimalSupplier_Model2> list     = new List <ManageAnimalSupplier_Model2>();
                List <ManageQuantity>          listQuantity = new List <ManageQuantity>();
                List <objManageAnimalSupplier> listdetail   = new List <objManageAnimalSupplier>();
                ManageQuantity        listQuantity2         = new ManageQuantity();
                XPObjectSpaceProvider directProvider        = new XPObjectSpaceProvider(scc, null);
                IObjectSpace          ObjectSpace           = directProvider.CreateObjectSpace();
                double balanceQTY = 0.0;


                ManageAnimalSupplier objManageAnimalSupplierOid = ObjectSpace.FindObject <ManageAnimalSupplier>(CriteriaOperator.Parse("[OrganizationOid]=?", orgOid));
                AnimalSupplie        objAnimalSupplie           = ObjectSpace.FindObject <AnimalSupplie>(CriteriaOperator.Parse("[oid] =? ", animalsupplieroid));
                if (objAnimalSupplie.AnimalSupplieName == "แห้ง")
                {
                    QuotaType objQuotaType = ObjectSpace.FindObject <QuotaType>(CriteriaOperator.Parse("[Oid]=?", quotatypeoid));
                    if (objQuotaType != null)
                    {
                        if (objQuotaType.QuotaName != "โควตาปศุสัตว์จังหวัด")
                        {
                            ManageAnimalSupplier objManageAnimalSupplier = ObjectSpace.FindObject <ManageAnimalSupplier>(CriteriaOperator.Parse("[OrganizationOid] =? and Status = 1", orgOid));
                            if (objManageAnimalSupplier != null)
                            {
                                if (objQuotaType.QuotaName == "โควตาปศุสัตว์เขต")
                                {
                                    listQuantity2.QuotaName = objQuotaType.QuotaName;
                                    listQuantity2.QuotaQTY  = objManageAnimalSupplier.ZoneQTY;
                                }
                                else if (objQuotaType.QuotaName == "โควตาอื่นๆ")
                                {
                                    listQuantity2.QuotaName = objQuotaType.QuotaName;
                                    listQuantity2.QuotaQTY  = objManageAnimalSupplier.OtherQTY;
                                }
                                else if (objQuotaType.QuotaName == "โควตาศูนย์ฯ")
                                {
                                    listQuantity2.QuotaName = objQuotaType.QuotaName;
                                    listQuantity2.QuotaQTY  = objManageAnimalSupplier.CenterQTY;
                                }
                                else if (objQuotaType.QuotaName == "โควตาสำนัก")
                                {
                                    listQuantity2.QuotaName = objQuotaType.QuotaName;
                                    SeedType          objSeedType          = ObjectSpace.FindObject <SeedType>(CriteriaOperator.Parse("[Oid]=?", seedtypeoid));
                                    AnimalSupplieType objAnimalSupplieType = ObjectSpace.FindObject <AnimalSupplieType>(CriteriaOperator.Parse("[Oid]=?", animalsuppliertypeoid));
                                    if (objSeedType != null && objAnimalSupplieType != null)
                                    {
                                        if (objSeedType.SeedTypeName == "GAP" && objAnimalSupplieType.SupplietypeName == "หญ้าแห้ง")
                                        {
                                            listQuantity2.QuotaQTY = objManageAnimalSupplier.OfficeGAPQTY;
                                        }
                                        else if (objSeedType.SeedTypeName.ToLower() == "normal" && objAnimalSupplieType.SupplietypeName == "หญ้าแห้ง")
                                        {
                                            listQuantity2.QuotaQTY = objManageAnimalSupplier.OfficeQTY;
                                        }
                                        else if (objSeedType.SeedTypeName.ToLower() == "normal" && objAnimalSupplieType.SupplietypeName == "ถั่วแห้ง")
                                        {
                                            listQuantity2.QuotaQTY = objManageAnimalSupplier.OfficeBeanQTY;
                                        }
                                        else if (objSeedType.SeedTypeName.ToLower() == "oganic")
                                        {
                                            listQuantity2.QuotaQTY = 0;
                                        }
                                    }
                                }
                            }
                        }
                        else //โควตาจังหวัด
                        {
                            listQuantity2.QuotaName = objQuotaType.QuotaName;
                            ManageSubAnimalSupplier objManageSubAnimalSupplier = ObjectSpace.FindObject <ManageSubAnimalSupplier>(CriteriaOperator.Parse("[ManageAnimalSupplierOid] =? and [ProvinceOid]=?  ", objManageAnimalSupplierOid.Oid, ProvinceOid));
                            if (objManageSubAnimalSupplier != null)
                            {
                                listQuantity2.QuotaQTY     = objManageSubAnimalSupplier.ProvinceQTY;
                                ManageSubAnimalSupplierOid = objManageSubAnimalSupplier.Oid.ToString();
                                listQuantity2.Provincename = objManageSubAnimalSupplier.ProvinceOid.ProvinceNameTH;
                            }
                        }

                        //Get StockUsed
                        DataSet Ds = null;
                        if (managesuboid != null && managesuboid.ToString() != "")
                        {
                            Ds = SqlHelper.ExecuteDataset(scc, CommandType.StoredProcedure, "GetStockUsed_QuotaHay_Province"
                                                          , new SqlParameter("@OrganizationOid", orgOid)
                                                          , new SqlParameter("@AnimalSupplieTypeOid", animalsuppliertypeoid)
                                                          , new SqlParameter("@QuotaTypeOid", quotatypeoid)
                                                          , new SqlParameter("@BudgetSourceOid", budgetsourceoid)
                                                          , new SqlParameter("@AnimalSupplieOid", animalsupplieroid)
                                                          , new SqlParameter("@ManageSubAnimalSupplierOid", ManageSubAnimalSupplierOid)
                                                          , new SqlParameter("@SeedTypeOid", seedtypeoid));
                        }
                        else
                        {
                            Ds = SqlHelper.ExecuteDataset(scc, CommandType.StoredProcedure, "GetStockUsed_QuotaHay"
                                                          , new SqlParameter("@OrganizationOid", orgOid.ToString())
                                                          , new SqlParameter("@AnimalSupplieTypeOid", animalsuppliertypeoid.ToString())
                                                          , new SqlParameter("@QuotaTypeOid", quotatypeoid.ToString())
                                                          , new SqlParameter("@BudgetSourceOid", budgetsourceoid.ToString())
                                                          , new SqlParameter("@AnimalSupplieOid", animalsupplieroid.ToString())
                                                          , new SqlParameter("@SeedTypeOid", seedtypeoid));
                        }
                        if (Ds.Tables[0].Rows.Count > 0)
                        {
                            //listQuantity2.ba = (double)Ds.Tables[0].Rows[0]["StockUsed"];
                            listQuantity2.balancQuotaQTY = listQuantity2.QuotaQTY - (double)Ds.Tables[0].Rows[0]["StockUsed"];
                            listQuantity2.StockUsed      = (double)Ds.Tables[0].Rows[0]["StockUsed"];
                        }
                        else
                        {
                            //listQuantity2.QuotaQTY = 0;
                            listQuantity2.balanceQTY     = 0;
                            listQuantity2.balancQuotaQTY = 0;
                        }

                        Ds = SqlHelper.ExecuteDataset(scc, CommandType.StoredProcedure, "sp_StockAnimalInfo"
                                                      , new SqlParameter("@OrganizationOid", orgOid)
                                                      , new SqlParameter("@AnimalSupplieTypeOid", animalsuppliertypeoid)
                                                      , new SqlParameter("@BudgetSourceOid", budgetsourceoid)
                                                      , new SqlParameter("@AnimalSupplieOid", animalsupplieroid)
                                                      , new SqlParameter("@SeedTypeOid", seedtypeoid));
                        if (Ds.Tables[0].Rows.Count > 0)
                        {
                            listQuantity2.balanceQTY = (double)Ds.Tables[0].Rows[0]["Total_StockAnimalInfo"];
                        }
                        else
                        {
                            listQuantity2.balanceQTY = 0;
                        }
                    }
                    else //QuotaType = null
                    {
                        listQuantity2.QuotaQTY       = 0; //ปริมาณตามแผนจัดสรร
                        listQuantity2.balanceQTY     = 0; //จำนวนคงเหลือตามจริง
                        listQuantity2.balancQuotaQTY = 0; //ปริมาณคงเหลือตามแผนจัดสรร
                    }

                    listQuantity.Add(listQuantity2);
                }
                else
                {
                    // string scc = ConfigurationManager.ConnectionStrings["scc"].ConnectionString.ToString();
                    orgOid = HttpContext.Current.Request.Form["orgoid"].ToString();
                    //   string quotatypeoid = HttpContext.Current.Request.Form["quotatypeoid"].ToString();
                    budgetsourceoid   = HttpContext.Current.Request.Form["budgetsourceoid"].ToString();
                    animalsupplieroid = HttpContext.Current.Request.Form["animalsupplieroid"].ToString();
                    if (HttpContext.Current.Request.Form["animalsuppliertypeoid"] != null)
                    {
                        animalsuppliertypeoid = HttpContext.Current.Request.Form["animalsuppliertypeoid"].ToString();
                    }

                    var stocklimit = 0.0;
                    if (seedtypeoid != null && seedtypeoid != "")
                    {
                        seedtypeoid = HttpContext.Current.Request.Form["seedtypeoid"].ToString();
                        DataSet Ds = SqlHelper.ExecuteDataset(scc, CommandType.StoredProcedure, "sp_StockAnimalInfo"
                                                              , new SqlParameter("@OrganizationOid", orgOid)
                                                              , new SqlParameter("@AnimalSupplieTypeOid", animalsuppliertypeoid)
                                                              , new SqlParameter("@BudgetSourceOid", budgetsourceoid)
                                                              , new SqlParameter("@AnimalSupplieOid", animalsupplieroid)
                                                              , new SqlParameter("@SeedTypeOid", seedtypeoid));
                        if (Ds.Tables[0].Rows.Count > 0)
                        {
                            balanceQTY = (double)Ds.Tables[0].Rows[0]["Total_StockAnimalInfo"];
                        }
                        else
                        {
                            balanceQTY = 0;
                        }

                        Ds = SqlHelper.ExecuteDataset(scc, CommandType.StoredProcedure, "sp_StockAnimalInfo_TMR"
                                                      , new SqlParameter("@OrganizationOid", orgOid)
                                                      , new SqlParameter("@AnimalSupplieTypeOid", animalsuppliertypeoid)
                                                      , new SqlParameter("@BudgetSourceOid", budgetsourceoid)
                                                      , new SqlParameter("@AnimalSupplieOid", animalsupplieroid)
                                                      , new SqlParameter("@SeedTypeOid", seedtypeoid));
                        if (Ds.Tables[0].Rows.Count > 0)
                        {
                            stocklimit = (double)Ds.Tables[0].Rows[0]["Total_Current"];
                        }
                        else
                        {
                            stocklimit = 0;
                        }
                    }
                    else
                    {
                        if (animalsuppliertypeoid != null)
                        {
                            animalsuppliertypeoid = HttpContext.Current.Request.Form["animalsuppliertypeoid"].ToString();
                        }
                        DataSet Ds = SqlHelper.ExecuteDataset(scc, CommandType.StoredProcedure, "sp_StockAnimalInfo"
                                                              , new SqlParameter("@OrganizationOid", orgOid)
                                                              , new SqlParameter("@AnimalSupplieTypeOid", animalsuppliertypeoid)
                                                              , new SqlParameter("@BudgetSourceOid", budgetsourceoid)
                                                              , new SqlParameter("@AnimalSupplieOid", animalsupplieroid)
                                                              , new SqlParameter("@SeedTypeOid", null));
                        if (Ds.Tables[0].Rows.Count > 0)
                        {
                            balanceQTY = (double)Ds.Tables[0].Rows[0]["Total_StockAnimalInfo"];
                        }
                        else
                        {
                            balanceQTY = 0;
                        }

                        Ds = SqlHelper.ExecuteDataset(scc, CommandType.StoredProcedure, "sp_StockAnimalInfo_TMR"
                                                      , new SqlParameter("@OrganizationOid", orgOid)
                                                      , new SqlParameter("@AnimalSupplieTypeOid", animalsuppliertypeoid)
                                                      , new SqlParameter("@BudgetSourceOid", budgetsourceoid)
                                                      , new SqlParameter("@AnimalSupplieOid", animalsupplieroid)
                                                      , new SqlParameter("@SeedTypeOid", null));
                        if (Ds.Tables[0].Rows.Count > 0)
                        {
                            stocklimit = (double)Ds.Tables[0].Rows[0]["Total_Current"];
                        }
                        else
                        {
                            stocklimit = 0;
                        }
                    }


                    listQuantity2.QuotaQTY       = 0;
                    listQuantity2.balanceQTY     = balanceQTY;
                    listQuantity2.balancQuotaQTY = 0;
                    listQuantity2.StockUsed      = stocklimit;
                    listQuantity.Add(listQuantity2);
                }

                UserError err = new UserError();
                err.code    = ""; // error จากสาเหตุอื่นๆ จะมีรายละเอียดจาก system แจ้งกลับ
                err.message = "OK";
                return(Request.CreateResponse(HttpStatusCode.OK, listQuantity));
            }
            catch (Exception ex)
            {
                UserError err = new UserError();
                err.code    = "6"; // error จากสาเหตุอื่นๆ จะมีรายละเอียดจาก system แจ้งกลับ
                err.message = ex.Message;
                return(Request.CreateResponse(HttpStatusCode.BadRequest, err));
            }
        }