public static CommonData.ReturnCode UpdateData(MeasureDTO dto)
        {
            CommonData.ReturnCode returnCode = CommonData.ReturnCode.Success;

            using (MySqlConnection connect = new MySqlConnection(constr))
            {
                using (MySqlCommand command = new MySqlCommand(
                           @"Update product_measure Set
                    `name` = @name, `description` = @description,
                    `updated_datetime` = SYSDATE(), `updated_by` = @updated_by Where `id` = @ID", connect))
                {
                    try
                    {
                        command.Parameters.AddWithValue("@name", dto.name);
                        command.Parameters.AddWithValue("@description", dto.description);
                        command.Parameters.AddWithValue("@updated_by", dto.updated_by);
                        command.Parameters.AddWithValue("@ID", dto.id);



                        connect.Open();
                        command.ExecuteNonQuery();
                    }
                    catch (Exception ex)
                    {
                        returnCode = CommonData.ReturnCode.UnSuccess;
                    }
                }
            }
            return(returnCode);
        }
Пример #2
0
        public static int CountPage(MeasureDTO dto)
        {
            DataTable tb         = new DataTable();
            int       returnCode = 0;
            string    constr     = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;

            using (MySqlConnection con = new MySqlConnection(constr))
            {
                using (MySqlCommand cmd = new MySqlCommand())
                {
                    string sql = @"SELECT Count(*) FROM product_measure WHERE TRUE";
                    if (dto.code.IsNotNullOrEmpty())
                    {
                        sql += " AND `code` = @code ";
                        cmd.Parameters.AddWithValue("@code", dto.code);
                    }
                    if (dto.code.IsNotNullOrEmpty())
                    {
                        sql += " AND `name` = @name ";
                        cmd.Parameters.AddWithValue("@name", dto.name);
                    }

                    con.Open();
                    cmd.Connection  = con;
                    cmd.CommandText = sql;
                    returnCode      = int.Parse(cmd.ExecuteScalar().ToString());
                }
            }
            return(returnCode);
        }
        public static CommonData.ReturnCode InsertData(MeasureDTO dto)
        {
            CommonData.ReturnCode returnCode = CommonData.ReturnCode.Success;
            try
            {
                using (MySqlConnection connect = new MySqlConnection(constr))
                {
                    using (MySqlCommand command = new MySqlCommand(
                               @"INSERT INTO product_measure(
                    `code`, `name`, `description`
                    , `created_datetime`, `created_by`,`updated_datetime`,`updated_by`
                    ) VALUES (
                    @code, @name, @description
                    , SYSDATE(), @created_by, SYSDATE(), @updated_by)", connect))
                    {
                        command.Parameters.AddWithValue("@code", dto.code);
                        command.Parameters.AddWithValue("@name", dto.name);
                        command.Parameters.AddWithValue("@description", dto.description);
                        command.Parameters.AddWithValue("@created_by", dto.created_by);
                        command.Parameters.AddWithValue("@updated_by", dto.updated_by);



                        connect.Open();
                        command.ExecuteNonQuery();
                    }
                }
            }
            catch (Exception ex)
            {
                returnCode = CommonData.ReturnCode.UnSuccess;
            }
            return(returnCode);
        }
Пример #4
0
        public ActionResult MeasureDelete(int id)
        {
            MeasureBL         bl         = new MeasureBL();
            List <MeasureDTO> dtResult   = new List <MeasureDTO>();
            MeasureDTO        measureDTO = new MeasureDTO();

            measureDTO.id = id;
            bl.SearchData(measureDTO, out dtResult);

            if (dtResult.Count() <= 0)
            {
                Response.StatusCode = 404;
                return(null);
            }
            else
            {
                int result = bl.DeleteData(id);
                if (result == 1)
                {
                    TempData["Error"]   = "Delete fail";
                    TempData["Success"] = "";
                }
                else
                {
                    TempData["Error"]   = "";
                    TempData["Success"] = "Delete sucessfully";
                }
            }
            return(RedirectToAction("MeasureSearch"));
        }
Пример #5
0
        public async Task <ActionResult <Response <Measure> > > PostMeasure(MeasureDTO measureDTO)
        {
            var thing = _context.Thing.AsNoTracking().Where(thing => thing.ThingId.Equals(measureDTO.ThingId)).FirstOrDefault();

            string message = string.Empty;

            if (thing == null)
            {
                message = $"Thing with Id {measureDTO.ThingId} not found";
            }
            else if (!thing.Features.ToString().Split(',', StringSplitOptions.RemoveEmptyEntries).Select(p => p.Trim()).ToList().Contains(measureDTO.Type.ToString().Trim()))
            {
                message = $"Thing with Id {measureDTO.ThingId} does not have the specified feature {measureDTO.Type}";
            }

            if (message != string.Empty)
            {
                Debug.WriteLine(message);
                return(BadRequest(new Response <Exception>(
                                      HttpStatusCode.BadRequest,
                                      message
                                      )));
            }

            Measure measure = new Measure(measureDTO);

            _context.Measure.Add(measure);
            await _context.SaveChangesAsync();

            await Notification(measure);

            return(CreatedAtAction("GetMeasure", new { id = measure.Id }, measure));
        }
Пример #6
0
        public static int SearchData(MeasureDTO inputData, out List <MeasureDTO> dt)
        {
            dt = new List <MeasureDTO>();
            DataTable tb         = new DataTable();
            int       returnCode = 0;
            string    constr     = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;

            using (MySqlConnection con = new MySqlConnection(constr))
            {
                using (MySqlCommand cmd = new MySqlCommand())
                {
                    string sql = "SELECT `id`,`code`, `name`,`description` FROM product_measure WHERE TRUE ";
                    if (inputData.id.HasValue)
                    {
                        sql += " AND `id` = @ID ";
                        cmd.Parameters.AddWithValue("@ID", inputData.id);
                    }
                    if (inputData.name.IsNotNullOrEmpty())
                    {
                        sql += " AND `name` LIKE CONCAT('%',@name,'%')";
                        cmd.Parameters.AddWithValue("@name", inputData.name);
                    }
                    if (inputData.code.IsNotNullOrEmpty())
                    {
                        sql += " AND `code` LIKE CONCAT('%',@code,'%')";
                        cmd.Parameters.AddWithValue("@code", inputData.code);
                    }
                    sql += " LIMIT  @start, 20 ";
                    cmd.Parameters.AddWithValue("@start", 20 * (inputData.page - 1));
                    cmd.Connection  = con;
                    cmd.CommandText = sql;
                    using (MySqlDataAdapter sda = new MySqlDataAdapter())
                    {
                        sda.SelectCommand = cmd;
                        sda.Fill(tb);
                        if (tb.Rows.Count == 0)
                        {
                            returnCode = 1;
                        }
                        if (tb.Rows.Count > 0)
                        {
                            foreach (DataRow item in tb.Rows)
                            {
                                MeasureDTO dto = new MeasureDTO();
                                dto.id   = int.Parse(item["id"].ToString());
                                dto.code = item["code"].ToString();
                                dto.name = item["name"].ToString();
                                if (item["description"].ToString().IsNotNullOrEmpty())
                                {
                                    dto.description = item["description"].ToString();
                                }
                                dt.Add(dto);
                            }
                        }
                    }
                }
            }

            return(returnCode);
        }
Пример #7
0
        public ActionResult Update(string id)
        {
            if (!id.IsNotNullOrEmpty())
            {
                TempData["Error"] = "Data has already been deleted by other user!";
                return(RedirectToAction("Measure"));
            }

            MeasureDTO model = new MeasureDTO();

            if (id.IsNumber())
            {
                List <MeasureDTO> list;
                measureBL.SearchData(new MeasureDTO {
                    id = int.Parse(id)
                }, out list);
                if (list.Count > 0)
                {
                    model = list[0];
                }
                else
                {
                    TempData["Error"] = "Data has already been deleted by other user!";
                    return(RedirectToAction("Measure"));
                }
            }
            else
            {
                TempData["Error"] = "Error exception";
                return(RedirectToAction("Measure"));
            }
            return(View(model));
        }
Пример #8
0
        public ActionResult MeasureSearch(string Page, MeasureSearch model)
        {
            MeasureDTO dto = new MeasureDTO();

            ModelState.Clear();
            if (!string.IsNullOrEmpty(model.SearchButton) || Page.IsNotNullOrEmpty())
            {
                if (Page != null)
                {
                    dto.page   = int.Parse(Page);
                    model.Page = dto.page;
                }
                MeasureBL         bl     = new MeasureBL();
                List <MeasureDTO> result = new List <MeasureDTO>();
                if (model.MeasureCode.IsNotNullOrEmpty())
                {
                    dto.code = model.MeasureCode;
                }
                if (model.MeasureName.IsNotNullOrEmpty())
                {
                    dto.name = model.MeasureName;
                }
                bl.SearchData(dto, out result);
                model.PageCount     = bl.PageCount(dto);
                model.SearchResults = new StaticPagedList <MeasureDTO>(result, model.Page, 20, model.PageCount);
            }


            return(View(model));
        }
Пример #9
0
 public ActionResult MeasureAdd(MeasureDTO measure)
 {
     if (ModelState.IsValid)
     {
         MeasureBL bl = new MeasureBL();
         if (bl.CheckCode(measure) > 0)
         {
             TempData["Error"]   = "Code already exsit";
             TempData["Success"] = "";
         }
         else
         {
             measure.created_by = 0;
             measure.updated_by = 0;
             int result = bl.InsertData(measure);
             if (result == 1)
             {
                 TempData["Error"]   = "Insert fail";
                 TempData["Success"] = "";
             }
             else
             {
                 TempData["Error"]   = "";
                 TempData["Success"] = "Insert successfully";
                 return(RedirectToAction("MeasureAdd"));
             }
         }
     }
     return(View(measure));
 }
Пример #10
0
        public ActionResult UpdateMeasure(MeasureDTO measure)
        {
            MeasureBL mesureBL = new MeasureBL();

            try
            {
                if (ModelState.IsValid)
                {
                    measure.created_by = 123;
                    measure.updated_by = 123;
                    mesureBL.UpdateData(measure);
                    return(RedirectToAction("Measure"));
                }
            }
            catch (DataException dex)
            {
                ModelState.AddModelError("", "Unable to perform action. Please contact us.");
                return(RedirectToAction("SubmissionFailed", measure));
            }
            measure = new MeasureDTO()
            {
                id = measure.id
            };
            return(View("Update"));
        }
Пример #11
0
        public ActionResult UpdateMeasure(MeasureDTO measure)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    measure.created_by = 123;
                    measure.updated_by = 123;


                    CommonData.ReturnCode returnCode = measureBL.UpdateData(measure);
                    if (returnCode == CommonData.ReturnCode.Success)
                    {
                        TempData["Success"] = "Update Successfully!";
                    }
                    else
                    {
                        TempData["Error"] = "Update fail";
                    }
                    Session["model.Measure"] = null;
                    return(RedirectToAction("Measure"));
                }
            }
            catch (DataException dex)
            {
                ModelState.AddModelError("", "Lỗi không xác định");
                return(RedirectToAction("SubmissionFailed", measure));
            }

            return(View("Update", measure));
        }
Пример #12
0
 public IActionResult Post(MeasureDTO measure)
 {
     if (measure == null)
     {
         return(BadRequest());
     }
     Measures.Add(DTO.FromDTO(measure));
     return(Ok(measure));
 }
Пример #13
0
        // GET: Measure
        public ActionResult MeasureSearch(MeasureDTO measure)
        {
            MeasureBL   bl    = new MeasureBL();
            MeasureList model = new MeasureList();
            DataTable   dt;

            bl.SearchData(measure, out dt);
            model.Measures = CommonMethod.DataTableToList <MeasureDTO>(dt);
            return(View(model));
        }
Пример #14
0
        public ActionResult MeasureUpdate(int id)
        {
            ModelState.Clear();
            MeasureBL         bl       = new MeasureBL();
            List <MeasureDTO> dtResult = new List <MeasureDTO>();
            MeasureDTO        measure  = new MeasureDTO();

            measure.id = id;
            bl.SearchData(measure, out dtResult);
            measure = dtResult[0];
            return(View(measure));
        }
Пример #15
0
 public IActionResult Put(int id, MeasureDTO measure)
 {
     if (measure == null)
     {
         return(BadRequest());
     }
     if (Measures.Read(id) == null)
     {
         return(NotFound());
     }
     Measures.Edit(id, DTO.FromDTO(measure));
     return(Ok(measure));
 }
Пример #16
0
        public ActionResult AddMeasure(MeasureDTO measure)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (!measure.code.Contains(" "))
                    {
                        int count = measureBL.CountData(new MeasureDTO()
                        {
                            code_key = measure.code
                        });
                        if (count == 0)
                        {
                            measure.created_by = 123;
                            measure.updated_by = 123;
                            CommonData.ReturnCode returnCode = measureBL.InsertData(measure);
                            if (returnCode == CommonData.ReturnCode.Success)
                            {
                                TempData["Success"] = "Inserted Successfully!";
                            }
                            else
                            {
                                TempData["Error"] = "Insert fail";
                            }
                            Session["model.Measure"] = null;
                            return(RedirectToAction("Measure"));
                        }
                        else
                        {
                            ModelState.AddModelError("code", "The Code already is existed!");
                            return(RedirectToAction("Add"));
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("code", "The code must not have spaces ");
                    }
                }
                else
                {
                }
            }
            catch (DataException dex)
            {
                ModelState.AddModelError("", "Lỗi không xác định");
            }

            return(View("Add", measure));
        }
        public async Task Post(MeasureDTO measure)
        {
            MeasureModel measureModel = _mapper.Map <MeasureModel>(measure);

            measureModel.Status = MeasureStatus.Pending;
            MeasureModel newMeasureModel = await _measureService.Add(measureModel);

            await _messageSession.Publish <IMeasureAdded>(message =>
            {
                message.MeasureId  = newMeasureModel.Id;
                message.Weight     = measure.Weight;
                message.UserFileId = measure.UserFileId;
            });
        }
Пример #18
0
        public async Task <ActionResult> AddMeasureAsync([FromBody] MeasureDTO measureDTO)
        {
            MeasureModel measureModel = _mapper.Map <MeasureModel>(measureDTO);
            int          measureId    = await _measureService.AddMeasureAsync(measureModel);

            MeasureAdded measureAdded = new MeasureAdded
            {
                MeasureId = measureId,
                CardId    = measureModel.CardId,
                Weight    = measureModel.Weight
            };
            await _messageSession.Publish(measureAdded)
            .ConfigureAwait(false);

            return(Ok("הפעולה נקלטה בהצלחה!"));
        }
Пример #19
0
        public async Task <IActionResult> PutMeasure(long Id, MeasureDTO measureDTO)
        {
            var measure = await _context.Measure.FindAsync(Id);

            if (measure == null)
            {
                return(NotFound());
            }

            var thing = _context.Thing.AsNoTracking().Where(thing => thing.ThingId.Equals(measureDTO.ThingId)).FirstOrDefault();

            string message = string.Empty;

            if (thing == null)
            {
                message = $"Thing with Id {measureDTO.ThingId} not found";
            }
            else if (!thing.Features.ToString().Split(',', StringSplitOptions.RemoveEmptyEntries).Select(p => p.Trim()).ToList().Contains(measureDTO.Type.ToString().Trim()))
            {
                message = $"Thing with Id {measureDTO.ThingId} does not have the specified feature {measureDTO.Type}";
            }

            if (message != string.Empty)
            {
                Debug.WriteLine(message);
                return(BadRequest(new Response <Exception>(
                                      HttpStatusCode.BadRequest,
                                      message
                                      )));
            }

            measure.MapFromDTO(measureDTO);

            _context.Entry(measure).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                throw;
            }

            return(NoContent());
        }
        public static int CountData(MeasureDTO dto)
        {
            int count = 0;

            using (MySqlConnection con = new MySqlConnection(constr))
            {
                using (MySqlCommand cmd = new MySqlCommand())
                {
                    string sql = " SELECT COUNT(*) FROM product_measure m WHERE TRUE ";


                    #region Where Clause
                    if (dto.id != null)
                    {
                        sql += " AND m.`id` = @ID ";
                        cmd.Parameters.AddWithValue("@ID", dto.id);
                    }

                    if (dto.code_key.IsNotNullOrEmpty())
                    {
                        sql += " AND m.`code` = @Code ";
                        cmd.Parameters.AddWithValue("@Code", dto.code_key);
                    }

                    if (dto.code.IsNotNullOrEmpty())
                    {
                        sql += " AND m.`code` LIKE CONCAT('%',@Code,'%') ";
                        cmd.Parameters.AddWithValue("@Code", dto.code);
                    }

                    if (dto.name.IsNotNullOrEmpty())
                    {
                        sql += " AND m.`name` LIKE CONCAT('%',@Name,'%') ";
                        cmd.Parameters.AddWithValue("@Name", dto.name);
                    }
                    #endregion

                    con.Open();
                    cmd.Connection  = con;
                    cmd.CommandText = sql;
                    count           = int.Parse(cmd.ExecuteScalar().ToString());
                }
            }
            return(count);
        }
        public static MeasureEN Convert(MeasureDTO dto)
        {
            MeasureEN newinstance = null;

            try
            {
                if (dto != null)
                {
                    newinstance = new MeasureEN();



                    newinstance.Id          = dto.Id;
                    newinstance.Name        = dto.Name;
                    newinstance.Description = dto.Description;
                    if (dto.Target_oid != null)
                    {
                        MoSIoTGenNHibernate.CAD.MosIoT.ITargetCAD targetCAD = new MoSIoTGenNHibernate.CAD.MosIoT.TargetCAD();

                        newinstance.Target = new System.Collections.Generic.List <MoSIoTGenNHibernate.EN.MosIoT.TargetEN>();
                        foreach (int entry in dto.Target_oid)
                        {
                            newinstance.Target.Add(targetCAD.ReadOIDDefault(entry));
                        }
                    }
                    if (dto.Telemetry_oid != null)
                    {
                        MoSIoTGenNHibernate.CAD.MosIoT.ITelemetryCAD telemetryCAD = new MoSIoTGenNHibernate.CAD.MosIoT.TelemetryCAD();

                        newinstance.Telemetry = new System.Collections.Generic.List <MoSIoTGenNHibernate.EN.MosIoT.TelemetryEN>();
                        foreach (int entry in dto.Telemetry_oid)
                        {
                            newinstance.Telemetry.Add(telemetryCAD.ReadOIDDefault(entry));
                        }
                    }
                    newinstance.LOINCcode = dto.LOINCcode;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(newinstance);
        }
Пример #22
0
        public static int UpdateData(MeasureDTO dto)
        {
            int    returnCode = 0;
            string constr     = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;

            using (MySqlConnection connect = new MySqlConnection(constr))
            {
                using (MySqlCommand command = new MySqlCommand(
                           @"UPDATE product_measure SET `name`=@name, `description`=@description
                    ,`updated_datetime`=SYSDATE(),`updated_by`=@updated_by WHERE `id`=@id", connect))
                {
                    command.Parameters.AddWithValue("@id", dto.id);
                    command.Parameters.AddWithValue("@name", dto.name);
                    command.Parameters.AddWithValue("@description", dto.description);
                    command.Parameters.AddWithValue("@updated_by", dto.updated_by);
                    connect.Open();
                    command.ExecuteNonQuery();
                }
            }
            return(returnCode);
        }
Пример #23
0
        public void AddEditMeasure(MeasureDTO measure)
        {
            using (var session = Hibernate.SessionFactory.OpenSession())
            {
                Measure m      = null;
                Measure entity = null;

                if (measure.Id != null)
                {
                    entity = session.QueryOver(() => m).Where(() => m.Id == measure.Id.Value).SingleOrDefault();
                }
                else
                {
                    entity = new Measure();
                }

                entity.Name = measure.Name;

                session.SaveOrUpdate(entity);
                session.Flush();
            }
        }
Пример #24
0
        public ActionResult Update(string id)
        {
            MeasureDTO dto = new MeasureDTO();

            if (id.IsNumber())
            {
                List <MeasureDTO> list;
                MeasureBL         bl = new MeasureBL();
                dto.id = int.Parse(id);
                bl.SearchData(dto, out list);
                if (list.Count > 0)
                {
                    dto = list[0];
                }
                else
                {
                    TempData["Success"] = "0 row(s) has found.";
                    return(RedirectToAction("Measure"));
                }
            }
            return(View(dto));
        }
Пример #25
0
        public void Should_Update_Measures_Collection(FoodDTO foodDto, MeasureDTO measureDto1, MeasureDTO measureDto2)
        {
            foodDto.FoodId = 0;
            foodDto.MeasureDtos.ForEach(p => p.MeasureId = 0);
            measureDto1.MeasureId = 0;
            measureDto2.MeasureId = 0;
            var measureCount = foodDto.MeasureDtos.Count;
            var id           = _foodService.AddFood(foodDto);
            var resultList   = _foodService.Search(id).ToList();

            resultList.Should().HaveCount(1);

            var dto = resultList[0];

            var updatedElement = dto.MeasureDtos.ToList()[0];

            updatedElement.Calories = updatedElement.Calories + 100;

            var toRemove = dto.MeasureDtos.ToList()[1];

            dto.MeasureDtos.Remove(toRemove);

            dto.MeasureDtos.Add(measureDto1);
            dto.MeasureDtos.Add(measureDto2);

            _foodService.UpdateFood(dto);

            resultList = _foodService.Search(id).ToList();
            resultList.Should().HaveCount(1);

            resultList[0].MeasureDtos.Should().HaveCount(measureCount + 1);
            resultList[0].MeasureDtos.Where(p => p.Description == measureDto1.Description).Should().HaveCount(1);
            resultList[0].MeasureDtos.Where(p => p.Description == measureDto2.Description).Should().HaveCount(1);
            resultList[0].MeasureDtos.Single(p => p.MeasureId == updatedElement.MeasureId)
            .Calories.Should()
            .Be(updatedElement.Calories);
            resultList[0].MeasureDtos.Where(p => p.MeasureId == toRemove.MeasureId).Should().BeEmpty();
        }
Пример #26
0
        public ActionResult MeasureUpdate(MeasureDTO measure)
        {
            if (ModelState.IsValid)
            {
                MeasureBL bl = new MeasureBL();
                measure.created_by = 0;
                measure.updated_by = 0;
                int result = bl.UpdateData(measure);
                if (result == 1)
                {
                    TempData["Error"]   = "Update fail";
                    TempData["Success"] = "";
                }
                else
                {
                    TempData["Error"]   = "";
                    TempData["Success"] = "Update successfully";
                }
                return(RedirectToAction("MeasureSearch"));
            }

            return(View(measure));
        }
Пример #27
0
        public ActionResult AddMeasure(MeasureDTO mesure)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    mesure.created_by = 113;
                    MeasureBL categorybl = new MeasureBL();
                    if (mesure.code.Contains(" "))
                    {
                        TempData["Error"] = "Don't input Space in Measure Code";
                        return(View("Add"));
                    }
                    int count = categorybl.CountData(new MeasureDTO()
                    {
                        code = mesure.code
                    });
                    if (count == 0)
                    {
                        categorybl.InsertData(mesure);
                    }
                    else
                    {
                        TempData["Error"] = "The Code already is exister!";
                        return(View("Add"));
                    }
                    return(RedirectToAction("Measure"));
                }
            }
            catch (DataException dex)
            {
                ModelState.AddModelError("", "Unable to perform action. Please contact us.");
                return(RedirectToAction("SubmissionFailed", mesure));
            }

            return(View("Add"));
        }
Пример #28
0
        public static int SearchList(out List <MeasureDTO> dt)
        {
            dt = new List <MeasureDTO>();
            DataTable tb         = new DataTable();
            int       returnCode = 0;
            string    constr     = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;

            using (MySqlConnection con = new MySqlConnection(constr))
            {
                using (MySqlCommand cmd = new MySqlCommand("SELECT ct.ID, ct.Name, ct.Code FROM product_measure ct WHERE TRUE ", con))
                {
                    using (MySqlDataAdapter sda = new MySqlDataAdapter())
                    {
                        sda.SelectCommand = cmd;
                        sda.Fill(tb);
                        if (tb.Rows.Count == 0)
                        {
                            returnCode = 1;
                        }
                        else
                        {
                            foreach (DataRow item in tb.Rows)
                            {
                                MeasureDTO dto = new MeasureDTO();
                                dto.id   = int.Parse(item["id"].ToString());
                                dto.code = item["code"].ToString();
                                dto.name = item["name"].ToString();
                                dt.Add(dto);
                            }
                        }
                    }
                }
            }

            return(returnCode);
        }
Пример #29
0
        public ActionResult MeasureDeleteMulti(FormCollection frm)
        {
            string[]  ids = frm["MeasureID"].Split(new char[] { ',' });
            MeasureBL bl  = new MeasureBL();

            foreach (string item in ids)
            {
                MeasureDTO measureDTO = new MeasureDTO();
                int        id         = item.ParseInt32();
                measureDTO.id = id;
                List <MeasureDTO> dtos = new List <MeasureDTO>();
                int returncode         = bl.SearchData(measureDTO, out dtos);
                if (returncode == 1)
                {
                    Response.StatusCode = 404;
                    return(null);
                }
                else
                {
                    bl.DeleteData(id);
                }
            }
            return(RedirectToAction("MeasureSearch"));
        }
Пример #30
0
        public static int SearchData(MeasureDTO inputDto, out DataTable dt)
        {
            dt = new DataTable();
            int    returnCode = 0;
            string constr     = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;

            using (MySqlConnection con = new MySqlConnection(constr))
            {
                using (MySqlCommand cmd = new MySqlCommand("SELECT * FROM product_measure", con))
                {
                    using (MySqlDataAdapter sda = new MySqlDataAdapter())
                    {
                        sda.SelectCommand = cmd;
                        sda.Fill(dt);
                        if (dt.Rows.Count == 0)
                        {
                            returnCode = 1;
                        }
                    }
                }
            }

            return(returnCode);
        }