Ejemplo n.º 1
0
        public bool AddFromMobile(object data)
        {
            T_Planing_Action_AfterRemovalMobileDTO obj = null;
            List <SqlParameter> parameterList          = new List <SqlParameter>();

            string         procName    = "sp_T_Planing_Action_AfterRemoval_Insert_Mobile";
            string         TPID        = "";
            SqlConnection  conn        = null;
            SqlTransaction transaction = null;

            isCan = true;
            try
            {
                if (data != null)
                {
                    conn        = OpenConnection();
                    transaction = conn.BeginTransaction();

                    obj     = (T_Planing_Action_AfterRemovalMobileDTO)data;
                    command = new SqlCommand(procName, conn, transaction);

                    command.CommandType = CommandType.StoredProcedure;

                    parameterList.AddRange(GetParametersExactly(procName, obj, transaction).ToArray());
                    command.Parameters.AddRange(parameterList.ToArray());

                    command.ExecuteNonQuery();

                    TPID = obj.TPID;

                    if (obj.DeleteDefectFiles != null && obj.DeleteDefectFiles.Length > 0)
                    {
                        procName = "[sp_T_Planing_Action_AfterRemoval_Defect_Delete_Mobile]";
                        foreach (var fileNo in obj.DeleteDefectFiles.Split(','))
                        {
                            if (fileNo != "")
                            {
                                command = new SqlCommand(procName, conn, transaction);

                                command.CommandType = CommandType.StoredProcedure;
                                if (fileNo != null)
                                {
                                    T_PlaningFileMobileDTO file = new T_PlaningFileMobileDTO();
                                    file.PID        = TPID;
                                    file.No         = fileNo;
                                    file.UploadType = "1";
                                    parameterList   = new List <SqlParameter>();
                                    parameterList.AddRange(GetParametersExactly(procName, file, transaction).ToArray());

                                    command.Parameters.AddRange(parameterList.ToArray());
                                }

                                command.ExecuteNonQuery();
                            }
                        }
                    }

                    procName = "sp_T_Planing_Action_AfterRemoval_Files_Insert_Mobile";
                    if (obj.UploadFileList != null && obj.UploadFileList.Count > 0)
                    {
                        foreach (T_PlaningFileMobileDTO file in obj.UploadFileList)
                        {
                            file.TPID = TPID;

                            command = new SqlCommand(procName, conn, transaction);

                            command.CommandType = CommandType.StoredProcedure;
                            if (file != null)
                            {
                                parameterList = new List <SqlParameter>();
                                parameterList.AddRange(GetParametersExactly(procName, file, transaction).ToArray());

                                command.Parameters.AddRange(parameterList.ToArray());
                            }

                            command.ExecuteNonQuery();
                        }
                    }

                    procName = "[sp_T_Planing_Action_AfterRemoval_Defect_Insert_Mobile]";
                    if (obj.DefectList != null && obj.DefectList.Count > 0)
                    {
                        foreach (T_Planing_Action_AfterRemoval_DefectMobileDTO dto in obj.DefectList)
                        {
                            dto.TPID = TPID;

                            command = new SqlCommand(procName, conn, transaction);

                            command.CommandType = CommandType.StoredProcedure;
                            if (dto != null)
                            {
                                parameterList = new List <SqlParameter>();
                                parameterList.AddRange(GetParametersExactly(procName, dto, transaction).ToArray());

                                command.Parameters.AddRange(parameterList.ToArray());
                            }

                            command.ExecuteNonQuery();
                        }
                    }

                    procName = "[sp_T_Planing_Action_AfterRemoval_WallThickness_Insert_Mobile]";
                    if (obj.WallThicknessList != null && obj.WallThicknessList.Count > 0)
                    {
                        foreach (T_Planing_Action_AfterRemoval_WallThicknessMobileDTO dto in obj.WallThicknessList)
                        {
                            dto.TPID = TPID;

                            command = new SqlCommand(procName, conn, transaction);

                            command.CommandType = CommandType.StoredProcedure;
                            if (dto != null)
                            {
                                parameterList = new List <SqlParameter>();
                                parameterList.AddRange(GetParametersExactly(procName, dto, transaction).ToArray());

                                command.Parameters.AddRange(parameterList.ToArray());
                            }

                            command.ExecuteNonQuery();
                        }
                    }

                    transaction.Commit();
                }
            }
            catch (Exception ex)
            {
                isCan = false;
                if (transaction != null)
                {
                    transaction.Rollback();
                }
                throw new Exception(ex.Message);
            }
            finally
            {
                CloseConnection();
            }
            return(isCan);
        }
Ejemplo n.º 2
0
        public HttpResponseMessage Add()
        {
            var deserializer = new JavaScriptSerializer();
            T_Planing_Action_AfterRemovalMobileBAL mobileBal = new T_Planing_Action_AfterRemovalMobileBAL();
            ResposeType         response   = new ResposeType();
            HttpResponseMessage mapMessage = null;

            T_Planing_Action_AfterRemovalMobileDTO dto = null;
            List <T_Planing_Action_AfterRemoval_DefectMobileDTO>        defectList        = null;
            List <T_Planing_Action_AfterRemoval_WallThicknessMobileDTO> wallThicknessList = null;

            try
            {
                var context = HttpContext.Current;
                context.Response.ContentType = "multipart/form-data";

                dto = ConvertX.GetReqeustFormExactly <T_Planing_Action_AfterRemovalMobileDTO>();
                string UserID = context.Request.Form["UserID"];
                dto.CreateBy  = UserID;
                dto.UpdateBy  = UserID;
                dto.CreatedBy = UserID;
                dto.UpdatedBy = UserID;

                defectList            = deserializer.Deserialize <List <T_Planing_Action_AfterRemoval_DefectMobileDTO> >(context.Request.Form["defectInputList"]);
                wallThicknessList     = deserializer.Deserialize <List <T_Planing_Action_AfterRemoval_WallThicknessMobileDTO> >(context.Request.Form["wallThicknessInputList"]);
                dto.DefectList        = defectList;;
                dto.WallThicknessList = wallThicknessList;

                dto.UploadFileList = deserializer.Deserialize <List <T_PlaningFileMobileDTO> >(context.Request.Form["fileList"]);

                if (dto.UploadFileList != null && dto.UploadFileList.Count > 0)
                {
                    foreach (T_PlaningFileMobileDTO file in dto.UploadFileList)
                    {
                        file.DesPath  = context.Server.MapPath(planPath) + @"\" + file.PID + @"\" + file.UploadType;
                        file.FullPath = file.DesPath + @"\" + file.FileName;
                        logger.debug("PlanActionAfterAppliedCoating Add file:" + file.ToString());
                    }
                }

                dto.DefectNumber = dto.DefectList.Count.ToString();

                logger.debug("PlanActionAfterRemovalController Add dto:" + dto.ToString());
                if (dto.DefectList != null && dto.DefectList.Count > 0)
                {
                    foreach (T_Planing_Action_AfterRemoval_DefectMobileDTO defect in dto.DefectList)
                    {
                        logger.debug("PlanActionAfterRemovalController Add defect:" + defect.ToString());
                    }
                }
                if (dto.WallThicknessList != null && dto.WallThicknessList.Count > 0)
                {
                    foreach (T_Planing_Action_AfterRemoval_WallThicknessMobileDTO wall in dto.WallThicknessList)
                    {
                        logger.debug("PlanActionAfterRemovalController Add WallThickness:" + wall.ToString());
                    }
                }

                response.statusCode = mobileBal.AddFromMobile(dto);

                if (response.statusCode)
                {
                    response.statusText = "Success";
                    try {
                        // For new upload
                        if (dto.UploadFileList != null && dto.UploadFileList.Count > 0)
                        {
                            foreach (T_PlaningFileMobileDTO f in dto.UploadFileList)
                            {
                                if (DTO.PTT.Util.FileMng.HaveDirectory(f.DesPath))
                                {
                                    logger.debug("Save file to :" + f.FullPath);
                                    Utility.saveBase64File(f.FullPath, f.Base64File);
                                }
                            }
                        }

                        // For delete old file
                        if (dto.DeleteDefectFiles != null && dto.DeleteDefectFiles.Length > 0)
                        {
                            foreach (var fileName in dto.DeleteDefectFiles.Split(','))
                            {
                                if (fileName != "")
                                {
                                    var realDesFile = context.Server.MapPath(planPath) + @"\" + dto.PID + @"\" + fileName;
                                    DTO.PTT.Util.FileMng.DeleteFile(realDesFile);
                                }
                            }
                        }
                    }catch (Exception e)
                    {
                        response.statusText = "Success but process file error :" + e.ToString();
                    }
                }
            }
            catch (Exception ex)
            {
                logger.error("Add error:" + ex.ToString());
                response.statusText = ex.ToString();
            }

            mapMessage = Request.CreateResponse(HttpStatusCode.OK, response);
            return(mapMessage);
        }