public HttpResponseMessage quata_typemanage()
        {
            try
            {
                string ManageAnimalSupplier = HttpContext.Current.Request.Form["manageanimalsupplieroid"].ToString();
                //      string animalSupplieOid = HttpContext.Current.Request.Form["animalSupplieOid"].ToString();
                string quotatypeoid = HttpContext.Current.Request.Form["quotatypeoid"].ToString();
                XpoTypesInfoHelper.GetXpoTypeInfoSource();
                XafTypesInfo.Instance.RegisterEntity(typeof(ManageAnimalSupplier));
                XafTypesInfo.Instance.RegisterEntity(typeof(QuotaType));
                XafTypesInfo.Instance.RegisterEntity(typeof(ManageSubAnimalSupplier));
                XafTypesInfo.Instance.RegisterEntity(typeof(AnimalSupplie));
                XPObjectSpaceProvider           directProvider = new XPObjectSpaceProvider(scc, null);
                IObjectSpace                    ObjectSpace    = directProvider.CreateObjectSpace();
                List <objManageAnimalSupplier>  listdetail     = new List <objManageAnimalSupplier>();
                ManageAnimalSupplier_Modelinfo2 item           = new ManageAnimalSupplier_Modelinfo2();
                QuotaType objQuotaType = ObjectSpace.FindObject <QuotaType>(CriteriaOperator.Parse(" GCRecord is null and  oid = ? ", quotatypeoid));
                IList <ManageSubAnimalSupplier> objmanageSubAnimalSupplier = ObjectSpace.GetObjects <ManageSubAnimalSupplier>(CriteriaOperator.Parse("ProvinceOid.OrganizationOid= '" + ManageAnimalSupplier + "' ", null));
                ManageSubAnimalSupplier         manageanimalsupplie        = ObjectSpace.FindObject <ManageSubAnimalSupplier>(CriteriaOperator.Parse(" GCRecord is null and  [ProvinceOid.OrganizationOid]= ? ", ManageAnimalSupplier));
                if (objQuotaType.QuotaName == "โควตาปศุสัตว์จังหวัด")
                {
                    QuotaType_Model itemquota = new QuotaType_Model();
                    item.QuotaName = objQuotaType.QuotaName;
                    //item.OrganizationOid = manageanimalsupplie.ManageAnimalSupplierOid.OrganizationOid.Oid.ToString();
                    //item.Organizationname = manageanimalsupplie.ManageAnimalSupplierOid.OrganizationOid.SubOrganizeName;

                    foreach (ManageSubAnimalSupplier row in objmanageSubAnimalSupplier)
                    {
                        objManageAnimalSupplier detail = new objManageAnimalSupplier();
                        detail.ProvinceOid  = row.ProvinceOid.Oid.ToString();
                        detail.Provincename = row.ProvinceOid.ProvinceNameTH;
                        listdetail.Add(detail);
                    }
                    item.detail = listdetail;
                }
                else
                {
                    item.QuotaName = objQuotaType.QuotaName;
                }

                return(Request.CreateResponse(HttpStatusCode.OK, item));
            }

            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));
            }
        }
Example #2
0
        public HttpResponseMessage QuotaType_list()
        {
            try
            {
                XpoTypesInfoHelper.GetXpoTypeInfoSource();
                XafTypesInfo.Instance.RegisterEntity(typeof(QuotaType));
                XPObjectSpaceProvider directProvider = new XPObjectSpaceProvider(scc, null);
                IObjectSpace          ObjectSpace    = directProvider.CreateObjectSpace();
                IList <QuotaType>     collection     = ObjectSpace.GetObjects <QuotaType>(CriteriaOperator.Parse(" GCRecord is null and IsActive = 1", null));

                if (collection.Count > 0)
                {
                    List <QuotaType_Model> list = new List <QuotaType_Model>();
                    foreach (QuotaType row in collection)
                    {
                        QuotaType_Model item = new QuotaType_Model();
                        item.QuotaTypeOid = row.Oid.ToString();
                        item.QuotaName    = row.QuotaName;

                        list.Add(item);
                    }
                    return(Request.CreateResponse(HttpStatusCode.OK, list));
                }
                else
                {
                    UserError err = new UserError();
                    err.code = "-1"; // error จากสาเหตุอื่นๆ จะมีรายละเอียดจาก system แจ้งกลับ

                    err.message = "ไม่พบข้อมูล";
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, err));
                }
            }
            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));
            }
        }
Example #3
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));
            }
        }