BEST /BaliEnterpriseSystems/BaliEnterpriseSystems/SaveSchedule.aspx.cs

Language C# Lines 230
MD5 Hash ce476de21abc357a233792e54c3ecd63
Repository https://github.com/sirivedula/BEST.git View Raw File
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using BaliEnterpriseSystems.BestObjects;
using System.Collections.Generic;

namespace BaliEnterpriseSystems
{
    public partial class SaveSchedule : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Page_LoadComplete(object sender, EventArgs e)
        {
            if (HttpContext.Current.Session["CurrentUser"] == null)
            {
                Response.Redirect("Logout.aspx");
            }

            string tutGuid = Request.Form["tutGuid"];
            string stuGuid1 = Request.Form["stuGuid1"];
            string stuGuid2 = Request.Form["stuGuid2"];
            string stuGuid3 = Request.Form["stuGuid3"];
            string stuGuid4 = Request.Form["stuGuid4"];
            string stuGuid5 = Request.Form["stuGuid5"];
            string schGuid = Request.Form["schGuid"];
            string schDate = Request.Form["schDate"];
            string schFrom = Request.Form["schFrom"];
            string schTo = Request.Form["schTo"];
            string isdelete = Request.Form["isDel"];
            string attend1 = Request.Form["attend0"];
            string attend2 = Request.Form["attend1"];
            string attend3 = Request.Form["attend2"];
            string attend4 = Request.Form["attend3"];
            string attend5 = Request.Form["attend4"];
            string note1 = Request.Form["note0"];
            string note2 = Request.Form["note1"];
            string note3 = Request.Form["note2"];
            string note4 = Request.Form["note3"];
            string note5 = Request.Form["note4"];
            string progGuid1 = Request.Form["progGuid1"];
            string progGuid2 = Request.Form["progGuid2"];
            string progGuid3 = Request.Form["progGuid3"];
            string progGuid4 = Request.Form["progGuid4"];
            string progGuid5 = Request.Form["progGuid5"];
            string tutorattend = Request.Form["tutorattend"];

            BestSchedules bsch = new BestSchedules();
            if (Utils.IsGuid(schGuid))
            {
                /* Update */
                if (!(Utils.User.UserRoleByName("5.Schedules").allowEdit))
                {
                    Response.Write("{result:false,Message:'You do not have rights to edit.'}");
                    return;
                }

                List<BestField> bparams = new List<BestField>();
                BestField guid = new BestField() { fieldName = "guidfield", fieldSize = 40, fieldType = "System.Guid", paramOledbType = System.Data.OleDb.OleDbType.Guid, displayField = false };
                guid.fieldValue = schGuid;
                bparams.Add(guid);
                bsch.LoadRows("guidfield = ?", bparams);
                if (bsch.TableRows.Count > 0)
                {
                    bsch.schDate = schDate;
                    bsch.schFrom = schFrom;
                    bsch.schTo = schTo;
                    if(! string.IsNullOrEmpty(isdelete))
                        bsch.isDeleted = isdelete;
                }
            }
            else
            {
                /* Add New */
                if (!(Utils.User.UserRoleByName("5.Schedules").allowAdd))
                {
                    Response.Write("{result:false,Message:'You do not have rights to add.'}");
                    return;
                }
                bsch.guidfield = Guid.NewGuid();
                bsch.schDate = schDate;
                bsch.schFrom = schFrom;
                bsch.schTo = schTo;
            }

            if (Utils.IsGuid(tutGuid))
                bsch.tutGuid = new Guid(tutGuid);

            bsch.stuGuid1 = new Guid(stuGuid1);
            if (Utils.IsGuid(stuGuid2))
                bsch.stuGuid2 = new Guid(stuGuid2);
            else
                bsch.stuGuid2 = null;

            if (Utils.IsGuid(stuGuid3))
                bsch.stuGuid3 = new Guid(stuGuid3);
            else
                bsch.stuGuid3 = null;

            if (Utils.IsGuid(stuGuid4))
                bsch.stuGuid4 = new Guid(stuGuid4);
            else
                bsch.stuGuid4 = null;

            if (Utils.IsGuid(stuGuid5))
                bsch.stuGuid5 = new Guid(stuGuid5);
            else
                bsch.stuGuid5 = null;

            bsch.isDeleted = isdelete;
            bsch.attended1 = attend1;
            if (!string.IsNullOrEmpty(attend2)) 
                bsch.attended2 = attend2;
            if (!string.IsNullOrEmpty(attend3)) 
            bsch.attended3 = attend3;
            if (!string.IsNullOrEmpty(attend4)) 
            bsch.attended4 = attend4;
            if (!string.IsNullOrEmpty(attend5)) 
            bsch.attended5 = attend5;
            if (!string.IsNullOrEmpty(note1)) 
                bsch.note1 = note1;
            if (!string.IsNullOrEmpty(note2)) 
                bsch.note2 = note2;
            if (!string.IsNullOrEmpty(note3)) 
                bsch.note3 = note3;
            if (!string.IsNullOrEmpty(note4)) 
                bsch.note4 = note4;
            if (!string.IsNullOrEmpty(note5)) 
                bsch.note5 = note5;

            if (!string.IsNullOrEmpty(progGuid1))
                bsch.progGuid1 = new Guid(progGuid1);
            else
                bsch.progGuid1 = null;

            if (!string.IsNullOrEmpty(progGuid2))
                bsch.progGuid2 = new Guid(progGuid2);
            else
                bsch.progGuid2 = null;

            if (!string.IsNullOrEmpty(progGuid3))
                bsch.progGuid3 = new Guid(progGuid3);
            else
                bsch.progGuid3 = null;

            if (!string.IsNullOrEmpty(progGuid4))
                bsch.progGuid4 = new Guid(progGuid4);
            else
                bsch.progGuid4 = null;

            if (!string.IsNullOrEmpty(progGuid5))
                bsch.progGuid5 = new Guid(progGuid5);
            else
                bsch.progGuid5 = null;
            if (!string.IsNullOrEmpty(tutorattend))
                bsch.tutorattend = tutorattend;

            if (!string.IsNullOrEmpty(stuGuid1) && !string.IsNullOrEmpty(progGuid1))
                bsch.Amount1 = getProgramAmount(bsch.stuGuid1, bsch.progGuid1);
            else
                bsch.Amount1 = 0;

            if (!string.IsNullOrEmpty(stuGuid2) && !string.IsNullOrEmpty(progGuid2))
                bsch.Amount2 = getProgramAmount(bsch.stuGuid2, bsch.progGuid2);
            else
                bsch.Amount2 = 0;

            if (!string.IsNullOrEmpty(stuGuid3) && !string.IsNullOrEmpty(progGuid3))
                bsch.Amount3 = getProgramAmount(bsch.stuGuid3, bsch.progGuid3);
            else
                bsch.Amount3 = 0;

            if (!string.IsNullOrEmpty(stuGuid4) && !string.IsNullOrEmpty(progGuid4))
                bsch.Amount4 = getProgramAmount(bsch.stuGuid4, bsch.progGuid4);
            else
                bsch.Amount4 = 0;

            if (!string.IsNullOrEmpty(stuGuid5) && !string.IsNullOrEmpty(progGuid5))
                bsch.Amount5 = getProgramAmount(bsch.stuGuid5, bsch.progGuid5);
            else
                bsch.Amount5 = 0;

            bsch.CenterId = Utils.User.CenterId;
            if (bsch.CurrentRow.Save())
            {
                Response.Write("{result:true,guid:'" + bsch.CurrentRow.Fields["guidfield"].fieldValue + "'}");
            }
            else
            {
                Response.Write("{result:false,Message:'" + Utils.EnquoteJS( bsch.CurrentRow.lastError )+ "'}");
            }
        }

        private Decimal getProgramAmount(Guid? stuguid, Guid? progGuid)
        {
            Decimal result = 0;

            BestField p1 = new BestField() { fieldName = "studentguid", fieldType = "System.Guid", fieldSize = 40, paramOledbType = System.Data.OleDb.OleDbType.Guid };
            p1.fieldValue = stuguid.ToString();
            BestField p2 = new BestField() { fieldName = "guidfield", fieldType = "System.Guid", fieldSize = 40, paramOledbType = System.Data.OleDb.OleDbType.Guid };
            p2.fieldValue = progGuid.ToString();
            List<BestField> bparams = new List<BestField>();
            bparams.Add(p1);
            bparams.Add(p2);

            BestStudentPrograms bstdProgs = new BestStudentPrograms();
            bstdProgs.LoadRows("studentguid=? and guidfield=?", bparams);
            if (bstdProgs.HasRows)
            {
                bstdProgs.currentRowId = 0;
                result = bstdProgs.Amount;
            }

            return result;
        }
    }
}
Back to Top