示例#1
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));
            }
        }
示例#2
0
        public HttpResponseMessage ManageSubAnimalSupplierList()
        {
            List <AnimalProductDetail> animalDatail = new List <AnimalProductDetail>();
            AnimalProductDetail        animal       = new AnimalProductDetail();

            try
            {
                //    string QuotaName = HttpContext.Current.Request.Form["QuotaName"].ToString();
                string OrganizationOid = HttpContext.Current.Request.Form["OrganizationOid"].ToString();
                //string AnimalSupplieOid = HttpContext.Current.Request.Form["AnimalSupplieOid"].ToString();
                //string AnimalSupplieTypeOid = HttpContext.Current.Request.Form["AnimalSupplieTypeOid"].ToString();
                string QuotaTypeOid = HttpContext.Current.Request.Form["QuotaTypeOid"].ToString();

                List <QuotaType_Model> listquo = new List <QuotaType_Model>();
                QuotaType_Model        quota   = new QuotaType_Model();
                XpoTypesInfoHelper.GetXpoTypeInfoSource();
                XafTypesInfo.Instance.RegisterEntity(typeof(QuotaType));
                XafTypesInfo.Instance.RegisterEntity(typeof(ManageAnimalSupplier));
                XafTypesInfo.Instance.RegisterEntity(typeof(ManageSubAnimalSupplier));
                XPObjectSpaceProvider directProvider    = new XPObjectSpaceProvider(scc, null);
                List <ManageAnimalSupplier_Model2> list = new List <ManageAnimalSupplier_Model2>();
                IObjectSpace ObjectSpace = directProvider.CreateObjectSpace();
                QuotaType    quotaType;
                //  var ManageSubAnimalSupplierOid = null;
                quotaType = ObjectSpace.FindObject <QuotaType>(CriteriaOperator.Parse("GCRecord is null and IsActive = 1 and Oid  = '" + QuotaTypeOid + "' ", null));

                ManageAnimalSupplier ObjManageAnimalSupplier = ObjectSpace.FindObject <ManageAnimalSupplier>(CriteriaOperator.Parse("[OrganizationOid]=? and Status=1", OrganizationOid));
                if (ObjManageAnimalSupplier != null)
                {
                    switch (quotaType.QuotaName)
                    {
                    case "โควตาสำนัก":
                        animal.QuotaName             = "โควตาสำนัก"; //ผิด
                        animal.AnimalSupplieTypeOid  = ObjectSpace.FindObject <AnimalSupplieType>(CriteriaOperator.Parse("[SupplietypeName]='หญ้าแห้ง'", null)).Oid.ToString();
                        animal.AnimalSupplieTypeName = ObjectSpace.FindObject <AnimalSupplieType>(CriteriaOperator.Parse("[SupplietypeName]='หญ้าแห้ง'", null)).SupplietypeName;

                        break;

                    case "โควตาศูนย์ฯ":
                        animal.QuotaName             = "โควตาศูนย์ฯ";
                        animal.AnimalSupplieTypeOid  = ObjectSpace.FindObject <AnimalSupplieType>(CriteriaOperator.Parse("[SupplietypeName]='หญ้าแห้ง'", null)).Oid.ToString();
                        animal.AnimalSupplieTypeName = ObjectSpace.FindObject <AnimalSupplieType>(CriteriaOperator.Parse("[SupplietypeName]='หญ้าแห้ง'", null)).SupplietypeName;
                        animal.QuotaQTY = ObjManageAnimalSupplier.CenterQTY;

                        break;

                    case "โควตาปศุสัตว์เขต":
                        animal.QuotaName             = "โควตาปศุสัตว์เขต";
                        animal.AnimalSupplieTypeOid  = ObjectSpace.FindObject <AnimalSupplieType>(CriteriaOperator.Parse("[SupplietypeName]='หญ้าแห้ง'", null)).Oid.ToString();
                        animal.AnimalSupplieTypeName = ObjectSpace.FindObject <AnimalSupplieType>(CriteriaOperator.Parse("[SupplietypeName]='หญ้าแห้ง'", null)).SupplietypeName;
                        animal.QuotaQTY = ObjManageAnimalSupplier.ZoneQTY;
                        break;

                    //case "โควตาปศุสัตว์จังหวัด":
                    //    animal.QuotaName = "โควตาปศุสัตว์จังหวัด";
                    //    animal.AnimalSupplieTypeOid = ObjectSpace.FindObject<AnimalSupplieType>(CriteriaOperator.Parse("[SupplietypeName]='หญ้าแห้ง'", null)).Oid.ToString();
                    //    animal.AnimalSupplieTypeName = ObjectSpace.FindObject<AnimalSupplieType>(CriteriaOperator.Parse("[SupplietypeName]='หญ้าแห้ง'", null)).SupplietypeName;
                    //    animal.QuotaQTY = ObjManageAnimalSupplier.ZoneQTY;
                    //    break;
                    case "โควตาอื่นๆ":
                        animal.QuotaName             = "โควตาอื่นๆ";
                        animal.AnimalSupplieTypeOid  = ObjectSpace.FindObject <AnimalSupplieType>(CriteriaOperator.Parse("[SupplietypeName]='หญ้าแห้ง'", null)).Oid.ToString();
                        animal.AnimalSupplieTypeName = ObjectSpace.FindObject <AnimalSupplieType>(CriteriaOperator.Parse("[SupplietypeName]='หญ้าแห้ง'", null)).SupplietypeName;
                        animal.QuotaQTY = ObjManageAnimalSupplier.OtherQTY;
                        break;

                    case "โควตาปศุสัตว์จังหวัด":
                        if (ObjManageAnimalSupplier != null)
                        {
                            animal.AnimalSupplieTypeOid       = ObjectSpace.FindObject <AnimalSupplieType>(CriteriaOperator.Parse("[SupplietypeName]='หญ้าแห้ง'", null)).Oid.ToString();
                            animal.AnimalSupplieTypeName      = ObjectSpace.FindObject <AnimalSupplieType>(CriteriaOperator.Parse("[SupplietypeName]='หญ้าแห้ง'", null)).SupplietypeName;
                            animal.manageSubAnimalSupplierOid = ObjManageAnimalSupplier.Oid.ToString();
                            List <ManageSubAnimalSupplier_Province> Detail2 = new List <ManageSubAnimalSupplier_Province>();
                            IList <ManageSubAnimalSupplier>         objmanageSubAnimalSupplier = ObjectSpace.GetObjects <ManageSubAnimalSupplier>(CriteriaOperator.Parse("[ManageAnimalSupplierOid]= '" + ObjManageAnimalSupplier.Oid + "' ", null));
                            if (objmanageSubAnimalSupplier.Count > 0)
                            {
                                foreach (ManageSubAnimalSupplier row2 in objmanageSubAnimalSupplier)
                                {
                                    ManageSubAnimalSupplier_Province subanimal = new ManageSubAnimalSupplier_Province();
                                    subanimal.ManageAnimalSupplierOid    = row2.ManageAnimalSupplierOid.Oid.ToString();
                                    subanimal.ManageSubAnimalSupplierOid = row2.Oid.ToString();
                                    subanimal.ProvinceOid  = row2.ProvinceOid.Oid.ToString();
                                    subanimal.ProvinceName = row2.ProvinceOid.ProvinceNameTH;
                                    Detail2.Add(subanimal);
                                }
                                animal.QuotaName       = quotaType.QuotaName;
                                animal.ObjProvinceName = Detail2;
                            }
                        }
                        break;
                    }
                    directProvider.Dispose();
                    ObjectSpace.Dispose();
                    return(Request.CreateResponse(HttpStatusCode.OK, animal));
                }
                else
                {
                    UserError err2 = new UserError();
                    err2.code    = "3"; // error จากสาเหตุอื่นๆ จะมีรายละเอียดจาก system แจ้งกลับ
                    err2.message = "ไม่พบข้อมูล";
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, err2));
                }
            }
            catch (Exception ex)
            {                   //Error case เกิดข้อผิดพลาด
                UserError err = new UserError();
                err.code = "6"; // error จากสาเหตุอื่นๆ จะมีรายละเอียดจาก system แจ้งกลับ

                err.message = ex.Message;
                //  Return resual
                return(Request.CreateResponse(HttpStatusCode.BadRequest, err));
            }
        }