コード例 #1
0
        protected void btnAddChange_Click(object sender, EventArgs e)
        {
            List <int> membersList = new List <int>();

            foreach (GridViewRow row in gvMembersOfCommittee.Rows)
            {
                int member = Convert.ToInt32(row.Cells[1].Text);
                membersList.Add(member);
            }
            string apiUrl2  = Utilities.BASE_URL + "/api/CommitteesMembers";
            int    memberId = WebApiConsume.GetUserId(Utilities.BASE_URL + "/api/Users", ddlMemberChange.SelectedItem.Text);

            if (!membersList.Contains(memberId))
            {
                int?meetingId = WebApiConsume.GetMeetingId(Utilities.BASE_URL + "/api/Committees", Convert.ToInt32(ViewState["CommitteeId"]), ViewState["CreatedAt"].ToString());

                CommitteesMember input = new CommitteesMember
                {
                    CommitteeId   = Convert.ToInt32(ViewState["CommitteeId"]),
                    MemberId      = memberId,
                    CommitteeRole = 6,
                    UpdatedAt     = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                    CreatedAt     = ViewState["CreatedAt"].ToString(),
                    MeetingId     = meetingId
                };
                try
                {
                    string apiUrlUser = Utilities.BASE_URL + "/api/Users";

                    string inputJson3 = (new JavaScriptSerializer()).Serialize(input);
                    WebApiConsume.PostCommitteeMembersUpdate(Utilities.BASE_URL + "/api/CommitteesMembers", inputJson3);


                    gvMembersOfCommittee.DataSource = WebApiConsume.ShowCommitteeMembers(Convert.ToInt32(ViewState["CommitteeId"]));

                    gvMembersOfCommittee.DataBind();
                    User   userFcm   = WebApiConsume.GetUserById(Utilities.BASE_URL + "/api/Users", memberId);
                    string apiUrlFcm = Utilities.BASE_URL + "/api/Fcm";
                    WebApiConsume.SendUserNotification(apiUrlFcm, Convert.ToInt32(ViewState["CommitteeId"]), txtCommitteeName.Text, userFcm.FCMToken);
                    SMS.SendSms("انت عضو فى لجنة " + "\n" + txtCommitteeName.Text + " المشكلة بتاريخ   " + "\n" + txtCommitteeDate.Text, userFcm.Phone);

                    foreach (GridViewRow row in gvMembersOfCommittee.Rows)
                    {
                        string mobile = row.Cells[3].Text;
                        SMS.SendSms("تم اضافة عضو للجنة " + "\n" + txtCommitteeName.Text + " المشكلة بتاريخ   " + "\n" + txtCommitteeDate.Text, mobile);
                    }
                    //  Utilities.SendMailToOnePerson(userFcm.UserEmailId, "انضمام للجنة", "تم اضافتك للجنة بنجاح");
                    ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "تم", "alert('تم اضافة العضو لللجنة بنجاح');", true);
                }
                catch (Exception ex)
                {
                    string filePath = @Utilities.LogError_Path + "Error.txt";


                    using (StreamWriter writer = new StreamWriter(filePath, true))
                    {
                        writer.WriteLine("-----------------------------------------------------------------------------");
                        writer.WriteLine("Date : " + DateTime.Now.ToString());
                        writer.WriteLine();

                        while (ex != null)
                        {
                            writer.WriteLine(ex.GetType().FullName);
                            writer.WriteLine("Message : " + ex.Message);
                            writer.WriteLine("StackTrace : " + ex.StackTrace);

                            ex = ex.InnerException;
                        }
                    }
                }

                //Page.ClientScript.RegisterStartupScript(this.GetType(), "toastr_message", "toastr.success('تم ارسال الاشعارات بنجاح', 'تم')", true);
            }
            else
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "toastr_message", "toastr.error('هذا العضو موجود بالفعل داخل اللجنه', 'تحذير')", true);
                //ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "تحذير", "alert('هذا العضو موجود بالفعل داخل اللجنه');", true);
            }
        }
コード例 #2
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (Request.QueryString["status"] == "update" || Request.QueryString["status"] == "selected")
            {
                int committeeId = Convert.ToInt32(Request.QueryString["cId"]);

                List <UserGrid> data = WebApiConsume.ShowCommitteeMembers(committeeId);
                gvMembersOfCommittee.DataSource = data.Where(x => x != null).ToList();

                gvMembersOfCommittee.DataBind();
                ViewState["CommitteeId"] = committeeId;
                List <User> Members = WebApiConsume.GetUsers(Utilities.BASE_URL + "/api/Users/GetUsers");
                ddlMemberChange.DataSource     = Members;
                ddlMemberChange.DataTextField  = "Name";
                ddlMemberChange.DataValueField = "ID";
                ddlMemberChange.DataBind();
                divAddMember.Visible = true;
                List <UserGrid> data2 = WebApiConsume.ShowCommitteeMembers(committeeId);
                gvMembersOfCommittee.DataSource = data2.Where(x => x != null).ToList();

                gvMembersOfCommittee.DataBind();
                if (Session["SystemRole"].ToString() == "2")

                {
                    divAddMember.Visible = true;
                }

                Committee.Models.Committee committeeUpdate = new Models.Committee()
                {
                    CommitteeName             = txtCommitteeName.Text,
                    CommitteeDate             = txtCommitteeDateHidden.Value,
                    TypeId                    = Convert.ToInt32(ddlCommitteeClassification.SelectedItem.Value),
                    ActivityId                = Convert.ToInt32(ddlcommitteeStatus.SelectedItem.Value),
                    ImportanceId              = Convert.ToInt32(ddlCommitteeImportancy.SelectedItem.Value),
                    CommitteeTopic            = txtCommitteeTopic.Text,
                    CommitteeBasedOn          = txtCommitteeBasedON.Text,
                    CommitteeEnrollmentNumber = txtEnrollmentNumber.Text,
                    CommitteeEnrollmentDate   = txtEnrollmentDate.Text,
                    CommitteeManager          = ddlCommitteepresident.SelectedItem.Value == "NULL" ? null : ddlCommitteepresident.SelectedItem.Value,
                    CommitteeSecretary        = ddlCommitteeSecrtary.SelectedItem.Value == "NULL" ? null : ddlCommitteeSecrtary.SelectedItem.Value,
                    CommitteeInbox1           = txtInboxSide.Text,
                    DeptId                    = ddlCommitteeDept.SelectedItem.Value == "NULL" ? null : ddlCommitteeDept.SelectedItem.Value,
                    CommitteeId               = Convert.ToInt32(ViewState["CommitteeId"]),
                    UpdatedAt                 = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                    CreatedAt                 = ViewState["CreatedAt"].ToString()
                };

                string inputJson = (new JavaScriptSerializer()).Serialize(committeeUpdate);
                WebApiConsume.UpdateCommittee(Utilities.BASE_URL + "/api/Committees", Convert.ToInt32(ViewState["CommitteeId"]), inputJson);
                btnSave.Text = "حفظ";

                Response.Redirect("CommitteeMangement.aspx?id=redirectUpdate");

                //gvCommittee.EditIndex = -1;
            }
            else if (Request.QueryString["status"] == "new")
            {
                string isCommitteeExist = "";

                bool CommitteeExist = WebApiConsume.IsCommitteeExist(Utilities.BASE_URL + "/api/Committees", txtCommitteeName.Text.Trim().ToLower());
                if (CommitteeExist)
                {
                    ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "تم", "alert('هذا الاسم موجود بالفعل من فضلك قم بادخال اسم اخر لللجنه');", true);
                }
                else
                {
                    if (ddlCommitteepresident.SelectedItem.Value != "NULL" || ddlCommitteeSecrtary.SelectedItem.Value != "NULL")
                    {
                        if (selectedUsers.Count == 0 && ddlCommitteeSecrtary.Visible == true && ddlCommitteepresident.Visible == true)
                        {
                            selectedUsers.Add(Convert.ToInt32(ddlCommitteeSecrtary.SelectedItem.Value));
                            selectedUsers.Add(Convert.ToInt32(ddlCommitteepresident.SelectedItem.Value));
                        }
                    }

                    Committee.Models.Committee committee = new Models.Committee()
                    {
                        CommitteeName             = txtCommitteeName.Text,
                        CommitteeDate             = txtCommitteeDateHidden.Value,
                        TypeId                    = Convert.ToInt32(ddlCommitteeClassification.SelectedItem.Value),
                        ActivityId                = Convert.ToInt32(ddlcommitteeStatus.SelectedItem.Value),
                        ImportanceId              = Convert.ToInt32(ddlCommitteeImportancy.SelectedItem.Value),
                        CommitteeTopic            = txtCommitteeTopic.Text,
                        CommitteeBasedOn          = txtCommitteeBasedON.Text,
                        CommitteeEnrollmentNumber = txtEnrollmentNumber.Text,
                        CommitteeEnrollmentDate   = txtEnrollmentDate.Text,
                        CommitteeManager          = ddlCommitteepresident.SelectedItem.Value == "NULL" ? null : ddlCommitteepresident.SelectedItem.Value,
                        CommitteeSecretary        = ddlCommitteeSecrtary.SelectedItem.Value == "NULL" ? null : ddlCommitteeSecrtary.SelectedItem.Value,
                        CommitteeInbox1           = txtInboxSide.Text,
                        DeptId                    = ddlCommitteeDept.SelectedItem.Value == "NULL" ? null : ddlCommitteeDept.SelectedItem.Value,
                        CreatedAt                 = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                        UpdatedAt                 = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
                    };

                    string inputJson = (new JavaScriptSerializer()).Serialize(committee);
                    WebApiConsume.PostCommittee(Utilities.BASE_URL + "/api/Committees", inputJson);


                    List <CommitteesMember> committeesMembers = new List <CommitteesMember>();
                    int Committee     = WebApiConsume.GetCommitteeId(Utilities.BASE_URL + "/api/Committees", txtCommitteeName.Text.Trim().ToLower());
                    int committeeRole = 0;

                    for (int i = 0; i < selectedUsers.Count; i++)
                    {
                        // client.DownloadString(apiUrl3 + "/GetCommitteeId?committeeName=" + txtCommitteeName.Text);

                        if (i == 0)
                        {
                            committeeRole = 4;
                        }
                        if (i == 1)
                        {
                            committeeRole = 5;
                        }
                        if (i > 1)
                        {
                            committeeRole = 6;
                        }
                        committeesMembers.Add(new CommitteesMember()
                        {
                            MemberId      = selectedUsers[i],
                            CommitteeId   = Committee,
                            CommitteeRole = committeeRole,
                            CreatedAt     = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                            UpdatedAt     = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
                        });
                    }

                    string inputJson2 = (new JavaScriptSerializer()).Serialize(committeesMembers);
                    //WebClient client = new WebClient();

                    WebApiConsume.PostCommitteeMembers(Utilities.BASE_URL + "/api/CommitteesMembers", inputJson2);

                    foreach (var member in committeesMembers)
                    {
                        object memb = new
                        {
                            id = member.MemberId,
                        };

                        try
                        {
                            User userFcm = WebApiConsume.GetUserById(Utilities.BASE_URL + "/api/Users", member.MemberId);
                            WebApiConsume.SendUserNotification(Utilities.BASE_URL + "/api/Fcm", member.CommitteeId, txtCommitteeName.Text, userFcm.FCMToken);
                            //  SMS.SendSms("تم إنشاء لجنة جديده : " + "\n" + txtCommitteeName.Text, userFcm.Phone);
                            if (userFcm.Phone != "" || userFcm.Phone != null)
                            {
                                SMS.SendSms("تم إنشاء لجنه " + "\n" + txtCommitteeName.Text + " المشكلة بتاريخ   " + "\n" + txtCommitteeDate.Text, userFcm.Phone);
                                //  Utilities.SendMailToOnePerson(userFcm.UserEmailId, "انضمام للجنة", "تم اضافتك للجنة بنجاح");
                            }
                        }
                        catch (Exception ex)
                        {
                            string filePath = @Utilities.LogError_Path + "Error.txt";


                            using (StreamWriter writer = new StreamWriter(filePath, true))
                            {
                                writer.WriteLine("-----------------------------------------------------------------------------");
                                writer.WriteLine("Date : " + DateTime.Now.ToString());
                                writer.WriteLine();

                                while (ex != null)
                                {
                                    writer.WriteLine(ex.GetType().FullName);
                                    writer.WriteLine("Message : " + ex.Message);
                                    writer.WriteLine("StackTrace : " + ex.StackTrace);

                                    ex = ex.InnerException;
                                }
                            }
                        }
                        string apiUrlAlert = "";
                        WebApiConsume.PostAlert(Utilities.BASE_URL + "/api/Committees", member.CommitteeId, member.MemberId);
                    }
                    ViewState["update"] = 0;
                    selectedUsers       = new List <int>();
                    userGrids           = new List <UserGrid>();
                    Response.Redirect("CommitteeMangement.aspx?id=redirectSave");
                }
            }
        }