protected void btnAddInitiatorAutoItem_Click(object sender, ImageClickEventArgs e)
        {
            List <UserFavoriteInitiator> userFavoriteInitiatorList = DocumentInitiatorQuery.FindUserFavoriteInitiatorByUserID(CreateCriteria(), RequesterID).ToList <UserFavoriteInitiator>();

            List <DocumentInitiatorLang> documentInitiatorList = new List <DocumentInitiatorLang>();
            int countSeq = 0;

            foreach (UserFavoriteInitiator item in userFavoriteInitiatorList)
            {
                ++countSeq;
                DocumentInitiatorLang documentInitiatorItem = new DocumentInitiatorLang();
                documentInitiatorItem.DocumentID    = DocumentID;
                documentInitiatorItem.Email         = item.Email;
                documentInitiatorItem.EmployeeName  = item.EmployeeName;
                documentInitiatorItem.Seq           = UIHelper.ParseShort(countSeq.ToString());
                documentInitiatorItem.UserID        = item.ActorUserID;
                documentInitiatorItem.InitiatorType = "1";
                documentInitiatorList.Add(documentInitiatorItem);
            }


            InitiatorReorderList.DataSource = ReorderInitiators(documentInitiatorList);
            InitiatorReorderList.DataBind();
            InitiatorUpdatePanel.Update();
        }
        public void Save()
        {
            List <DocumentInitiatorLang> documentInitiatorList = ReorderInitiators(GetInitiators());

            DataSet ds = TransactionService.GetDS(this.TransactionId);


            // the program below is supposed to put in Service layer
            Spring.Validation.ValidationErrors errors = new Spring.Validation.ValidationErrors();

            foreach (DocumentInitiatorLang item in documentInitiatorList)
            {
                if (String.IsNullOrEmpty(item.InitiatorType))
                {
                    errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("RequiredInitiatorType"));
                }
            }

            if (!errors.IsEmpty)
            {
                throw new ServiceValidationException(errors);
            }

            foreach (DataRow row in ds.Tables["DocumentInitiator"].Select())  //("DocumentID=" + DocumentID))
            {
                row.Delete();
            }

            DateTime dt          = DateTime.Now;
            long     UserID      = UserAccount.UserID;
            long     documentID  = DocumentID;
            string   progamecode = UserAccount.CurrentProgramCode;

            int seq = 1;

            foreach (DocumentInitiatorLang item in documentInitiatorList)
            {
                // new initiator
                DataRow dr = ds.Tables["DocumentInitiator"].NewRow();
                dr["Seq"]           = item.Seq;
                dr["DocumentID"]    = item.DocumentID;
                dr["UserID"]        = item.UserID;
                dr["InitiatorType"] = item.InitiatorType;
                dr["DoApprove"]     = item.DoApprove;
                dr["Active"]        = true;
                dr["CreBy"]         = UserID;
                dr["CreDate"]       = dt;
                dr["UpdBy"]         = UserID;
                dr["UpdDate"]       = dt;
                dr["UpdPgm"]        = progamecode;
                //dr["RowFlag"] = DataRowState.Added.ToString();
                ds.Tables["DocumentInitiator"].Rows.Add(dr);
            }


            InitiatorReorderList.DataSource = documentInitiatorList;
            InitiatorReorderList.DataBind();
            InitiatorUpdatePanel.Update();
        }
        protected void InitiatorReorderList_DeleteCommand(object sender, AjaxControlToolkit.ReorderListCommandEventArgs e)
        {
            List <DocumentInitiatorLang> documentInitiatorList = GetInitiators();

            documentInitiatorList.RemoveAt(e.Item.ItemIndex);

            InitiatorReorderList.DataSource = ReorderInitiators(documentInitiatorList);
            InitiatorReorderList.DataBind();
            InitiatorUpdatePanel.Update();
        }
        protected void InitiatorReorderList_ItemReorder(object sender, AjaxControlToolkit.ReorderListItemReorderEventArgs e)
        {
            List <DocumentInitiatorLang> documentInitiatorList = GetInitiators();

            int   NewIndex = e.NewIndex + 1;
            int   OldIndex = e.OldIndex + 1;
            short oldSeq   = UIHelper.ParseShort(OldIndex.ToString());
            short newSeq   = UIHelper.ParseShort(NewIndex.ToString());

            documentInitiatorList[e.OldIndex].Seq = newSeq;
            documentInitiatorList[e.NewIndex].Seq = oldSeq;

            InitiatorReorderList.DataSource = ReorderInitiators(documentInitiatorList);
            InitiatorReorderList.DataBind();
            InitiatorUpdatePanel.Update();
        }
        protected void CtlInitiatorLookup_OnObjectLookUpReturn(object sender, ObjectLookUpReturnArgs e)
        {
            //Insert New Initiator on ViewSate

            IList <SuUser> list = (IList <SuUser>)e.ObjectReturn;

            List <DocumentInitiatorLang> documentInitiatorList = GetInitiators();

            int countSeq = documentInitiatorList.Count;

            foreach (SuUser item in list)
            {
                int count = (from i in documentInitiatorList
                             where i.UserID == item.Userid
                             select i).Count();;
                if (count > 0)
                {
                    continue;
                }

                ++countSeq;
                DocumentInitiatorLang documentInitiatorItem = new DocumentInitiatorLang();
                documentInitiatorItem.DocumentID   = DocumentID;
                documentInitiatorItem.Email        = item.Email;
                documentInitiatorItem.EmployeeName = item.EmployeeName;
                // documentInitiatorItem.LastName = item.LastName;
                documentInitiatorItem.Seq           = UIHelper.ParseShort(countSeq.ToString());
                documentInitiatorItem.UserID        = item.Userid;
                documentInitiatorItem.InitiatorType = "1";
                documentInitiatorList.Add(documentInitiatorItem);
            }

            InitiatorReorderList.DataSource = ReorderInitiators(documentInitiatorList);
            InitiatorReorderList.DataBind();
            InitiatorUpdatePanel.Update();
        }