예제 #1
0
파일: DALBill.cs 프로젝트: kalirajanl/UBRS
        public static long AddBill(BillItem itm)
        {
            bool returnValue = false;
            long billID = 0;
            if (itm != null)
            {
                billID = getNextBillID();
                long scheduleID = 0;
                List<DateTime> schedules = null;
                if (itm.BillSchedule != null)
                {
                    scheduleID = DALSchedule.AddSchedule(itm.BillSchedule);
                    schedules = ScheduleHelper.GetInstanceDates(itm.BillSchedule, itm.StartDate, itm.EndDate);
                }
                else
                {
                    schedules = new List<DateTime>();
                    schedules.Add(itm.StartDate);
                }

                IBaseQueryData query = new InsertQueryData();
                query.TableName = "Bill";
                query.Fields.Add(new FieldData { FieldName = "BillID", FieldValue = billID.ToString(), FieldType = SqlDbType.BigInt });
                if (itm.Biller != null)
                {
                    query.Fields.Add(new FieldData { FieldName = "BillerID", FieldValue = itm.Biller.ID.ToString(), FieldType = SqlDbType.Int });
                }
                query.Fields.Add(new FieldData { FieldName = "StartDate", FieldValue = itm.StartDate.ToString(Constants.DATE_FORMAT_SQL), FieldType = SqlDbType.DateTime });
                query.Fields.Add(new FieldData { FieldName = "FinishDate", FieldValue = itm.EndDate.ToString(Constants.DATE_FORMAT_SQL), FieldType = SqlDbType.DateTime });
                query.Fields.Add(new FieldData { FieldName = "BillAmount", FieldValue = itm.Amount.ToString(Constants.CURRENCY_FORMAT_SQL), FieldType = SqlDbType.Money });
                query.Fields.Add(new FieldData { FieldName = "Notes", FieldValue = itm.Notes, FieldType = SqlDbType.VarChar });
                query.Fields.Add(new FieldData { FieldName = "BillTitle", FieldValue = itm.BillTitle, FieldType = SqlDbType.VarChar });
                query.Fields.Add(new FieldData { FieldName = "ScheduleID", FieldValue = scheduleID.ToString(), FieldType = SqlDbType.BigInt });

                List<BillInstanceItem> itms = new List<BillInstanceItem>();
                for (int j = 0; j <= schedules.Count - 1; j++)
                {
                    itms.Add(new BillInstanceItem { BillID = billID, InstanceDate = schedules[j] });
                }

                List<IBaseQueryData> queryData = DALBillInstance.GetUpsertBillInstanceQueryData(billID, itms);
                queryData.Insert(0, query);

                returnValue = SQLWrapper.ExecuteQuery(queryData);

            }
            if (returnValue)
            {
                return billID;
            }
            else
            {
                return 0;
            }
        }
예제 #2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            bool returnValue = false;
            if (isValidData(true))
            {
                if (IsPageDirty)
                {
                    BillItem bill = null;
                    switch (this.CurrentPageMode)
                    {
                        case PageMode.Add:
                            {
                                bill = new BillItem();
                                break;
                            }
                        case PageMode.Edit:
                            {
                                bill = DALBill.GetBillByID(ItemID);
                                break;
                            }
                    }
                    bill.BillTitle = this.txtBillTitle.Text;
                    bill.Amount = Convert.ToDecimal(this.txtBillAmount.Text);
                    bill.Biller = (BillerItem)this.cboBillers.SelectedItem;
                    bill.StartDate = this.dtpStartDate.Value;
                    bill.EndDate = this.dtpEndDate.Value;
                    bill.Notes = this.txtBillNotes.Text;

                    bill.BillSchedule = CurrentSchedule;

                    try
                    {
                        switch (this.CurrentPageMode)
                        {
                            case PageMode.Add:
                                {
                                    returnValue = (DALBill.AddBill(bill) > 0);
                                    break;
                                }
                            case PageMode.Edit:
                                {
                                    returnValue = DALBill.UpdateBill(bill);
                                    break;
                                }
                        }
                    }
                    catch (Exception ex)
                    {
                        ShowError("Unable to save bill information. Please review the error message below and fix the data accordingly" + Environment.NewLine + ex.Message, Form_Title);
                    }
                    bill = null;
                }
                if (returnValue)
                {
                    this.Hide();
                    this.Close();
                }
            }
        }
예제 #3
0
파일: DALBill.cs 프로젝트: kalirajanl/UBRS
 private static BillItem loadBill(DataTable dt, int rowNo)
 {
     BillItem bill = null;
     if (dt != null)
     {
         if (dt.Rows.Count > rowNo)
         {
             bill = new BillItem();
             bill.ID = (long)dt.Rows[rowNo]["BillID"];
             bill.StartDate = Convert.ToDateTime(dt.Rows[rowNo]["StartDate"]);
             bill.EndDate = Convert.ToDateTime(dt.Rows[rowNo]["FinishDate"]);
             bill.Amount = Convert.ToDecimal(dt.Rows[rowNo]["BillAmount"]);
             bill.BillTitle = dt.Rows[rowNo]["BillTitle"].ToString().Trim();
             bill.Notes = dt.Rows[rowNo]["Notes"].ToString();
             bill.Biller = DALBiller.GetBillerByID(Convert.ToInt32(dt.Rows[rowNo]["BillerID"]));
             if (dt.Rows[rowNo]["ScheduleID"] != DBNull.Value)
             {
                 bill.BillSchedule = DALSchedule.GetScheduleByID(Convert.ToInt64(dt.Rows[rowNo]["ScheduleID"]));
             }
         }
     }
     return bill;
 }
예제 #4
0
파일: DALBill.cs 프로젝트: kalirajanl/UBRS
        public static bool UpdateBill(BillItem itm)
        {
            bool returnValue = false;
            if (itm != null)
            {
                long scheduleID = 0;
                if (itm.BillSchedule == null)
                {
                    scheduleID = 0;
                    BillItem olditm = GetBillByID(itm.ID);
                    if (olditm != null)
                    {
                        if (olditm.BillSchedule != null)
                        {
                            DALSchedule.DeleteScheduleByID(olditm.BillSchedule.ScheduleID);
                        }
                    }
                }
                else
                {
                    scheduleID = itm.BillSchedule.ScheduleID;
                    if (scheduleID == 0)
                    {
                        BillItem olditm = GetBillByID(itm.ID);
                        if (olditm != null)
                        {
                            if (olditm.BillSchedule != null)
                            {
                                DALSchedule.DeleteScheduleByID(olditm.BillSchedule.ScheduleID);
                            }
                        }
                        scheduleID = DALSchedule.AddSchedule(itm.BillSchedule);
                        returnValue = (scheduleID > 0);
                    }
                    else
                    {
                        returnValue = DALSchedule.UpdateSchedule(itm.BillSchedule);
                    }
                }

                List<DateTime> schedules = null;
                if (itm.BillSchedule != null)
                {
                    schedules = ScheduleHelper.GetInstanceDates(itm.BillSchedule, itm.StartDate, itm.EndDate);
                }
                else
                {
                    schedules = new List<DateTime>();
                    schedules.Add(itm.StartDate);
                }
                IBaseQueryData query = new UpdateQueryData();
                query.TableName = "Bill";
                query.KeyFields.Add(new FieldData { FieldName = "BillID", FieldValue = itm.ID.ToString(), FieldType = SqlDbType.BigInt });
                if (itm.Biller != null)
                {
                    query.Fields.Add(new FieldData { FieldName = "BillerID", FieldValue = itm.Biller.ID.ToString(), FieldType = SqlDbType.Int });
                }
                query.Fields.Add(new FieldData { FieldName = "StartDate", FieldValue = itm.StartDate.ToString(Constants.DATE_FORMAT_SQL), FieldType = SqlDbType.DateTime });
                query.Fields.Add(new FieldData { FieldName = "FinishDate", FieldValue = itm.EndDate.ToString(Constants.DATE_FORMAT_SQL), FieldType = SqlDbType.DateTime });
                query.Fields.Add(new FieldData { FieldName = "BillAmount", FieldValue = itm.Amount.ToString(Constants.CURRENCY_FORMAT_SQL), FieldType = SqlDbType.Money });
                query.Fields.Add(new FieldData { FieldName = "Notes", FieldValue = itm.Notes, FieldType = SqlDbType.VarChar });
                query.Fields.Add(new FieldData { FieldName = "BillTitle", FieldValue = itm.BillTitle, FieldType = SqlDbType.VarChar });
                query.Fields.Add(new FieldData { FieldName = "ScheduleID", FieldValue = scheduleID.ToString(), FieldType = SqlDbType.BigInt });

                List<BillInstanceItem> itms = new List<BillInstanceItem>();
                for (int j = 0; j <= schedules.Count - 1; j++)
                {
                    itms.Add(new BillInstanceItem { BillID = itm.ID , InstanceDate = schedules[j] });
                }

                List<IBaseQueryData> queryData = DALBillInstance.GetUpsertBillInstanceQueryData(itm.ID, itms);
                queryData.Insert(0, query);

                returnValue = SQLWrapper.ExecuteQuery(queryData);

            }
            return returnValue;
        }