Im trying to create page for giving my to customers discounts on my products, but for a short period of time. I have created a field "start date" and "end date" of this promotion. Next thing i want to do, is to validate the input of the date.
By "Validate" i mean, that start date cannot be greater then end date. I decided to try preventing from writing into "end date" field unless there is a value in "Start date" field, but i ran into some syntax errors... Can you help me with that? Here is the logic i want to write for my page:
field("Starting Date"; Rec."Starting Date")
{
ApplicationArea = All;
}
field("End Date"; Rec."End Date")
{
ApplicationArea = All;
if Rec."Starting Date" = '' then
Editable = false;
}
Here is the full page code i have so far for better understanding:
page 95012 "ArKe Provision Subform"
{
Caption = 'ArKe Provision Subform';
PageType = ListPart;
ApplicationArea = All;
UsageCategory = Administration;
SourceTable = ArKeProvisionLine;
SourceTableView = sorting(Status, "Line No.") order(descending);
layout
{
area(Content)
{
repeater(ProvisionLineRepeater)
{
field(Status; Rec.Status)
{
ApplicationArea = All;
trigger OnValidate()
begin
CurrPage.Update();
end;
}
field("Customer Type"; Rec."Customer Type")
{
ApplicationArea = All;
}
field("Product Type"; Rec."Product Type")
{
ApplicationArea = All;
}
field("Starting Date"; Rec."Starting Date")
{
ApplicationArea = All;
}
field("End Date"; Rec."End Date")
{
ApplicationArea = All;
if Rec."Starting Date" = '' then begin
Editable = false;
end
}
field("Provision %"; Rec."Provision %")
{
ApplicationArea = All;
}
field("Line No."; Rec."Line No.")
{
ApplicationArea = All;
Editable = false;
}
}
}
}
}
You do not have to format "End Date" or "Starting Date", you can just compare them to 0D (or 0DT if their DataType is DateTime)
Like This:
field("Starting Date"; Rec."Starting Date")
{
ApplicationArea = All;
trigger OnValidate()
begin
if Rec."End Date" <> 0D then begin//0DT in case field is DateTime
if rec."End Date" < rec."Starting Date" then begin
Error('Starting date greater then end date!');
end;
end;
end;
}
field("End Date"; Rec."End Date")
{
ApplicationArea = All;
trigger OnValidate()
begin
if Rec."Starting Date" <> 0D then begin//0DT in case field is DateTime
if rec."Starting Date" > rec."End Date" then begin
Error('Starting date greater then end date!');
end;
end;
end;
}
I found the solution! You should convert your date into a string by writing Format(Rec. ...) and then compare it by using <> instead of :=.
code:
field("Starting Date"; Rec."Starting Date")
{
ApplicationArea = All;
trigger OnValidate()
begin
if Format(Rec."End Date") <> '' then begin
if rec."End Date" < rec."Starting Date" then begin
Error('Starting date greater then end date!');
end;
end;
end;
}
field("End Date"; Rec."End Date")
{
ApplicationArea = All;
trigger OnValidate()
begin
if Format(Rec."Starting Date") <> '' then begin
if rec."Starting Date" > rec."End Date" then begin
Error('Starting date greater then end date!');
end;
end;
end;
}
Related
While using swing everything works just fine.
String sql= "SELECT idrepair as '№',"
+ "case when repairStatus in (0) then 'Not Done' "
+ "when repairStatus in (1) then 'Closed' "
+ "when repairStatus in (2) then 'Open' "
+ "else 'Unknown' end as 'Status'"
+ "FROM repairjournal";
I just want new UI using JavaFX, so here is my code, i would say my efforts:
private void loadTableViewRepList(ObservableList oblist, Connection conn, TableView table) {
oblist.clear();
try {
String sql = "SELECT * FROM repairjournal";
pst = conn.prepareStatement(sql);
rs = pst.executeQuery();
while (rs.next()) {
oblist.add(new ModelTableRepairList(
rs.getString("idrepair"),
rs.getString("case when repairStatus in (0) then 'Not Done' "
+ "when repairStatus in (1) then 'Closed' "
+ "when repairStatus in (2) then 'Open' "
+ "else 'Unknown' end ")
));
}
table.setItems(oblist);
} catch (SQLException ex) {
Logger.getLogger(RepairListController
.class.getName()).log(Level.SEVERE, null, ex);
}
}
or
private void loadTableViewRepList(ObservableList oblist, Connection conn, TableView table) {
oblist.clear();
try {
String sql = "SELECT idrepair,
case when repairStatus in (0) then
'Not Done.' when repairStatus in (1) then
'Closed' when repairStatus in (2) then 'Open'
else 'Unknown' end as 'Status' FROM repairjournal";
pst = conn.prepareStatement(sql);
rs = pst.executeQuery();
while (rs.next()) {
oblist.add(new ModelTableRepairList(
rs.getString("idrepair"),
rs.getString("repairStatus")
));
}
table.setItems(oblist);
} catch (SQLException ex) {
Logger.getLogger(RepairListController
.class.getName()).log(Level.SEVERE, null, ex);
}
}
Main error is no such column: 'repairStatus'
Any ideas how to fix this? Yes i can rename data, but i have more tables with such data in DB.
I want to get all records with timestamp of a current day. According to [this][1] I creating query
SELECT *
FROM table
WHERE timestamp BETWEEN date('now', 'start of day', 'localtime', 'unixepoch') AND
date('now', 'start of day','+1 day', 'localtime', 'unixepoch')"
but allways got nothing. I updating some records calling System.currentTimeMillis()/1000 function. I try without unixepoch parameter but still got nothing
EDIT: I paste my code I try to set timestamp column with diffrent types but it doesnt help too mutch
private static final String DATABASE_CREATE = "create table if not exists "
+ TABLE_DAILY_CHALLENGES +
"(" + DAILY_CHALLENGES_ID + " integer primary key autoincrement, " +
DAILY_CHALLENGES_TITLE + " text not null, "+
DAILY_CHALLENGES_CONTENT + " text not null, "+
DAILY_CHALLENGES_COUNTER + " text not null, "+
DAILY_CHALLENGES_SORT+ " integer not null, " +
DAILY_CHALLENGES_ACTUAL_COUNTER+ " text not null, " +
DAILY_CHALLENGES_TIMESTAMP+ " integer DEFAULT 0, " +
DAILY_CHALLENGES_FINISHED+ " integer DEFAULT 0, " +
DAILY_CHALLENGES_TYPE + " text not null);";
private static Database getDbHandlerInstance(){
if(dbHandler==null){
return init();
}else
return dbHandler;
}
private static Database init(){
dbHandler = DatabaseFactory.getNewDatabase(DATABASE_NAME,
DATABASE_VERSION, DATABASE_CREATE, null);
dbHandler.setupDatabase();
try {
dbHandler.openOrCreateDatabase();
dbHandler.execSQL(DATABASE_CREATE);
} catch (SQLiteGdxException e) {
e.printStackTrace();
}
try { //TODO:: make it more efficient
String query="SELECT * FROM dailyChallenges";
DatabaseCursor cursor = dbHandler.rawQuery(query);
if(cursor.getCount()!=NUMBERS_OF_RECORDS){
cleanTable();
populateDatabase();
}
} catch (SQLiteGdxException e) {
e.printStackTrace();
}
return dbHandler;
}
private static void cleanTable() {
try {
dbHandler.execSQL("delete from "+ TABLE_DAILY_CHALLENGES);
} catch (SQLiteGdxException e) {
e.printStackTrace();
}
}
public static Challenge[] getChallenge(){
DatabaseCursor cursor=null,cursorAll=null;
Challenge[] challenge;
try {
String query="SELECT * FROM dailyChallenges WHERE timestamp BETWEEN date('now', 'start of day', 'localtime', 'unixepoch') AND date('now', 'start of day','+1 day', 'localtime', 'unixepoch')";
cursor = getDbHandlerInstance().rawQuery(query);
} catch (SQLiteGdxException e) {
e.printStackTrace();
}
//create new challenge
if(cursor.getCount()!=0){
//logic,cursor.getCount() is always 0}
Actually commas are perfectly executed in the text box. 12345=12,345
However my submit button is not functioning well when i am declaring the javascrip with my textbox:
<asp:TextBox ID="txtProductPrice" runat="server" class="form-control" MaxLength ="6" onkeyup ="javascript:this.value=Comma(this.value);"></asp:TextBox>
here is my button code:
protected void btnSubmit_Click(object sender, EventArgs e)
{
if (uploadProductPhoto.PostedFile != null)
{
SaveProductPhoto();
ShoppingCart k = new ShoppingCart()
{
ProductName = txtProductName.Text,
ProductImage = "~/ProductImages/" + uploadProductPhoto.FileName,
ProductPrice = txtProductPrice.Text,
ProductDescription = txtProductDescription.Text,
CategoryID = Convert.ToInt32(ddlCategory.SelectedValue),
TotalProducts = Convert.ToInt32(txtProductQuantity.Text)
};
k.AddNewProduct();
ClearText();
Label2.Text = "Product Added!";
//Response.Redirect("AddNewProduct.aspx?alert=success");
}
else
{
Response.Write("<script>alert('Please upload photo');</script>");
The code is finished ("Product Added" is showing up) however, the product is not actually added. its not in the database or anywhere. any tricks on this?
here is the k.AddNewProduct();
ALTER PROCEDURE [dbo].[SP_AddNewProduct]
(
#ProductName varchar(300),
#ProductPrice varchar(500),
#ProductImage varchar(500),
#ProductDescription varchar(1000),
#CategoryID int,
#ProductQuantity int
)
AS
BEGIN
BEGIN TRY
Insert into products
values
(#ProductName,
#ProductDescription,
#ProductPrice,
#ProductImage,
#CategoryID,
#ProductQuantity
)
END TRY
BEGIN CATCH
PRINT ('Error Occured')
END CATCH
END
I have js by using simplified regex
function Comma(Num) {
var parts = Num.toString().split(".");
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
return parts.join(".");
}
if you also need support for numbers with decimals then use the below code
function numberWithCommas(n) {
var parts=n.toString().split(".");
return parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",") + (parts[1] ? "." + parts[1] : "");
}
I am passing xml to a stored procedure and it is compiling but no row inserted into the database.
My code
foreach (int item in objDirectory.PhotoId)
{
//roots = roots + "<row DirectoryId='"+objDirectory.DirectoryId+"'PhotoId='" +item+"'CreatedBy='"+"Admin"+"'ModifiedBy='"+"Admin"+"'/>";
roots = roots + "<row DirectoryId= '" + objDirectory.DirectoryId + "' PhotoId='" + item + "' CreatedBy ='" + "Admin" + "' ModifiedBy ='" + "Admin" + "'/>";
}
PhotoIds = string.Format(PhotoIds, roots);
objDirectory.SavePhotoId(PhotoIds);
Save Method
public void SavePhotoId(string PhotoId)
{
SqlTransaction tran = null;
try
{
SqlParameter[] arParams = new SqlParameter[3];
m_objConn = new SqlConnection(m_strConn);
m_objConn.Open();
tran = m_objConn.BeginTransaction();
arParams[0] = new SqlParameter("#PhotoID", PhotoId);
SqlHelper.ExecuteNonQuery(tran, CommandType.StoredProcedure, "InsertUpdatePhotIdInAlbum", arParams);
}
catch (Exception ex)
{
throw ex;
}
finally
{
if (m_objConn.State == ConnectionState.Open)
{
m_objConn.Close();
m_objConn = null;
}
}
}
Stored procedure:
CREATE Procedure [dbo].[InsertUpdatePhotIdInAlbum]
#PhotoID xml=null
As
Begin
set nocount on;
if #PhotoID IS NULL
Begin
Return;
End
Declare #PhotoAlbumDetail TABLE (AlbumID int, PhotoId int, CreatedBy varchar(50),
ModifiedBy varchar(50))
insert into #PhotoAlbumDetail(AlbumID, PhotoID, CreatedBy, ModifiedBy)
select
t.c.value('./#DirectoryId', 'int') as AlbumID,
t.c.value('./#PhotoId', 'int') as PhotoID,
t.c.value('./#CreatedBy', 'varchar(50)') as CreatedBy,
t.c.value('./#ModifiedBy', 'varchar(50)') as ModifiedBy
from
#PhotoID.nodes('/root/row') t(c);
INSERT INTO [dbo].[tbl_PhotoAlbumDetail](AlbumID, PhotoId, CreatedBy, ModifiedBy)
SELECT
p.AlbumID, p.PhotoId, p.CreatedBy, p.ModifiedBy
FROM
#PhotoAlbumDetail p
End
i have the following label.
<asp:Label ID="lbl_Modification" runat="server" Font-Bold="False" Font-Size="Small" ForeColor="#FF3300" Visible="False" Width="300px"></asp:Label>
<asp:Label ID="lbl_Message" runat="server" Font-Bold="False" Font-Size="Small" ForeColor="#FF3300" Visible="False" Width="300px"></asp:Label>
i want to pass id of the above label to the following method.
public bool date_Validation(DateTime t_Start_Date,DateTime t_End_Date,DateTime t_View_From)
{
#region date_Validation
try
{
if (t_Start_Date.Date < DateTime.Today)
{
lbl_Modification.Visible = true;
lbl_Modification.Text = "Date cannot be lesser than the Current Date";
return false;
}
else if (t_End_Date.Date < t_Start_Date)
{
lbl_Modification.Visible = true;
lbl_Modification.Text = "Invalid End Date";
return false;
}
else if (t_View_From.Date < DateTime.Today || t_View_From.Date >= t_Start_Date.Date)
{
lbl_Modification.Visible = true;
lbl_Modification.Text = "view Date cannot be greater than the Start Date or lesser than Current date";
return false;
}
return true;
}
catch (Exception e)
{
throw e;
}
#endregion
}
How i can i do this.
Please someone help me to do this.
public bool date_Validation(DateTime t_Start_Date,DateTime t_End_Date,DateTime t_View_From, Label lblModification)
{
// Method Content
}
//Call this method with your label parameter
date_Validation(startdate,enddate,viewform,lbl_Modification)
//lbl_Modification -> its your label name
Control's ID is a string, if you want to pass it as an extra parameter then change your method declaration to accept an additional param
public bool date_Validation(DateTime t_Start_Date,DateTime t_End_Date,DateTime t_View_From, string LabelID)
{
#region date_Validation
try
{
if (t_Start_Date.Date < DateTime.Today)
{
//Find the control here
var label=This.FindControl(LabelID);
lbl_Modification.Visible = true;
lbl_Modification.Text = "Date cannot be lesser than the Current Date";
return false;
}
else if (t_End_Date.Date < t_Start_Date)
{
lbl_Modification.Visible = true;
lbl_Modification.Text = "Invalid End Date";
return false;
}
else if (t_View_From.Date < DateTime.Today || t_View_From.Date >= t_Start_Date.Date)
{
lbl_Modification.Visible = true;
lbl_Modification.Text = "view Date cannot be greater than the Start Date or lesser than Current date";
return false;
}
return true;
}
catch (Exception e)
{
throw e;
}
#endregion
}
then your calling code would be something like
var isValid=date_Validation(startdate, enddate, "lbl_Modification");