Exemplo n.º 1
0
        public static string SaveRequest(
            string RequestID,
            string DepartmentID,
            string RequestType,
            string RequestNo,
            string RequestBy,
            string RequestTitle,
            string RequestStatus,
            string RequestOn,
            string MeetingID,
            string Remark,
            string ApprovedBy,
            string ApprovedOn,
            string ApprovedRemark,
            string Description,
            string UserID,
            string Requestitems,
            string RequestDecisions)
        {
            try
            {
                //Security Check
                if (!Controller_User_Access.CheckProgramAccess(AccessProgramCode, UserID, "read"))
                {
                    throw new Exception("No Access.");
                }

                LINQ_MeetingDataContext dc          = new LINQ_MeetingDataContext();
                MET_Request             the_request = new MET_Request();

                if (RequestID == "")
                {
                    the_request = new MET_Request()
                    {
                        Active    = true,
                        CreatedBy = UserID,
                        CreatedOn = DateTime.Now,
                        RequestID = Guid.NewGuid().ToString(),
                        RequestNo = Controller_RunningNo.GetNewRunningCode("Request", UserID),


                        ApprovedBy     = "",
                        ApprovedOn     = DateTime.Now,
                        ApprovedRemark = "",
                        ApprovalStatus = ""
                    };
                    RequestID = the_request.RequestID;
                    dc.MET_Requests.InsertOnSubmit(the_request);
                }
                else
                {
                    the_request = (from c in dc.MET_Requests where c.RequestID == RequestID select c).FirstOrDefault();
                    if (the_request == null)
                    {
                        throw new Exception("System cannot find the record.");
                    }
                }

                DateTime request_on = DateTime.Today;
                DateTime.TryParseExact(RequestOn, "yyyy/M/d", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, out request_on);
                the_request.RequestType  = RequestType;
                the_request.RequestBy    = RequestBy;
                the_request.RequestTitle = RequestTitle;
                the_request.DepartmentID = DepartmentID;

                the_request.RequestStatus = RequestStatus;
                the_request.RequestOn     = request_on;
                the_request.AgendaID      = MeetingID;
                the_request.Remark        = Remark.Replace("%27", "");
                the_request.Description   = Description.Replace("%27", "");

                the_request.ModifiedBy = UserID;
                the_request.ModifiedOn = DateTime.Now;
                the_request.LastAction = Guid.NewGuid().ToString();


                #region Clear previous items
                List <MET_RequestItem> req_old_items = (from c in dc.MET_RequestItems
                                                        where c.RequestID == the_request.RequestID &&
                                                        c.Active == true
                                                        select c).ToList();
                if (req_old_items != null)
                {
                    dc.MET_RequestItems.DeleteAllOnSubmit(req_old_items);
                }
                #endregion


                #region Request Items

                if (Requestitems != "")
                {
                    List <MET_RequestItem> request_items = new List <MET_RequestItem>();
                    List <string>          items         = Requestitems.Split('~').ToList();
                    foreach (string item in items)
                    {
                        if (item != "")
                        {
                            List <string> itemInfo = item.Split('^').ToList();

                            request_items.Add(new MET_RequestItem()
                            {
                                CreatedBy     = UserID,
                                CreatedOn     = DateTime.Now,
                                ModifiedBy    = UserID,
                                ModifiedOn    = DateTime.Now,
                                Active        = true,
                                LastAction    = Guid.NewGuid().ToString(),
                                RequestID     = the_request.RequestID,
                                RequestItemID = itemInfo[0],
                                RequestItem   = itemInfo[1],
                                Seq           = convertToDecimal(itemInfo[2]),
                            });
                        }
                    }
                    dc.MET_RequestItems.InsertAllOnSubmit(request_items);
                }

                #endregion

                #region Request Decision

                #region Clear previous items
                List <MET_RequestDecision> req_old_decisions = (from c in dc.MET_RequestDecisions
                                                                where c.RequestID == the_request.RequestID &&
                                                                c.Active == true
                                                                select c).ToList();
                if (req_old_decisions != null)
                {
                    dc.MET_RequestDecisions.DeleteAllOnSubmit(req_old_decisions);
                }
                #endregion
                if (RequestDecisions != "")
                {
                    List <MET_RequestDecision> request_decisions = new List <MET_RequestDecision>();
                    List <string> decisions         = RequestDecisions.Split('~').ToList();
                    string[]      combine_decisions = new string[decisions.Count];
                    int           count             = 0;
                    foreach (string decision in decisions)
                    {
                        if (decision != "")
                        {
                            List <string> decisionInfo = decision.Split('^').ToList();

                            request_decisions.Add(new MET_RequestDecision()
                            {
                                CreatedBy         = UserID,
                                CreatedOn         = DateTime.Now,
                                ModifiedBy        = UserID,
                                ModifiedOn        = DateTime.Now,
                                Active            = true,
                                LastAction        = Guid.NewGuid().ToString(),
                                RequestID         = the_request.RequestID,
                                RequestDecisionID = decisionInfo[0],
                                Description       = decisionInfo[1],
                                Seq = convertToDecimal(decisionInfo[2]),
                            });
                            combine_decisions[count] = decisionInfo[1];
                            count++;
                        }
                    }

                    dc.MET_RequestDecisions.InsertAllOnSubmit(request_decisions);
                    the_request.CombineDecision = string.Join(",", combine_decisions);
                }

                #endregion

                #region update the log for POS_SellVouncher

                MET_Request log_obj = dc.GetChangeSet().Updates.OfType <MET_Request>().FirstOrDefault();
                if (log_obj != null)
                {
                    if (Controller_SystemLog.WirteUpdateLog(dc.MET_Requests.GetModifiedMembers(log_obj).ToList(), RequestID, UserID) == false)
                    {
                        //Error fail to log.
                    }
                }
                #endregion
                dc.SubmitChanges();

                do_populate_print_description(the_request.RequestID);

                //#region Conbine Decisions
                //the_request.CombineDecision = dc.MET_CombineDecisionsOfRequest(the_request.RequestID).ToString();
                //#endregion
                //dc.SubmitChanges();

                return("Success~" + the_request.RequestID + "~" + the_request.RequestNo);
            }
            catch (Exception ex)
            {
                return("Error~" + ex.Message);
            }
        }
Exemplo n.º 2
0
        public static string SaveAgenda(
            string AgendaID,
            string AgendaDate,
            string AgendaNo,
            string AgendaNoLabel,
            string AgendaStatus,
            string AgendaHistory,
            string AgendaRemark,
            string UserID)
        {
            try
            {
                //Security Check
                if (!Controller_User_Access.CheckProgramAccess(AccessProgramCode, UserID, "read"))
                {
                    throw new Exception("No Access.");
                }

                LINQ_MeetingDataContext dc = new LINQ_MeetingDataContext();
                MET_Agenda the_agenda      = new MET_Agenda();

                if (AgendaID == "")
                {
                    the_agenda = new MET_Agenda()
                    {
                        Active    = true,
                        CreatedBy = UserID,
                        CreatedOn = DateTime.Now,
                        AgendaID  = Guid.NewGuid().ToString(),
                        AgendaNo  = Controller_RunningNo.GetNewRunningCode("Agenda", UserID),
                    };
                    AgendaID = the_agenda.AgendaID;
                    dc.MET_Agendas.InsertOnSubmit(the_agenda);
                }
                else
                {
                    the_agenda = (from c in dc.MET_Agendas where c.AgendaID == AgendaID select c).FirstOrDefault();
                    if (the_agenda == null)
                    {
                        throw new Exception("System cannot find the record.");
                    }
                }

                DateTime agenda_date = DateTime.Today;
                DateTime.TryParseExact(AgendaDate, "yyyy/M/d", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, out agenda_date);
                the_agenda.AgendaStatus  = AgendaStatus;
                the_agenda.AgendaHistory = AgendaHistory;
                the_agenda.AgendaRemark  = AgendaRemark;
                the_agenda.AgendaDate    = agenda_date;
                the_agenda.AgendaNoLable = AgendaNoLabel;

                the_agenda.ModifiedBy = UserID;
                the_agenda.ModifiedOn = DateTime.Now;
                the_agenda.LastAction = Guid.NewGuid().ToString();


                #region update the log for Met_Agenda


                MET_Agenda log_obj = dc.GetChangeSet().Updates.OfType <MET_Agenda>().FirstOrDefault();
                if (log_obj != null)
                {
                    if (Controller_SystemLog.WirteUpdateLog(dc.MET_Agendas.GetModifiedMembers(log_obj).ToList(), AgendaID, UserID) == false)
                    {
                        //Error fail to log.
                    }
                }
                #endregion

                dc.SubmitChanges();


                return("Success~" + the_agenda.AgendaID + "~" + the_agenda.AgendaNo);
            }
            catch (Exception ex)
            {
                return("Error~" + ex.Message);
            }
        }