public async Task <IActionResult> UpdateDocMenuC2Edit([FromBody] ModelMenuC2 model)
        {
            ModelResponseC2Message e = await _IDocMenuCService.UpdateDocMenuC2EditAsync(model);

            if (e.Status)
            {
                return(Ok(e));
            }
            else
            {
                return(BadRequest());
            }
        }
        public async Task <IActionResult> AddDocMenuC2([FromBody] ModelMenuC2 model)
        {
            IActionResult _result = BadRequest();

            ModelResponseC2Message e = await _IDocMenuCService.AddDocMenuC2Async(model);

            if (e.Status)
            {
                return(Ok(e));
            }
            else
            {
                return(BadRequest());
            }
        }
        public async Task <ModelResponseC2Message> UpdateDocMenuC2EditAsync(ModelMenuC2 model)
        {
            var cultureInfo = new CultureInfo("en-GB");

            CultureInfo.DefaultThreadCurrentCulture   = cultureInfo;
            CultureInfo.DefaultThreadCurrentUICulture = cultureInfo;

            ModelResponseC2Message resp = new ModelResponseC2Message();

            try
            {
                using (SqlConnection conn = new SqlConnection(ConnectionString))
                {
                    conn.Open();
                    using (SqlCommand cmd = new SqlCommand("sp_doc_menu_c2_edit", conn))
                    {
                        cmd.CommandType = CommandType.StoredProcedure;

                        string assigner_code = Encoding.UTF8.GetString(Convert.FromBase64String(model.assignercode));

                        cmd.Parameters.Add("@doc_id", SqlDbType.Int).Value = model.docid;
                        cmd.Parameters.Add("@assigner_code", SqlDbType.VarChar, 50).Value      = ParseDataHelper.ConvertDBNull(assigner_code);
                        cmd.Parameters.Add("@position_name", SqlDbType.VarChar, 200).Value     = ParseDataHelper.ConvertDBNull(model.positionname);
                        cmd.Parameters.Add("@assigner_seq", SqlDbType.Int).Value               = ParseDataHelper.ConvertDBNull(model.assignerseq);
                        cmd.Parameters.Add("@project_number", SqlDbType.VarChar, 20).Value     = ParseDataHelper.ConvertDBNull(model.projectnumber);
                        cmd.Parameters.Add("@project_head_name", SqlDbType.VarChar, 200).Value = ParseDataHelper.ConvertDBNull(model.projectheadname);
                        cmd.Parameters.Add("@faculty_name", SqlDbType.VarChar, 200).Value      = ParseDataHelper.ConvertDBNull(model.facultyname);
                        cmd.Parameters.Add("@project_name_thai", SqlDbType.VarChar, 200).Value = ParseDataHelper.ConvertDBNull(model.projectnamethai);
                        cmd.Parameters.Add("@project_name_eng", SqlDbType.VarChar, 200).Value  = ParseDataHelper.ConvertDBNull(model.projectnameeng);
                        cmd.Parameters.Add("@safety_type", SqlDbType.VarChar, 2).Value         = ParseDataHelper.ConvertDBNull(model.safetytype);
                        cmd.Parameters.Add("@approval_type", SqlDbType.VarChar, 2).Value       = ParseDataHelper.ConvertDBNull(model.approvaltype);
                        cmd.Parameters.Add("@comment_consider", SqlDbType.VarChar).Value       = ParseDataHelper.ConvertDBNull(model.commentconsider);
                        cmd.Parameters.Add("@round_of_meeting", SqlDbType.Int).Value           = model.roundofmeeting;
                        cmd.Parameters.Add("@year_of_meeting", SqlDbType.Int).Value            = model.yearofmeeting;
                        cmd.Parameters.Add("@create_by", SqlDbType.VarChar, 50).Value          = Encoding.UTF8.GetString(Convert.FromBase64String(model.createby));

                        SqlParameter rStatus = cmd.Parameters.Add("@rStatus", SqlDbType.Int);
                        rStatus.Direction = ParameterDirection.Output;
                        SqlParameter rMessage = cmd.Parameters.Add("@rMessage", SqlDbType.NVarChar, 500);
                        rMessage.Direction = ParameterDirection.Output;

                        await cmd.ExecuteNonQueryAsync();

                        if ((int)cmd.Parameters["@rStatus"].Value > 0)
                        {
                            resp.Status = true;

                            model_rpt_10_file rpt = await _IDocMenuReportRepository.GetReportR10Async(Convert.ToInt32(model.docid));

                            resp.filename   = rpt.filename;
                            resp.filebase64 = rpt.filebase64;
                        }
                        else
                        {
                            resp.Message = (string)cmd.Parameters["@rMessage"].Value;
                        }
                    }
                    conn.Close();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(resp);
        }
        private async Task <ModelMenuC2> GetMenuC2DataEditAsync(int docid, string userid, ModelPermissionPage permission)
        {
            string user_id = Encoding.UTF8.GetString(Convert.FromBase64String(userid));

            string sql = "SELECT TOP(1) A.*, (D.first_name + ' ' + D.full_name) AS assigner_name, B.name_thai AS safety_type_name, " +
                         "(C.name_thai + ' ' + C.name_thai_sub) AS approval_type_name, E.meeting_date " +
                         "FROM [dbo].[Doc_MenuC2] A " +
                         "LEFT OUTER JOIN[dbo].[MST_Safety] B ON A.safety_type = B.id " +
                         "LEFT OUTER JOIN[dbo].[MST_ApprovalType] C ON A.approval_type = C.id " +
                         "LEFT OUTER JOIN[dbo].[RegisterUser] D ON A.assigner_code = D.register_id " +
                         "LEFT OUTER JOIN Transaction_Document E ON A.project_number = E.project_number " +
                         "WHERE A.doc_id='" + docid + "' " +
                         (permission.alldata == true ? "" : " AND A.create_by = '" + user_id + "'") +
                         "ORDER BY A.doc_id DESC";

            using (SqlConnection conn = new SqlConnection(ConnectionString))
            {
                conn.Open();
                using (SqlCommand command = new SqlCommand(sql, conn))
                {
                    SqlDataReader reader = await command.ExecuteReaderAsync();

                    if (reader.HasRows)
                    {
                        ModelMenuC2 e = new ModelMenuC2();
                        while (await reader.ReadAsync())
                        {
                            string assigner_code = System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(reader["assigner_code"].ToString()));

                            e.docid            = reader["doc_id"].ToString();
                            e.assignercode     = assigner_code;
                            e.assignername     = reader["assigner_name"].ToString();
                            e.positionname     = reader["position_name"].ToString();
                            e.assignerseq      = reader["assigner_seq"].ToString();
                            e.projectnumber    = reader["project_number"].ToString();
                            e.projectheadname  = reader["project_head_name"].ToString();
                            e.facultyname      = reader["faculty_name"].ToString();
                            e.projectnamethai  = reader["project_name_thai"].ToString();
                            e.projectnameeng   = reader["project_name_eng"].ToString();
                            e.safetytype       = reader["safety_type"].ToString();
                            e.safetytypename   = reader["safety_type_name"].ToString();
                            e.approvaltype     = reader["approval_type"].ToString();
                            e.approvaltypename = reader["approval_type_name"].ToString();
                            e.commentconsider  = reader["comment_consider"].ToString();
                            e.roundofmeeting   = reader["round_of_meeting"].ToString();
                            e.yearofmeeting    = reader["year_of_meeting"].ToString();
                            e.createby         = reader["create_by"].ToString();

                            //Default Edit False
                            e.editenable = false;
                            if (permission.edit == true)
                            {
                                if (string.IsNullOrEmpty(reader["meeting_date"].ToString()))
                                {
                                    if (user_id == reader["create_by"].ToString())
                                    {
                                        e.editenable = true;
                                    }
                                }
                            }
                        }
                        return(e);
                    }
                }
                conn.Close();
            }
            return(null);
        }
        public async Task <ModelResponseC2Message> AddDocMenuC2Async(ModelMenuC2 model)
        {
            var cultureInfo = new CultureInfo("en-GB");

            CultureInfo.DefaultThreadCurrentCulture   = cultureInfo;
            CultureInfo.DefaultThreadCurrentUICulture = cultureInfo;

            ModelResponseC2Message resp = new ModelResponseC2Message();

            try
            {
                using (SqlConnection conn = new SqlConnection(ConnectionString))
                {
                    conn.Open();

                    IList <ModelSelectOption> list_assign_seq = new List <ModelSelectOption>();
                    int assig_seq = 0;

                    string sqlA = "SELECT board_code_array FROM Doc_MenuC1 WHERE project_number='" + model.projectnumber + "'";

                    using (SqlCommand cmdA = new SqlCommand(sqlA, conn))
                    {
                        SqlDataReader reader = await cmdA.ExecuteReaderAsync();

                        if (reader.HasRows)
                        {
                            while (await reader.ReadAsync())
                            {
                                list_assign_seq = JsonConvert.DeserializeObject <List <ModelSelectOption> >(reader["board_code_array"].ToString());
                            }
                            if (list_assign_seq != null && list_assign_seq.Count > 0)
                            {
                                int seq = 1;
                                foreach (var item in list_assign_seq)
                                {
                                    if (item.value == model.assignercode)
                                    {
                                        assig_seq = seq;
                                    }
                                    seq++;
                                }
                            }
                        }
                        reader.Close();
                    }



                    StringBuilder array_comment_date = new StringBuilder();

                    string sqlB = "SELECT committee_comment_date FROM Transaction_Document WHERE project_number='" + model.projectnumber + "'";

                    using (SqlCommand cmdB = new SqlCommand(sqlB, conn))
                    {
                        SqlDataReader reader = await cmdB.ExecuteReaderAsync();

                        if (reader.HasRows)
                        {
                            while (await reader.ReadAsync())
                            {
                                array_comment_date.AppendLine(reader["committee_comment_date"].ToString().Trim());

                                array_comment_date.AppendLine("คนที่ " + assig_seq.ToString() + ". " + DateTime.Now.ToString("dd/MM/yyyy"));
                            }
                        }
                        reader.Close();
                    }



                    using (SqlCommand cmd = new SqlCommand("sp_doc_menu_c2", conn))
                    {
                        cmd.CommandType = CommandType.StoredProcedure;

                        string assigner_code = Encoding.UTF8.GetString(Convert.FromBase64String(model.assignercode));

                        cmd.Parameters.Add("@assigner_code", SqlDbType.VarChar, 50).Value           = ParseDataHelper.ConvertDBNull(assigner_code);
                        cmd.Parameters.Add("@position_name", SqlDbType.VarChar, 200).Value          = ParseDataHelper.ConvertDBNull(model.positionname);
                        cmd.Parameters.Add("@assigner_seq", SqlDbType.Int).Value                    = ParseDataHelper.ConvertDBNull(model.assignerseq);
                        cmd.Parameters.Add("@project_number", SqlDbType.VarChar, 20).Value          = ParseDataHelper.ConvertDBNull(model.projectnumber);
                        cmd.Parameters.Add("@project_head_name", SqlDbType.VarChar, 200).Value      = ParseDataHelper.ConvertDBNull(model.projectheadname);
                        cmd.Parameters.Add("@faculty_name", SqlDbType.VarChar, 200).Value           = ParseDataHelper.ConvertDBNull(model.facultyname);
                        cmd.Parameters.Add("@project_name_thai", SqlDbType.VarChar, 200).Value      = ParseDataHelper.ConvertDBNull(model.projectnamethai);
                        cmd.Parameters.Add("@project_name_eng", SqlDbType.VarChar, 200).Value       = ParseDataHelper.ConvertDBNull(model.projectnameeng);
                        cmd.Parameters.Add("@safety_type", SqlDbType.VarChar, 2).Value              = ParseDataHelper.ConvertDBNull(model.safetytype);
                        cmd.Parameters.Add("@approval_type", SqlDbType.VarChar, 2).Value            = ParseDataHelper.ConvertDBNull(model.approvaltype);
                        cmd.Parameters.Add("@comment_consider", SqlDbType.VarChar).Value            = ParseDataHelper.ConvertDBNull(model.commentconsider);
                        cmd.Parameters.Add("@committee_comment_date", SqlDbType.VarChar, 200).Value = ParseDataHelper.ConvertDBNull(array_comment_date.ToString());
                        cmd.Parameters.Add("@round_of_meeting", SqlDbType.Int).Value                = model.roundofmeeting;
                        cmd.Parameters.Add("@year_of_meeting", SqlDbType.Int).Value                 = model.yearofmeeting;
                        cmd.Parameters.Add("@create_by", SqlDbType.VarChar, 50).Value               = Encoding.UTF8.GetString(Convert.FromBase64String(model.createby));

                        SqlParameter rStatus = cmd.Parameters.Add("@rStatus", SqlDbType.Int);
                        rStatus.Direction = ParameterDirection.Output;
                        SqlParameter rMessage = cmd.Parameters.Add("@rMessage", SqlDbType.NVarChar, 500);
                        rMessage.Direction = ParameterDirection.Output;
                        SqlParameter rDocId = cmd.Parameters.Add("@rDocId", SqlDbType.Int);
                        rDocId.Direction = ParameterDirection.Output;

                        await cmd.ExecuteNonQueryAsync();

                        if ((int)cmd.Parameters["@rStatus"].Value > 0)
                        {
                            resp.Status = true;

                            model_rpt_10_file rpt = await _IDocMenuReportRepository.GetReportR10Async((int)cmd.Parameters["@rDocId"].Value);

                            resp.filename   = rpt.filename;
                            resp.filebase64 = rpt.filebase64;
                        }
                        else
                        {
                            resp.Message = (string)cmd.Parameters["@rMessage"].Value;
                        }
                    }
                    conn.Close();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(resp);
        }
Exemple #6
0
        public async Task <ModelResponseC2Message> UpdateDocMenuC2EditAsync(ModelMenuC2 model)
        {
            var resp = await _IDocMenuC2Repository.UpdateDocMenuC2EditAsync(model);

            return(resp);
        }
Exemple #7
0
        public async Task <ModelResponseC2Message> AddDocMenuC2Async(ModelMenuC2 model)
        {
            var resp = await _IDocMenuC2Repository.AddDocMenuC2Async(model);

            return(resp);
        }